@@ -189,8 +189,12 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
189
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
- 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
+ }
194
198
195
199
case * lsp.CodeActionParams :
196
200
// method "textDocument/codeAction"
@@ -216,8 +220,12 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
216
220
doc := & p .TextDocumentPositionParams
217
221
log .Printf ("--> hover(%s:%d:%d)\n " , doc .TextDocument .URI , doc .Position .Line , doc .Position .Character )
218
222
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
+ }
221
229
222
230
case * lsp.DocumentSymbolParams :
223
231
// method "textDocument/documentSymbol"
@@ -235,6 +243,21 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
235
243
cppURI = p .TextDocument .URI
236
244
log .Printf (" --> formatting(%s)" , p .TextDocument .URI )
237
245
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
+
238
261
case * lsp.DidSaveTextDocumentParams : // "textDocument/didSave":
239
262
log .Printf ("--X " + req .Method )
240
263
return nil , nil
@@ -246,24 +269,11 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
246
269
// uri = p.TextDocument.URI
247
270
// err = handler.sketchToBuildPathTextDocumentIdentifier(&p.TextDocument)
248
271
// 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 )
262
272
case * lsp.ReferenceParams : // "textDocument/references":
263
273
log .Printf ("--X " + req .Method )
264
274
return nil , nil
265
275
inoURI = p .TextDocument .URI
266
- err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
276
+ _ , err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
267
277
case * lsp.DocumentRangeFormattingParams : // "textDocument/rangeFormatting":
268
278
log .Printf ("--X " + req .Method )
269
279
return nil , nil
@@ -739,22 +749,25 @@ func (handler *InoHandler) cpp2inoDocumentURI(cppURI lsp.DocumentURI, cppRange l
739
749
return "" , lsp.Range {}, err
740
750
}
741
751
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 )
753
754
if err != nil {
754
- return err
755
+ return nil , err
755
756
}
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
758
771
}
759
772
760
773
func (handler * InoHandler ) ino2cppDocumentRangeFormattingParams (params * lsp.DocumentRangeFormattingParams ) error {
@@ -914,26 +927,45 @@ func (handler *InoHandler) transformClangdResult(method string, inoURI, cppURI l
914
927
}
915
928
return & inoEdits
916
929
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 )
926
943
}
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
+
927
963
case * []lsp.DocumentHighlight : // "textDocument/documentHighlight":
928
964
for index := range * r {
929
965
handler .cpp2inoDocumentHighlight (& (* r )[index ], inoURI )
930
966
}
931
967
case * lsp.WorkspaceEdit : // "textDocument/rename":
932
968
return handler .cpp2inoWorkspaceEdit (r )
933
- case * []lsp.SymbolInformation : // "workspace/symbol":
934
- for index := range * r {
935
- handler .cpp2inoLocation (& (* r )[index ].Location )
936
- }
937
969
}
938
970
return result
939
971
}
@@ -1026,12 +1058,12 @@ func (handler *InoHandler) cpp2inoWorkspaceEdit(origWorkspaceEdit *lsp.Workspace
1026
1058
return resWorkspaceEdit
1027
1059
}
1028
1060
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
1035
1067
}
1036
1068
1037
1069
func (handler * InoHandler ) cpp2inoDocumentHighlight (highlight * lsp.DocumentHighlight , uri lsp.DocumentURI ) {
0 commit comments