Skip to content

Added textDocument/highlight support #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
log.Printf("--> %s(%s:%s)", req.Method, p.TextDocument.URI, p.Position)
inoURI = p.TextDocument.URI
if res, e := handler.ino2cppTextDocumentPositionParams(p); e == nil {
cppURI = p.TextDocument.URI
params = res
log.Printf(" --> %s(%s:%s)", req.Method, p.TextDocument.URI, p.Position)
} else {
Expand Down Expand Up @@ -960,10 +961,19 @@ func (handler *InoHandler) transformClangdResult(method string, inoURI, cppURI l
}
return &inoSymbols

case *[]lsp.DocumentHighlight: // "textDocument/documentHighlight":
for index := range *r {
handler.cpp2inoDocumentHighlight(&(*r)[index], inoURI)
case *[]lsp.DocumentHighlight:
// Method: "textDocument/documentHighlight"
res := []lsp.DocumentHighlight{}
for _, cppHL := range *r {
inoHL, err := handler.cpp2inoDocumentHighlight(&cppHL, cppURI)
if err != nil {
log.Printf("ERROR converting location %s:%s: %s", cppURI, cppHL.Range, err)
return nil
}
res = append(res, *inoHL)
}
return &res

case *lsp.WorkspaceEdit: // "textDocument/rename":
return handler.cpp2inoWorkspaceEdit(r)
}
Expand Down Expand Up @@ -1058,19 +1068,23 @@ func (handler *InoHandler) cpp2inoWorkspaceEdit(origWorkspaceEdit *lsp.Workspace
return resWorkspaceEdit
}

func (handler *InoHandler) cpp2inoLocation(inoLocation lsp.Location) (lsp.Location, error) {
cppURI, cppRange, err := handler.cpp2inoDocumentURI(inoLocation.URI, inoLocation.Range)
func (handler *InoHandler) cpp2inoLocation(cppLocation lsp.Location) (lsp.Location, error) {
inoURI, inoRange, err := handler.cpp2inoDocumentURI(cppLocation.URI, cppLocation.Range)
return lsp.Location{
URI: cppURI,
Range: cppRange,
URI: inoURI,
Range: inoRange,
}, err
}

func (handler *InoHandler) cpp2inoDocumentHighlight(highlight *lsp.DocumentHighlight, uri lsp.DocumentURI) {
panic("not implemented")
// if data, ok := handler.data[uri]; ok {
// _, highlight.Range = data.sourceMap.CppToInoRange(highlight.Range)
// }
func (handler *InoHandler) cpp2inoDocumentHighlight(cppHighlight *lsp.DocumentHighlight, cppURI lsp.DocumentURI) (*lsp.DocumentHighlight, error) {
_, inoRange, err := handler.cpp2inoDocumentURI(cppURI, cppHighlight.Range)
if err != nil {
return nil, err
}
return &lsp.DocumentHighlight{
Kind: cppHighlight.Kind,
Range: inoRange,
}, nil
}

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