diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-22 17:38:51 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-22 17:38:51 +0800 |
commit | 2cc3a207718197fc42b382bc1c82f15fdafb5ee7 (patch) | |
tree | 56668b201e30a234b71dd82afea7b06774b069cf | |
parent | 48c5a0eea7c9478b43d447b0c47ee2f3d7b01f47 (diff) | |
download | lua-language-server-2cc3a207718197fc42b382bc1c82f15fdafb5ee7.zip |
fix #612
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/client.lua | 20 | ||||
-rw-r--r-- | script/provider/provider.lua | 32 |
3 files changed, 43 insertions, 10 deletions
diff --git a/changelog.md b/changelog.md index 6d9882e7..cd4ce15e 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## 2.3.3 * `NEW` config supports prop +* `FIX` [#612](https://github.com/sumneko/lua-language-server/issues/612) ## 2.3.2 `2021-7-21` diff --git a/script/client.lua b/script/client.lua index ad585e85..1897ca21 100644 --- a/script/client.lua +++ b/script/client.lua @@ -38,6 +38,26 @@ function m.getOption(name) return option end +function m.getAbility(name) + local current = m.info.capabilities + while true do + local parent, nextPos = name:match '^([^%.]+)()' + if not parent then + break + end + current = current[parent] + if not current then + return nil + end + if nextPos > #name then + break + else + name = name:sub(nextPos + 1) + end + end + return current +end + local function packMessage(...) local strs = table.pack(...) for i = 1, strs.n do diff --git a/script/provider/provider.lua b/script/provider/provider.lua index e90bbeff..61e43eba 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -291,11 +291,17 @@ proto.on('textDocument/definition', function (params) local targetUri = info.uri if targetUri then if files.exists(targetUri) then - response[i] = define.locationLink(targetUri - , files.range(targetUri, info.target.start, info.target.finish) - , files.range(targetUri, info.target.start, info.target.finish) - , files.range(uri, info.source.start, info.source.finish) - ) + if client.getAbility 'textDocument.definition.linkSupport' then + response[i] = define.locationLink(targetUri + , files.range(targetUri, info.target.start, info.target.finish) + , files.range(targetUri, info.target.start, info.target.finish) + , files.range(uri, info.source.start, info.source.finish) + ) + else + response[i] = define.location(targetUri + , files.range(targetUri, info.target.start, info.target.finish) + ) + end end end end @@ -320,11 +326,17 @@ proto.on('textDocument/typeDefinition', function (params) local targetUri = info.uri if targetUri then if files.exists(targetUri) then - response[i] = define.locationLink(targetUri - , files.range(targetUri, info.target.start, info.target.finish) - , files.range(targetUri, info.target.start, info.target.finish) - , files.range(uri, info.source.start, info.source.finish) - ) + if client.getAbility 'textDocument.typeDefinition.linkSupport' then + response[i] = define.locationLink(targetUri + , files.range(targetUri, info.target.start, info.target.finish) + , files.range(targetUri, info.target.start, info.target.finish) + , files.range(uri, info.source.start, info.source.finish) + ) + else + response[i] = define.location(targetUri + , files.range(targetUri, info.target.start, info.target.finish) + ) + end end end end |