From e2aad67eedd07cff24a51faf31b8c6984a23d777 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sat, 7 Jan 2023 12:42:34 -0500 Subject: fix texlab go-to-definition actually its their fault for ignoring the lack of capability --- lsp-parse.c | 10 ++++++++-- main.c | 4 +++- test/lsp/go/main.go | 18 ++++++++++++++++++ test/lsp/js/main.js | 13 +++++++++++++ test/lsp/tex/thing.tex | 7 +++++++ 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 test/lsp/js/main.js create mode 100644 test/lsp/tex/thing.tex diff --git a/lsp-parse.c b/lsp-parse.c index 56a980d..f794c4b 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -540,15 +540,21 @@ static bool parse_hover(LSP *lsp, const JSON *json, LSPResponse *response) { return true; } -// parse a Location: {uri: DocumentUri, range: Range} +// parse a Location or a LocationLink static bool parse_location(LSP *lsp, const JSON *json, JSONValue value, LSPLocation *location) { if (!lsp_expect_object(lsp, value, "Location")) return false; JSONObject object = value.val.object; JSONValue uri = json_object_get(json, object, "uri"); + JSONValue range = json_object_get(json, object, "range"); + if (uri.type == JSON_UNDEFINED) { + // maybe it's a LocationLink + uri = json_object_get(json, object, "targetUri"); + range = json_object_get(json, object, "targetRange"); + } + if (!parse_document_uri(lsp, json, uri, &location->document)) return false; - JSONValue range = json_object_get(json, object, "range"); if (!parse_range(lsp, json, range, &location->range)) return false; return true; diff --git a/main.c b/main.c index ff62481..d035efc 100644 --- a/main.c +++ b/main.c @@ -10,7 +10,9 @@ - bad json can give "Unexpected error: client exited without proper shutdown sequence" - containerName not always given in workspace/symbols - clangd bug report: - - textDocumemt/definition on ted.h declarations just gives you the declaration + - textDocument/definition on ted.h declarations just gives you the declaration +- texlab bug report: + - textDocument/definition gives LocationLink regardless of client capabilities FUTURE FEATURES: - write first to .tmp then rename to . this prevents freak occurences, e.g. power outage during file write, diff --git a/test/lsp/go/main.go b/test/lsp/go/main.go index e69de29..d60bcd1 100644 --- a/test/lsp/go/main.go +++ b/test/lsp/go/main.go @@ -0,0 +1,18 @@ +package main; +import ( + "fmt" +) + +type X struct { + y int +} + +func main() { + _, err := fmt.Println("hello world"); + if err != nil { + return; + } + var a X + println(a.y); + +} diff --git a/test/lsp/js/main.js b/test/lsp/js/main.js new file mode 100644 index 0000000..ccf94ed --- /dev/null +++ b/test/lsp/js/main.js @@ -0,0 +1,13 @@ +/** this is my favorit funciton */ +function funciton() { + var xYz = 123; + xYz += 555; + console.log(xYz); +} + +function main() { + funciton(); +} + +main(); +funciton(); diff --git a/test/lsp/tex/thing.tex b/test/lsp/tex/thing.tex new file mode 100644 index 0000000..337261e --- /dev/null +++ b/test/lsp/tex/thing.tex @@ -0,0 +1,7 @@ +\documentclass{article} +\newcommand{\Sin}[1]{\sin\left(#1\right)} +\begin{document} +$$x^2 + \pi = 5\pi - \sin\sqrt{100+12}$$ +$$\Sin{123}$$ + +\end{document} -- cgit v1.2.3