summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/completion.lua8
-rw-r--r--script/parser/luadoc.lua19
-rw-r--r--test/crossfile/completion.lua12
3 files changed, 30 insertions, 9 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 58b87247..74017ec6 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -892,7 +892,7 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
collect[info.expect] = {
textEdit = {
start = smark and (source.start + #smark) or position,
- finish = smark and (source.start - #smark) or position,
+ finish = smark and (source.finish - #smark) or position,
newText = smark and info.expect or util.viewString(info.expect),
}
}
@@ -919,7 +919,7 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
collect[open] = {
textEdit = {
start = smark and (source.start + #smark) or position,
- finish = smark and (source.start - #smark) or position,
+ finish = smark and (source.finish - #smark) or position,
newText = smark and open or util.viewString(open),
}
}
@@ -945,7 +945,7 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
collect[path] = {
textEdit = {
start = smark and (source.start + #smark) or position,
- finish = smark and (source.start - #smark) or position,
+ finish = smark and (source.finish - #smark) or position,
newText = smark and path or util.viewString(path),
}
}
@@ -1759,6 +1759,8 @@ local function tryLuaDocBySource(state, position, source, results)
}
end
end
+ elseif source.type == 'doc.module' then
+ collectRequireNames('require', state.uri, source.module or '', source, source.smark, position, results)
end
return false
end
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index f6de87fd..195ea815 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -3,7 +3,7 @@ local re = require 'parser.relabel'
local guide = require 'parser.guide'
local parser = require 'parser.newparser'
-local TokenTypes, TokenStarts, TokenFinishs, TokenContents
+local TokenTypes, TokenStarts, TokenFinishs, TokenContents, TokenMarks
local Ci, Offset, pushError, NextComment, Lines
local parseType
local Parser = re.compile([[
@@ -18,15 +18,15 @@ Integer <- ({} {[0-9]+} !'.' {})
-> Integer
String <- ({} StringDef {})
-> String
-StringDef <- '"'
+StringDef <- {'"'}
{~(Esc / !'"' .)*~} -> 1
('"'?)
- / "'"
+ / {"'"}
{~(Esc / !"'" .)*~} -> 1
("'"?)
- / ('[' {:eq: '='* :} '['
+ / {'[' {:eq: '='* :} '['}
{(!StringClose .)*} -> 1
- (StringClose?))
+ StringClose?
StringClose <- ']' =eq ']'
Esc <- '\' -> ''
EChar
@@ -92,12 +92,13 @@ Symbol <- ({} {
TokenFinishs[Ci] = finish - 1
TokenContents[Ci] = content
end,
- String = function (start, content, finish)
+ String = function (start, mark, content, finish)
Ci = Ci + 1
TokenTypes[Ci] = 'string'
TokenStarts[Ci] = start
TokenFinishs[Ci] = finish - 1
TokenContents[Ci] = content
+ TokenMarks[Ci] = mark
end,
Integer = function (start, content, finish)
Ci = Ci + 1
@@ -126,6 +127,7 @@ local function parseTokens(text, offset)
TokenStarts = {}
TokenFinishs = {}
TokenContents = {}
+ TokenMarks = {}
Parser:match(text)
Ci = 0
end
@@ -163,6 +165,10 @@ local function getFinish()
return TokenFinishs[Ci] + Offset + 1
end
+local function getMark()
+ return TokenMarks[Ci]
+end
+
local function try(callback)
local savePoint = Ci
-- rollback
@@ -1077,6 +1083,7 @@ local function parseModule()
nextToken()
result.start = getStart()
result.finish = getFinish()
+ result.smark = getMark()
else
pushError {
type = 'LUADOC_MISS_MODULE_NAME',
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index 4e59096e..ae843d3b 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -838,3 +838,15 @@ TEST {
},
completion = EXISTS
}
+
+TEST {
+ { path = 'abcde.lua', content = '' },
+ {
+ path = 'main.lua',
+ main = true,
+ content = [[
+ ---@module 'ab<??>'
+ ]]
+ },
+ completion = EXISTS
+}