summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/client.lua20
-rw-r--r--script/provider/provider.lua32
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