@@ -189,8 +189,12 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
189189 inoURI = p .TextDocument .URI
190190 log .Printf ("--> completion(%s:%d:%d)\n " , p .TextDocument .URI , p .Position .Line , p .Position .Character )
191191
192- err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
193- log .Printf (" --> completion(%s:%d:%d)\n " , p .TextDocument .URI , p .Position .Line , p .Position .Character )
192+ if res , e := handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams ); e == nil {
193+ p .TextDocumentPositionParams = * res
194+ log .Printf (" --> completion(%s:%d:%d)\n " , p .TextDocument .URI , p .Position .Line , p .Position .Character )
195+ } else {
196+ err = e
197+ }
194198
195199 case * lsp.CodeActionParams :
196200 // method "textDocument/codeAction"
@@ -216,8 +220,12 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
216220 doc := & p .TextDocumentPositionParams
217221 log .Printf ("--> hover(%s:%d:%d)\n " , doc .TextDocument .URI , doc .Position .Line , doc .Position .Character )
218222
219- err = handler .ino2cppTextDocumentPositionParams (doc )
220- log .Printf (" --> hover(%s:%d:%d)\n " , doc .TextDocument .URI , doc .Position .Line , doc .Position .Character )
223+ if res , e := handler .ino2cppTextDocumentPositionParams (doc ); e == nil {
224+ p .TextDocumentPositionParams = * res
225+ log .Printf (" --> hover(%s:%d:%d)\n " , doc .TextDocument .URI , doc .Position .Line , doc .Position .Character )
226+ } else {
227+ err = e
228+ }
221229
222230 case * lsp.DocumentSymbolParams :
223231 // method "textDocument/documentSymbol"
@@ -235,6 +243,21 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
235243 cppURI = p .TextDocument .URI
236244 log .Printf (" --> formatting(%s)" , p .TextDocument .URI )
237245
246+ case * lsp.TextDocumentPositionParams :
247+ // Method: "textDocument/signatureHelp"
248+ // Method: "textDocument/definition"
249+ // Method: "textDocument/typeDefinition"
250+ // Method: "textDocument/implementation"
251+ // Method: "textDocument/documentHighlight"
252+ log .Printf ("--> %s(%s:%s)" , req .Method , p .TextDocument .URI , p .Position )
253+ inoURI = p .TextDocument .URI
254+ if res , e := handler .ino2cppTextDocumentPositionParams (p ); e == nil {
255+ params = res
256+ log .Printf (" --> %s(%s:%s)" , req .Method , p .TextDocument .URI , p .Position )
257+ } else {
258+ err = e
259+ }
260+
238261 case * lsp.DidSaveTextDocumentParams : // "textDocument/didSave":
239262 log .Printf ("--X " + req .Method )
240263 return nil , nil
@@ -246,24 +269,11 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
246269 // uri = p.TextDocument.URI
247270 // err = handler.sketchToBuildPathTextDocumentIdentifier(&p.TextDocument)
248271 // handler.deleteFileData(uri)
249- // case "textDocument/signatureHelp":
250- // fallthrough
251- // case "textDocument/definition":
252- // fallthrough
253- // case "textDocument/typeDefinition":
254- // fallthrough
255- // case "textDocument/implementation":
256- // fallthrough
257- case * lsp.TextDocumentPositionParams : // "textDocument/documentHighlight":
258- log .Printf ("--X " + req .Method )
259- return nil , nil
260- inoURI = p .TextDocument .URI
261- err = handler .ino2cppTextDocumentPositionParams (p )
262272 case * lsp.ReferenceParams : // "textDocument/references":
263273 log .Printf ("--X " + req .Method )
264274 return nil , nil
265275 inoURI = p .TextDocument .URI
266- err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
276+ _ , err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
267277 case * lsp.DocumentRangeFormattingParams : // "textDocument/rangeFormatting":
268278 log .Printf ("--X " + req .Method )
269279 return nil , nil
@@ -739,22 +749,25 @@ func (handler *InoHandler) cpp2inoDocumentURI(cppURI lsp.DocumentURI, cppRange l
739749 return "" , lsp.Range {}, err
740750}
741751
742- func (handler * InoHandler ) ino2cppTextDocumentPositionParams (params * lsp.TextDocumentPositionParams ) error {
743- sourceURI := params .TextDocument .URI
744- if strings .HasSuffix (string (sourceURI ), ".ino" ) {
745- line , ok := handler .sketchMapper .InoToCppLineOk (sourceURI , params .Position .Line )
746- if ! ok {
747- log .Printf (" invalid line requested: %s:%d" , sourceURI , params .Position .Line )
748- return unknownURI (params .TextDocument .URI )
749- }
750- params .Position .Line = line
751- }
752- cppDoc , err := handler .ino2cppTextDocumentIdentifier (params .TextDocument )
752+ func (handler * InoHandler ) ino2cppTextDocumentPositionParams (inoParams * lsp.TextDocumentPositionParams ) (* lsp.TextDocumentPositionParams , error ) {
753+ cppDoc , err := handler .ino2cppTextDocumentIdentifier (inoParams .TextDocument )
753754 if err != nil {
754- return err
755+ return nil , err
755756 }
756- params .TextDocument = cppDoc
757- return nil
757+ cppPosition := inoParams .Position
758+ inoURI := inoParams .TextDocument .URI
759+ if inoURI .Ext () == ".ino" {
760+ if cppLine , ok := handler .sketchMapper .InoToCppLineOk (inoURI , inoParams .Position .Line ); ok {
761+ cppPosition .Line = cppLine
762+ } else {
763+ log .Printf (" invalid line requested: %s:%d" , inoURI , inoParams .Position .Line )
764+ return nil , unknownURI (inoURI )
765+ }
766+ }
767+ return & lsp.TextDocumentPositionParams {
768+ TextDocument : cppDoc ,
769+ Position : cppPosition ,
770+ }, nil
758771}
759772
760773func (handler * InoHandler ) ino2cppDocumentRangeFormattingParams (params * lsp.DocumentRangeFormattingParams ) error {
@@ -914,26 +927,45 @@ func (handler *InoHandler) transformClangdResult(method string, inoURI, cppURI l
914927 }
915928 return & inoEdits
916929
917- // case "textDocument/definition":
918- // fallthrough
919- // case "textDocument/typeDefinition":
920- // fallthrough
921- // case "textDocument/implementation":
922- // fallthrough
923- case * []lsp.Location : // "textDocument/references":
924- for index := range * r {
925- handler .cpp2inoLocation (& (* r )[index ])
930+ case * []lsp.Location :
931+ // Method: "textDocument/definition"
932+ // Method: "textDocument/typeDefinition"
933+ // Method: "textDocument/implementation"
934+ // Method: "textDocument/references"
935+ inoLocations := []lsp.Location {}
936+ for _ , cppLocation := range * r {
937+ inoLocation , err := handler .cpp2inoLocation (cppLocation )
938+ if err != nil {
939+ log .Printf ("ERROR converting location %s:%s: %s" , cppLocation .URI , cppLocation .Range , err )
940+ return nil
941+ }
942+ inoLocations = append (inoLocations , inoLocation )
926943 }
944+ return & inoLocations
945+
946+ case * []lsp.SymbolInformation :
947+ // Method: "workspace/symbol"
948+
949+ inoSymbols := []lsp.SymbolInformation {}
950+ for _ , cppSymbolInfo := range * r {
951+ cppLocation := cppSymbolInfo .Location
952+ inoLocation , err := handler .cpp2inoLocation (cppLocation )
953+ if err != nil {
954+ log .Printf ("ERROR converting location %s:%s: %s" , cppLocation .URI , cppLocation .Range , err )
955+ return nil
956+ }
957+ inoSymbolInfo := cppSymbolInfo
958+ inoSymbolInfo .Location = inoLocation
959+ inoSymbols = append (inoSymbols , inoSymbolInfo )
960+ }
961+ return & inoSymbols
962+
927963 case * []lsp.DocumentHighlight : // "textDocument/documentHighlight":
928964 for index := range * r {
929965 handler .cpp2inoDocumentHighlight (& (* r )[index ], inoURI )
930966 }
931967 case * lsp.WorkspaceEdit : // "textDocument/rename":
932968 return handler .cpp2inoWorkspaceEdit (r )
933- case * []lsp.SymbolInformation : // "workspace/symbol":
934- for index := range * r {
935- handler .cpp2inoLocation (& (* r )[index ].Location )
936- }
937969 }
938970 return result
939971}
@@ -1026,12 +1058,12 @@ func (handler *InoHandler) cpp2inoWorkspaceEdit(origWorkspaceEdit *lsp.Workspace
10261058 return resWorkspaceEdit
10271059}
10281060
1029- func (handler * InoHandler ) cpp2inoLocation (location * lsp.Location ) {
1030- panic ( "not implemented" )
1031- // if data, ok := handler.data[location.URI]; ok {
1032- // location. URI = data.sourceURI
1033- // _, location. Range = data.sourceMap.CppToInoRange(location.Range)
1034- // }
1061+ func (handler * InoHandler ) cpp2inoLocation (inoLocation lsp.Location ) (lsp. Location , error ) {
1062+ cppURI , cppRange , err := handler . cpp2inoDocumentURI ( inoLocation . URI , inoLocation . Range )
1063+ return lsp. Location {
1064+ URI : cppURI ,
1065+ Range : cppRange ,
1066+ }, err
10351067}
10361068
10371069func (handler * InoHandler ) cpp2inoDocumentHighlight (highlight * lsp.DocumentHighlight , uri lsp.DocumentURI ) {
0 commit comments