@@ -126,7 +126,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
126
126
}
127
127
128
128
// Handle LSP methods: transform parameters and send to clangd
129
- var uri lsp.DocumentURI
129
+ var inoURI , cppURI lsp.DocumentURI
130
130
131
131
params , err := lsp .ReadParams (req .Method , req .Params )
132
132
if err != nil {
@@ -146,7 +146,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
146
146
147
147
case * lsp.DidOpenTextDocumentParams :
148
148
// method "textDocument/didOpen"
149
- uri = p .TextDocument .URI
149
+ inoURI = p .TextDocument .URI
150
150
log .Printf ("--> didOpen(%s@%d as '%s')" , p .TextDocument .URI , p .TextDocument .Version , p .TextDocument .LanguageID )
151
151
152
152
res , err := handler .didOpen (ctx , p )
@@ -161,7 +161,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
161
161
162
162
case * lsp.DidChangeTextDocumentParams :
163
163
// notification "textDocument/didChange"
164
- uri = p .TextDocument .URI
164
+ inoURI = p .TextDocument .URI
165
165
log .Printf ("--> didChange(%s@%d)" , p .TextDocument .URI , p .TextDocument .Version )
166
166
for _ , change := range p .ContentChanges {
167
167
log .Printf (" > %s -> %s" , change .Range , strconv .Quote (change .Text ))
@@ -186,33 +186,33 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
186
186
187
187
case * lsp.CompletionParams :
188
188
// method: "textDocument/completion"
189
- uri = p .TextDocument .URI
189
+ inoURI = p .TextDocument .URI
190
190
log .Printf ("--> completion(%s:%d:%d)\n " , p .TextDocument .URI , p .Position .Line , p .Position .Character )
191
191
192
192
err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
193
193
log .Printf (" --> completion(%s:%d:%d)\n " , p .TextDocument .URI , p .Position .Line , p .Position .Character )
194
194
195
195
case * lsp.CodeActionParams :
196
196
// method "textDocument/codeAction"
197
- uri = p .TextDocument .URI
197
+ inoURI = p .TextDocument .URI
198
198
log .Printf ("--> codeAction(%s:%s)" , p .TextDocument .URI , p .Range .Start )
199
199
200
200
p .TextDocument , err = handler .ino2cppTextDocumentIdentifier (p .TextDocument )
201
201
if err != nil {
202
202
break
203
203
}
204
204
if p .TextDocument .URI .AsPath ().EquivalentTo (handler .buildSketchCpp ) {
205
- p .Range = handler .sketchMapper .InoToCppLSPRange (uri , p .Range )
205
+ p .Range = handler .sketchMapper .InoToCppLSPRange (inoURI , p .Range )
206
206
for index := range p .Context .Diagnostics {
207
207
r := & p .Context .Diagnostics [index ].Range
208
- * r = handler .sketchMapper .InoToCppLSPRange (uri , * r )
208
+ * r = handler .sketchMapper .InoToCppLSPRange (inoURI , * r )
209
209
}
210
210
}
211
211
log .Printf (" --> codeAction(%s:%s)" , p .TextDocument .URI , p .Range .Start )
212
212
213
213
case * lsp.HoverParams :
214
214
// method: "textDocument/hover"
215
- uri = p .TextDocument .URI
215
+ inoURI = p .TextDocument .URI
216
216
doc := & p .TextDocumentPositionParams
217
217
log .Printf ("--> hover(%s:%d:%d)\n " , doc .TextDocument .URI , doc .Position .Line , doc .Position .Character )
218
218
@@ -221,7 +221,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
221
221
222
222
case * lsp.DocumentSymbolParams :
223
223
// method "textDocument/documentSymbol"
224
- uri = p .TextDocument .URI
224
+ inoURI = p .TextDocument .URI
225
225
log .Printf ("--> documentSymbol(%s)" , p .TextDocument .URI )
226
226
227
227
p .TextDocument , err = handler .ino2cppTextDocumentIdentifier (p .TextDocument )
@@ -230,7 +230,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
230
230
case * lsp.DidSaveTextDocumentParams : // "textDocument/didSave":
231
231
log .Printf ("--X " + req .Method )
232
232
return nil , nil
233
- uri = p .TextDocument .URI
233
+ inoURI = p .TextDocument .URI
234
234
p .TextDocument , err = handler .ino2cppTextDocumentIdentifier (p .TextDocument )
235
235
case * lsp.DidCloseTextDocumentParams : // "textDocument/didClose":
236
236
log .Printf ("--X " + req .Method )
@@ -249,32 +249,32 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
249
249
case * lsp.TextDocumentPositionParams : // "textDocument/documentHighlight":
250
250
log .Printf ("--X " + req .Method )
251
251
return nil , nil
252
- uri = p .TextDocument .URI
252
+ inoURI = p .TextDocument .URI
253
253
err = handler .ino2cppTextDocumentPositionParams (p )
254
254
case * lsp.ReferenceParams : // "textDocument/references":
255
255
log .Printf ("--X " + req .Method )
256
256
return nil , nil
257
- uri = p .TextDocument .URI
257
+ inoURI = p .TextDocument .URI
258
258
err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
259
259
case * lsp.DocumentFormattingParams : // "textDocument/formatting":
260
260
log .Printf ("--X " + req .Method )
261
261
return nil , nil
262
- uri = p .TextDocument .URI
262
+ inoURI = p .TextDocument .URI
263
263
p .TextDocument , err = handler .ino2cppTextDocumentIdentifier (p .TextDocument )
264
264
case * lsp.DocumentRangeFormattingParams : // "textDocument/rangeFormatting":
265
265
log .Printf ("--X " + req .Method )
266
266
return nil , nil
267
- uri = p .TextDocument .URI
267
+ inoURI = p .TextDocument .URI
268
268
err = handler .ino2cppDocumentRangeFormattingParams (p )
269
269
case * lsp.DocumentOnTypeFormattingParams : // "textDocument/onTypeFormatting":
270
270
log .Printf ("--X " + req .Method )
271
271
return nil , nil
272
- uri = p .TextDocument .URI
272
+ inoURI = p .TextDocument .URI
273
273
err = handler .ino2cppDocumentOnTypeFormattingParams (p )
274
274
case * lsp.RenameParams : // "textDocument/rename":
275
275
log .Printf ("--X " + req .Method )
276
276
return nil , nil
277
- uri = p .TextDocument .URI
277
+ inoURI = p .TextDocument .URI
278
278
err = handler .ino2cppRenameParams (p )
279
279
case * lsp.DidChangeWatchedFilesParams : // "workspace/didChangeWatchedFiles":
280
280
log .Printf ("--X " + req .Method )
@@ -324,7 +324,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
324
324
325
325
// Transform and return the result
326
326
if result != nil {
327
- result = handler .transformClangdResult (req .Method , uri , result )
327
+ result = handler .transformClangdResult (req .Method , inoURI , cppURI , result )
328
328
}
329
329
return result , err
330
330
}
@@ -416,7 +416,7 @@ func (handler *InoHandler) refreshCppDocumentSymbols() error {
416
416
if err != nil {
417
417
return errors .WithMessage (err , "quering source code symbols" )
418
418
}
419
- result = handler .transformClangdResult ("textDocument/documentSymbol" , cppURI , result )
419
+ result = handler .transformClangdResult ("textDocument/documentSymbol" , cppURI , "" , result )
420
420
if symbols , ok := result .([]lsp.DocumentSymbol ); ! ok {
421
421
return errors .WithMessage (err , "quering source code symbols (2)" )
422
422
} else {
@@ -817,8 +817,8 @@ func (handler *InoHandler) ino2cppWorkspaceEdit(origEdit *lsp.WorkspaceEdit) *ls
817
817
return & newEdit
818
818
}
819
819
820
- func (handler * InoHandler ) transformClangdResult (method string , uri lsp.DocumentURI , result interface {}) interface {} {
821
- cppToIno := uri != "" && uri .AsPath ().EquivalentTo (handler .buildSketchCpp )
820
+ func (handler * InoHandler ) transformClangdResult (method string , inoURI , cppURI lsp.DocumentURI , result interface {}) interface {} {
821
+ cppToIno := inoURI != "" && inoURI .AsPath ().EquivalentTo (handler .buildSketchCpp )
822
822
823
823
switch r := result .(type ) {
824
824
case * lsp.Hover :
@@ -853,7 +853,7 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
853
853
854
854
if r .DocumentSymbolArray != nil {
855
855
// Treat the input as []DocumentSymbol
856
- return handler .cpp2inoDocumentSymbols (* r .DocumentSymbolArray , uri )
856
+ return handler .cpp2inoDocumentSymbols (* r .DocumentSymbolArray , inoURI )
857
857
} else if r .SymbolInformationArray != nil {
858
858
// Treat the input as []SymbolInformation
859
859
return handler .cpp2inoSymbolInformation (* r .SymbolInformationArray )
@@ -873,7 +873,7 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
873
873
}
874
874
(* r )[i ] = lsp.CommandOrCodeAction {
875
875
Command : handler .Cpp2InoCommand (item .Command ),
876
- CodeAction : handler .cpp2inoCodeAction (item .CodeAction , uri ),
876
+ CodeAction : handler .cpp2inoCodeAction (item .CodeAction , inoURI ),
877
877
}
878
878
}
879
879
log .Printf ("<-- codeAction(%d elements)" , len (* r ))
@@ -890,15 +890,15 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
890
890
}
891
891
case * []lsp.DocumentHighlight : // "textDocument/documentHighlight":
892
892
for index := range * r {
893
- handler .cpp2inoDocumentHighlight (& (* r )[index ], uri )
893
+ handler .cpp2inoDocumentHighlight (& (* r )[index ], inoURI )
894
894
}
895
895
// case "textDocument/formatting":
896
896
// fallthrough
897
897
// case "textDocument/rangeFormatting":
898
898
// fallthrough
899
899
case * []lsp.TextEdit : // "textDocument/onTypeFormatting":
900
900
for index := range * r {
901
- handler .cpp2inoTextEdit (& (* r )[index ], uri )
901
+ handler .cpp2inoTextEdit (& (* r )[index ], inoURI )
902
902
}
903
903
case * lsp.WorkspaceEdit : // "textDocument/rename":
904
904
return handler .cpp2inoWorkspaceEdit (r )
0 commit comments