summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/jump-source.lua8
-rw-r--r--script/parser/luadoc.lua4
-rw-r--r--test/tclient/tests/jump-source.lua38
3 files changed, 45 insertions, 5 deletions
diff --git a/script/core/jump-source.lua b/script/core/jump-source.lua
index 76d7324b..15afae39 100644
--- a/script/core/jump-source.lua
+++ b/script/core/jump-source.lua
@@ -8,8 +8,8 @@ return function (results)
if doc then
result.uri = doc.source
result.target.uri = doc.source
- result.target.start = guide.positionOf(doc.line - 1, 0)
- result.target.finish = guide.positionOf(doc.line - 1, 0)
+ result.target.start = guide.positionOf(doc.line - 1, doc.char)
+ result.target.finish = guide.positionOf(doc.line - 1, doc.char)
end
else
local target = result.target
@@ -23,8 +23,8 @@ return function (results)
and doc.bindSource == target then
result.uri = doc.source
result.target.uri = doc.source
- result.target.start = guide.positionOf(doc.line - 1, 0)
- result.target.finish = guide.positionOf(doc.line - 1, 0)
+ result.target.start = guide.positionOf(doc.line - 1, doc.char)
+ result.target.finish = guide.positionOf(doc.line - 1, doc.char)
end
end
end
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 91ed44c0..9ea99f39 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -1415,9 +1415,10 @@ local docSwitch = util.switch()
if fullSource == '' then
return
end
- local source, line = fullSource:match('^(.-):(%d+)$')
+ local source, line, char = fullSource:match('^(.-):?(%d*):?(%d*)$')
source = source or fullSource
line = tonumber(line) or 1
+ char = tonumber(char) or 0
local uri
if furi.split(source) then
uri = source
@@ -1430,6 +1431,7 @@ local docSwitch = util.switch()
finish = getFinish(),
source = uri,
line = line,
+ char = char,
}
return result
end)
diff --git a/test/tclient/tests/jump-source.lua b/test/tclient/tests/jump-source.lua
index ff679826..5b9b7fb6 100644
--- a/test/tclient/tests/jump-source.lua
+++ b/test/tclient/tests/jump-source.lua
@@ -25,6 +25,12 @@ local mt = {}
---@source file:///yyy.lua:30
function mt:ff() end
+
+---@source file:///lib.c
+XX = 1
+
+---@source file:///lib.c:30:20
+YY = 1
]]
}
})
@@ -40,6 +46,8 @@ local a
print(a.x)
print(a.ff)
+print(XX)
+print(YY)
]]
}
})
@@ -73,4 +81,34 @@ print(a.ff)
}
}
}))
+
+ local locations = client:awaitRequest('textDocument/definition', {
+ textDocument = { uri = furi.encode('main.lua') },
+ position = { line = 5, character = 7 },
+ })
+
+ 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 = 6, character = 7 },
+ })
+
+ assert(util.equal(locations, {
+ {
+ uri = 'file:///lib.c',
+ range = {
+ start = { line = 29, character = 20 },
+ ['end'] = { line = 29, character = 20 },
+ }
+ }
+ }))
end)