@@ -100,6 +100,15 @@ type
100
100
name: string
101
101
nimDir: Option[string ]
102
102
nimblePath: Option[string ]
103
+ entryPoints: seq [string ] # when it's empty, means the nimble version doesnt dump it.
104
+
105
+
106
+ proc getNimbleEntryPoints(dumpInfo: NimbleDumpInfo, nimbleProjectPath: string ): seq [string ] =
107
+ if dumpInfo.entryPoints.len > 0 :
108
+ return dumpInfo.entryPoints.mapIt(nimbleProjectPath / it)
109
+ # Nimble doesnt include the entry points, returning the nimble project file as the entry point
110
+ let sourceDir = nimbleProjectPath / dumpInfo.srcDir
111
+ @ [sourceDir / (dumpInfo.name & " .nim" )]
103
112
104
113
proc getVersionFromNimble(): string =
105
114
# We should static run nimble dump instead
@@ -166,7 +175,9 @@ proc getNimbleDumpInfo(ls: LanguageServer, nimbleFile: string): NimbleDumpInfo =
166
175
result .nimDir = some line[(1 + line.find '"' )..^ 2 ]
167
176
if line.startsWith(" nimblePath" ):
168
177
result .nimblePath = some line[(1 + line.find '"' )..^ 2 ]
169
-
178
+ if line.startsWith(" entryPoints" ):
179
+ result .entryPoints = line[(1 + line.find '"' )..^ 2 ].split(',' ).mapIt(it.strip(chars = {' ' , '"' }))
180
+
170
181
var nimbleFile = nimbleFile
171
182
if nimbleFile == " " and result .nimblePath.isSome:
172
183
nimbleFile = result .nimblePath.get
@@ -251,13 +262,28 @@ proc getProjectFile(fileUri: string, ls: LanguageServer): Future[string] {.async
251
262
else :
252
263
trace " getProjectFile does not match" , uri = fileUri, matchedRegex = mapping.fileRegex
253
264
265
+ once: # once we refactor the project to chronos, we may move this code into init. Right now it hangs for some odd reason
266
+ let rootPath = ls.initializeParams.getRootPath
267
+ if rootPath != " " :
268
+ let nimbleFiles = walkFiles(rootPath / " *.nimble" ).toSeq
269
+ if nimbleFiles.len > 0 :
270
+ let nimbleFile = nimbleFiles[0 ]
271
+ let nimbleDumpInfo = ls.getNimbleDumpInfo(nimbleFile)
272
+ let entryPoints = nimbleDumpInfo.getNimbleEntryPoints(ls.initializeParams.getRootPath)
273
+ for entryPoint in entryPoints:
274
+ debug " Starting nimsuggest for entry point " , entry = entryPoint
275
+ if not ls.projectFiles.hasKey(entryPoint):
276
+ ls.createOrRestartNimsuggest(entryPoint)
277
+ # let ns = await ls.projectFiles[entryPoint]
278
+
254
279
let otherNsProject = await ls.isKnownByAnyNimsuggest(fileUri)
255
280
if otherNsProject.isSome:
256
281
debug " File is known by nimsuggest" , uri = fileUri, projectFile = otherNsProject.get
257
282
result = otherNsProject.get
258
283
else :
259
284
result = ls.getProjectFileAutoGuess(fileUri)
260
- debug " getProjectFile" , project = result
285
+
286
+ debug " getProjectFile" , project = result , fileUri = fileUri
261
287
262
288
proc showMessage(ls: LanguageServer, message: string , typ: MessageType) =
263
289
proc notify() =
@@ -387,7 +413,11 @@ proc initialize(p: tuple[ls: LanguageServer, pipeInput: AsyncInputStream], param
387
413
result .capabilities.renameProvider = %* {
388
414
" prepareProvider" : true
389
415
}
390
- debug " Initialize completed."
416
+ debug " Initialize completed. Trying to start nimsuggest instances"
417
+ # If we are in a nimble project here, we try to start the entry points
418
+
419
+
420
+
391
421
392
422
proc requiresDynamicRegistrationForDidChangeConfiguration(ls: LanguageServer): bool =
393
423
ls.clientCapabilities.workspace.isSome and
@@ -807,6 +837,8 @@ proc warnIfUnknown(ls: LanguageServer, ns: Nimsuggest, uri: string, projectFile:
807
837
808
838
proc didOpen(ls: LanguageServer, params: DidOpenTextDocumentParams):
809
839
Future[void ] {.async, gcsafe.} =
840
+
841
+
810
842
with params.textDocument:
811
843
debug " New document opened for URI:" , uri = uri
812
844
let
@@ -1027,13 +1059,6 @@ proc status(ls: LanguageServer, params: NimLangServerStatusParams): Future[NimLa
1027
1059
path: ns.nimsuggestPath,
1028
1060
port: ns.port,
1029
1061
)
1030
- for openFile in ns.openFiles:
1031
- let openFilePath = openFile.uriToPath
1032
- let isKnown = await ns.isKnown(openFilePath)
1033
- nsStatus.openFiles.add openFilePath
1034
- if not isKnown:
1035
- nsStatus.unknownFiles.add openFilePath
1036
-
1037
1062
status.nimsuggestInstances.add nsStatus
1038
1063
1039
1064
for openFile in ls.openFiles.keys:
0 commit comments