summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-14 18:46:12 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-14 18:46:12 +0800
commit4a0a07f81df346170bc71ca83b154448faf1f586 (patch)
treedfe3f77b680e5373dca52713fd799e109bcb905f
parentb154ddeb48450cdb78a589abf3705d3f9df758d7 (diff)
downloadlua-language-server-4a0a07f81df346170bc71ca83b154448faf1f586.zip
bind source for class
-rw-r--r--script/core/jump-source.lua3
-rw-r--r--script/parser/luadoc.lua4
-rw-r--r--script/provider/build-meta.lua1
-rw-r--r--test/tclient/tests/jump-source.lua37
4 files changed, 44 insertions, 1 deletions
diff --git a/script/core/jump-source.lua b/script/core/jump-source.lua
index 15afae39..2de23b29 100644
--- a/script/core/jump-source.lua
+++ b/script/core/jump-source.lua
@@ -3,7 +3,8 @@ local guide = require 'parser.guide'
---@param results table
return function (results)
for _, result in ipairs(results) do
- if result.target.type == 'doc.field.name' then
+ if result.target.type == 'doc.field.name'
+ or result.target.type == 'doc.class.name' then
local doc = result.target.parent.source
if doc then
result.uri = doc.source
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 9ea99f39..2cde6bff 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -1787,6 +1787,10 @@ local function bindCommentsAndFields(binded)
if class then
class.bindSource = nil
end
+ if source then
+ doc.source = source
+ source.bindSource = doc
+ end
class = doc
bindCommentsToDoc(doc, comments)
comments = {}
diff --git a/script/provider/build-meta.lua b/script/provider/build-meta.lua
index 2c4a29c2..baabe39c 100644
--- a/script/provider/build-meta.lua
+++ b/script/provider/build-meta.lua
@@ -105,6 +105,7 @@ local function buildText(root, class)
lines[#lines+1] = ('---@field %s %s'):format(field.name, field.typeName)
end
+ lines[#lines+1] = ('---@source %s'):format(class.location:gsub('#', ':'))
local name = mergeString(root, class.namespace, class.name)
lines[#lines+1] = ('%s = {}'):format(name)
lines[#lines+1] = ''
diff --git a/test/tclient/tests/jump-source.lua b/test/tclient/tests/jump-source.lua
index 5b9b7fb6..b6ad4da0 100644
--- a/test/tclient/tests/jump-source.lua
+++ b/test/tclient/tests/jump-source.lua
@@ -31,6 +31,11 @@ XX = 1
---@source file:///lib.c:30:20
YY = 1
+
+---@source file:///lib.c
+---@class BBB
+---@source file:///lib.c
+BBB = {}
]]
}
})
@@ -48,6 +53,8 @@ print(a.x)
print(a.ff)
print(XX)
print(YY)
+---@type BBB
+print(BBB)
]]
}
})
@@ -111,4 +118,34 @@ print(YY)
}
}
}))
+
+ local locations = client:awaitRequest('textDocument/definition', {
+ textDocument = { uri = furi.encode('main.lua') },
+ position = { line = 7, character = 10 },
+ })
+
+ assert(util.equal(locations, {
+ {
+ uri = 'file:///lib.c',
+ range = {
+ start = { line = 0, character = 0 },
+ ['end'] = { line = 0, character = 0 },
+ }
+ }
+ }))
+
+ local locations = client:awaitRequest('textDocument/definition', {
+ textDocument = { uri = furi.encode('main.lua') },
+ position = { line = 8, character = 7 },
+ })
+
+ assert(util.equal(locations, {
+ {
+ uri = 'file:///lib.c',
+ range = {
+ start = { line = 0, character = 0 },
+ ['end'] = { line = 0, character = 0 },
+ }
+ }
+ }))
end)