@@ -126,7 +126,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
126126 }
127127
128128 // Handle LSP methods: transform parameters and send to clangd
129- var uri lsp.DocumentURI
129+ var inoURI , cppURI lsp.DocumentURI
130130
131131 params , err := lsp .ReadParams (req .Method , req .Params )
132132 if err != nil {
@@ -146,7 +146,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
146146
147147 case * lsp.DidOpenTextDocumentParams :
148148 // method "textDocument/didOpen"
149- uri = p .TextDocument .URI
149+ inoURI = p .TextDocument .URI
150150 log .Printf ("--> didOpen(%s@%d as '%s')" , p .TextDocument .URI , p .TextDocument .Version , p .TextDocument .LanguageID )
151151
152152 res , err := handler .didOpen (ctx , p )
@@ -161,7 +161,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
161161
162162 case * lsp.DidChangeTextDocumentParams :
163163 // notification "textDocument/didChange"
164- uri = p .TextDocument .URI
164+ inoURI = p .TextDocument .URI
165165 log .Printf ("--> didChange(%s@%d)" , p .TextDocument .URI , p .TextDocument .Version )
166166 for _ , change := range p .ContentChanges {
167167 log .Printf (" > %s -> %s" , change .Range , strconv .Quote (change .Text ))
@@ -186,33 +186,33 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
186186
187187 case * lsp.CompletionParams :
188188 // method: "textDocument/completion"
189- uri = p .TextDocument .URI
189+ inoURI = p .TextDocument .URI
190190 log .Printf ("--> completion(%s:%d:%d)\n " , p .TextDocument .URI , p .Position .Line , p .Position .Character )
191191
192192 err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
193193 log .Printf (" --> completion(%s:%d:%d)\n " , p .TextDocument .URI , p .Position .Line , p .Position .Character )
194194
195195 case * lsp.CodeActionParams :
196196 // method "textDocument/codeAction"
197- uri = p .TextDocument .URI
197+ inoURI = p .TextDocument .URI
198198 log .Printf ("--> codeAction(%s:%s)" , p .TextDocument .URI , p .Range .Start )
199199
200200 p .TextDocument , err = handler .ino2cppTextDocumentIdentifier (p .TextDocument )
201201 if err != nil {
202202 break
203203 }
204204 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 )
206206 for index := range p .Context .Diagnostics {
207207 r := & p .Context .Diagnostics [index ].Range
208- * r = handler .sketchMapper .InoToCppLSPRange (uri , * r )
208+ * r = handler .sketchMapper .InoToCppLSPRange (inoURI , * r )
209209 }
210210 }
211211 log .Printf (" --> codeAction(%s:%s)" , p .TextDocument .URI , p .Range .Start )
212212
213213 case * lsp.HoverParams :
214214 // method: "textDocument/hover"
215- uri = p .TextDocument .URI
215+ inoURI = p .TextDocument .URI
216216 doc := & p .TextDocumentPositionParams
217217 log .Printf ("--> hover(%s:%d:%d)\n " , doc .TextDocument .URI , doc .Position .Line , doc .Position .Character )
218218
@@ -221,7 +221,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
221221
222222 case * lsp.DocumentSymbolParams :
223223 // method "textDocument/documentSymbol"
224- uri = p .TextDocument .URI
224+ inoURI = p .TextDocument .URI
225225 log .Printf ("--> documentSymbol(%s)" , p .TextDocument .URI )
226226
227227 p .TextDocument , err = handler .ino2cppTextDocumentIdentifier (p .TextDocument )
@@ -230,7 +230,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
230230 case * lsp.DidSaveTextDocumentParams : // "textDocument/didSave":
231231 log .Printf ("--X " + req .Method )
232232 return nil , nil
233- uri = p .TextDocument .URI
233+ inoURI = p .TextDocument .URI
234234 p .TextDocument , err = handler .ino2cppTextDocumentIdentifier (p .TextDocument )
235235 case * lsp.DidCloseTextDocumentParams : // "textDocument/didClose":
236236 log .Printf ("--X " + req .Method )
@@ -249,32 +249,32 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
249249 case * lsp.TextDocumentPositionParams : // "textDocument/documentHighlight":
250250 log .Printf ("--X " + req .Method )
251251 return nil , nil
252- uri = p .TextDocument .URI
252+ inoURI = p .TextDocument .URI
253253 err = handler .ino2cppTextDocumentPositionParams (p )
254254 case * lsp.ReferenceParams : // "textDocument/references":
255255 log .Printf ("--X " + req .Method )
256256 return nil , nil
257- uri = p .TextDocument .URI
257+ inoURI = p .TextDocument .URI
258258 err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
259259 case * lsp.DocumentFormattingParams : // "textDocument/formatting":
260260 log .Printf ("--X " + req .Method )
261261 return nil , nil
262- uri = p .TextDocument .URI
262+ inoURI = p .TextDocument .URI
263263 p .TextDocument , err = handler .ino2cppTextDocumentIdentifier (p .TextDocument )
264264 case * lsp.DocumentRangeFormattingParams : // "textDocument/rangeFormatting":
265265 log .Printf ("--X " + req .Method )
266266 return nil , nil
267- uri = p .TextDocument .URI
267+ inoURI = p .TextDocument .URI
268268 err = handler .ino2cppDocumentRangeFormattingParams (p )
269269 case * lsp.DocumentOnTypeFormattingParams : // "textDocument/onTypeFormatting":
270270 log .Printf ("--X " + req .Method )
271271 return nil , nil
272- uri = p .TextDocument .URI
272+ inoURI = p .TextDocument .URI
273273 err = handler .ino2cppDocumentOnTypeFormattingParams (p )
274274 case * lsp.RenameParams : // "textDocument/rename":
275275 log .Printf ("--X " + req .Method )
276276 return nil , nil
277- uri = p .TextDocument .URI
277+ inoURI = p .TextDocument .URI
278278 err = handler .ino2cppRenameParams (p )
279279 case * lsp.DidChangeWatchedFilesParams : // "workspace/didChangeWatchedFiles":
280280 log .Printf ("--X " + req .Method )
@@ -324,7 +324,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
324324
325325 // Transform and return the result
326326 if result != nil {
327- result = handler .transformClangdResult (req .Method , uri , result )
327+ result = handler .transformClangdResult (req .Method , inoURI , cppURI , result )
328328 }
329329 return result , err
330330}
@@ -416,7 +416,7 @@ func (handler *InoHandler) refreshCppDocumentSymbols() error {
416416 if err != nil {
417417 return errors .WithMessage (err , "quering source code symbols" )
418418 }
419- result = handler .transformClangdResult ("textDocument/documentSymbol" , cppURI , result )
419+ result = handler .transformClangdResult ("textDocument/documentSymbol" , cppURI , "" , result )
420420 if symbols , ok := result .([]lsp.DocumentSymbol ); ! ok {
421421 return errors .WithMessage (err , "quering source code symbols (2)" )
422422 } else {
@@ -817,8 +817,8 @@ func (handler *InoHandler) ino2cppWorkspaceEdit(origEdit *lsp.WorkspaceEdit) *ls
817817 return & newEdit
818818}
819819
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 )
822822
823823 switch r := result .(type ) {
824824 case * lsp.Hover :
@@ -853,7 +853,7 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
853853
854854 if r .DocumentSymbolArray != nil {
855855 // Treat the input as []DocumentSymbol
856- return handler .cpp2inoDocumentSymbols (* r .DocumentSymbolArray , uri )
856+ return handler .cpp2inoDocumentSymbols (* r .DocumentSymbolArray , inoURI )
857857 } else if r .SymbolInformationArray != nil {
858858 // Treat the input as []SymbolInformation
859859 return handler .cpp2inoSymbolInformation (* r .SymbolInformationArray )
@@ -873,7 +873,7 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
873873 }
874874 (* r )[i ] = lsp.CommandOrCodeAction {
875875 Command : handler .Cpp2InoCommand (item .Command ),
876- CodeAction : handler .cpp2inoCodeAction (item .CodeAction , uri ),
876+ CodeAction : handler .cpp2inoCodeAction (item .CodeAction , inoURI ),
877877 }
878878 }
879879 log .Printf ("<-- codeAction(%d elements)" , len (* r ))
@@ -890,15 +890,15 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
890890 }
891891 case * []lsp.DocumentHighlight : // "textDocument/documentHighlight":
892892 for index := range * r {
893- handler .cpp2inoDocumentHighlight (& (* r )[index ], uri )
893+ handler .cpp2inoDocumentHighlight (& (* r )[index ], inoURI )
894894 }
895895 // case "textDocument/formatting":
896896 // fallthrough
897897 // case "textDocument/rangeFormatting":
898898 // fallthrough
899899 case * []lsp.TextEdit : // "textDocument/onTypeFormatting":
900900 for index := range * r {
901- handler .cpp2inoTextEdit (& (* r )[index ], uri )
901+ handler .cpp2inoTextEdit (& (* r )[index ], inoURI )
902902 }
903903 case * lsp.WorkspaceEdit : // "textDocument/rename":
904904 return handler .cpp2inoWorkspaceEdit (r )
0 commit comments