93
93
Folder,
94
94
Cfg,
95
95
Nimble
96
+
97
+ NimbleDumpInfo = object
98
+ srcDir: string
99
+ name: string
100
+ nimDir: Option[string ]
101
+ nimblePath: Option[string ]
96
102
97
103
createJsonFlavor(LSPFlavour, omitOptionalFields = true )
98
104
Option.useDefaultSerializationIn LSPFlavour
@@ -136,7 +142,19 @@ proc supportSignatureHelp(cc: ClientCapabilities): bool =
136
142
let caps = cc.textDocument
137
143
caps.isSome and caps.get.signatureHelp.isSome
138
144
139
- proc getProjectFileAutoGuess(fileUri: string ): string =
145
+ proc getNimbleDumpInfo(ls: LanguageServer, nimbleFile: string ): NimbleDumpInfo =
146
+ let info = execProcess("nimble dump " & nimbleFile)
147
+ for line in info.splitLines:
148
+ if line.startsWith("srcDir"):
149
+ result .srcDir = line[(1 + line.find '"')..^ 2]
150
+ if line.startsWith(" name" ):
151
+ result .name = line[(1 + line.find '"' )..^ 2 ]
152
+ if line.startsWith(" nimDir" ):
153
+ result .nimDir = some line[(1 + line.find '"' )..^ 2 ]
154
+ if line.startsWith(" nimblePath" ):
155
+ result .nimblePath = some line[(1 + line.find '"' )..^ 2 ]
156
+
157
+ proc getProjectFileAutoGuess(ls: LanguageServer, fileUri: string ): string =
140
158
let file = fileUri.decodeUrl
141
159
result = file
142
160
let (dir, _, _) = result .splitFile()
@@ -157,13 +175,9 @@ proc getProjectFileAutoGuess(fileUri: string): string =
157
175
certainty = Cfg
158
176
if certainty <= Nimble:
159
177
for nimble in walkFiles(path / " *.nimble" ):
160
- let info = execProcess("nimble dump " & nimble)
161
- var sourceDir, name: string
162
- for line in info.splitLines:
163
- if line.startsWith("srcDir"):
164
- sourceDir = path / line[(1 + line.find '"')..^ 2]
165
- if line.startsWith(" name" ):
166
- name = line[(1 + line.find '"' )..^ 2 ]
178
+ let dumpInfo = ls.getNimbleDumpInfo(nimble)
179
+ let name = dumpInfo.name
180
+ let sourceDir = path / dumpInfo.srcDir
167
181
let projectFile = sourceDir / (name & " .nim" )
168
182
if sourceDir.len != 0 and name.len != 0 and
169
183
file.isRelativeTo(sourceDir) and fileExists(projectFile):
@@ -206,7 +220,7 @@ proc getProjectFile(fileUri: string, ls: LanguageServer): Future[string] {.async
206
220
else :
207
221
trace " getProjectFile does not match" , uri = fileUri, matchedRegex = mapping.fileRegex
208
222
209
- result = getProjectFileAutoGuess(fileUri)
223
+ result = ls. getProjectFileAutoGuess(fileUri)
210
224
debug " getProjectFile" , project = result
211
225
212
226
proc showMessage(ls: LanguageServer, message: string , typ: MessageType) =
@@ -677,12 +691,8 @@ proc getNimVersion(nimDir: string): string =
677
691
678
692
proc getNimSuggestPath(ls: LanguageServer, conf: NlsConfig, workingDir: string ): string =
679
693
# Attempting to see if the project is using a custom Nim version, if it's the case this will be slower than usual
680
- let info: string = execProcess(" nimble dump " , workingDir)
681
- var nimDir = " "
682
- const NimDirSplit = " nimDir:"
683
- for line in info.splitLines:
684
- if line.startsWith(NimDirSplit):
685
- nimDir = line.split(NimDirSplit)[1 ].strip.strip(chars = {'"' , ' ' })
694
+ let nimbleDumpInfo = ls.getNimbleDumpInfo(" " )
695
+ let nimDir = nimbleDumpInfo.nimDir.get " "
686
696
687
697
result = expandTilde(conf.nimsuggestPath.get(" " ))
688
698
var nimVersion = " "
0 commit comments