Skip to content

Commit d12931f

Browse files
committed
Added textDocument/highlight support
1 parent 49aadf2 commit d12931f

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

Diff for: handler/handler.go

+26-12
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
252252
log.Printf("--> %s(%s:%s)", req.Method, p.TextDocument.URI, p.Position)
253253
inoURI = p.TextDocument.URI
254254
if res, e := handler.ino2cppTextDocumentPositionParams(p); e == nil {
255+
cppURI = p.TextDocument.URI
255256
params = res
256257
log.Printf(" --> %s(%s:%s)", req.Method, p.TextDocument.URI, p.Position)
257258
} else {
@@ -960,10 +961,19 @@ func (handler *InoHandler) transformClangdResult(method string, inoURI, cppURI l
960961
}
961962
return &inoSymbols
962963

963-
case *[]lsp.DocumentHighlight: // "textDocument/documentHighlight":
964-
for index := range *r {
965-
handler.cpp2inoDocumentHighlight(&(*r)[index], inoURI)
964+
case *[]lsp.DocumentHighlight:
965+
// Method: "textDocument/documentHighlight"
966+
res := []lsp.DocumentHighlight{}
967+
for _, cppHL := range *r {
968+
inoHL, err := handler.cpp2inoDocumentHighlight(&cppHL, cppURI)
969+
if err != nil {
970+
log.Printf("ERROR converting location %s:%s: %s", cppURI, cppHL.Range, err)
971+
return nil
972+
}
973+
res = append(res, *inoHL)
966974
}
975+
return &res
976+
967977
case *lsp.WorkspaceEdit: // "textDocument/rename":
968978
return handler.cpp2inoWorkspaceEdit(r)
969979
}
@@ -1058,19 +1068,23 @@ func (handler *InoHandler) cpp2inoWorkspaceEdit(origWorkspaceEdit *lsp.Workspace
10581068
return resWorkspaceEdit
10591069
}
10601070

1061-
func (handler *InoHandler) cpp2inoLocation(inoLocation lsp.Location) (lsp.Location, error) {
1062-
cppURI, cppRange, err := handler.cpp2inoDocumentURI(inoLocation.URI, inoLocation.Range)
1071+
func (handler *InoHandler) cpp2inoLocation(cppLocation lsp.Location) (lsp.Location, error) {
1072+
inoURI, inoRange, err := handler.cpp2inoDocumentURI(cppLocation.URI, cppLocation.Range)
10631073
return lsp.Location{
1064-
URI: cppURI,
1065-
Range: cppRange,
1074+
URI: inoURI,
1075+
Range: inoRange,
10661076
}, err
10671077
}
10681078

1069-
func (handler *InoHandler) cpp2inoDocumentHighlight(highlight *lsp.DocumentHighlight, uri lsp.DocumentURI) {
1070-
panic("not implemented")
1071-
// if data, ok := handler.data[uri]; ok {
1072-
// _, highlight.Range = data.sourceMap.CppToInoRange(highlight.Range)
1073-
// }
1079+
func (handler *InoHandler) cpp2inoDocumentHighlight(cppHighlight *lsp.DocumentHighlight, cppURI lsp.DocumentURI) (*lsp.DocumentHighlight, error) {
1080+
_, inoRange, err := handler.cpp2inoDocumentURI(cppURI, cppHighlight.Range)
1081+
if err != nil {
1082+
return nil, err
1083+
}
1084+
return &lsp.DocumentHighlight{
1085+
Kind: cppHighlight.Kind,
1086+
Range: inoRange,
1087+
}, nil
10741088
}
10751089

10761090
func (handler *InoHandler) cpp2inoTextEdits(cppURI lsp.DocumentURI, cppEdits []lsp.TextEdit) (map[lsp.DocumentURI][]lsp.TextEdit, error) {

0 commit comments

Comments
 (0)