summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/signature.lua22
-rw-r--r--script/parser/guide.lua8
-rw-r--r--test/completion/init.lua17
-rw-r--r--test/highlight/init.lua2
5 files changed, 45 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md
index 0babb4f8..5ba769af 100644
--- a/changelog.md
+++ b/changelog.md
@@ -3,6 +3,7 @@
## 1.16.1
* `FIX` signature: parameters may be misplaced
* `FIX` completion: interface in nested table
+* `FIX` completion: interface not show after `,`
* `FIX` [#400](https://github.com/sumneko/lua-language-server/issues/400)
* `FIX` runtime errors
diff --git a/script/core/signature.lua b/script/core/signature.lua
index ab6d133a..295b5437 100644
--- a/script/core/signature.lua
+++ b/script/core/signature.lua
@@ -99,11 +99,33 @@ local function makeSignatures(call, pos)
return signs
end
+local function isSpace(char)
+ if char == ' '
+ or char == '\n'
+ or char == '\r'
+ or char == '\t' then
+ return true
+ end
+ return false
+end
+
+local function skipSpace(text, offset)
+ for i = offset, 1, -1 do
+ local char = text:sub(i, i)
+ if not isSpace(char) then
+ return i
+ end
+ end
+ return 0
+end
+
return function (uri, pos)
local ast = files.getAst(uri)
if not ast then
return nil
end
+ local text = files.getText(uri)
+ pos = skipSpace(text, pos)
local call = findNearCall(uri, ast, pos)
if not call then
return nil
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 98dca211..c34e65f9 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -460,7 +460,7 @@ function m.isContain(source, offset)
if not start then
return false
end
- return start <= offset and finish >= offset - 1
+ return start <= offset and finish >= offset
end
--- 判断offset在source的影响范围内
@@ -471,7 +471,7 @@ function m.isInRange(source, offset)
if not start then
return false
end
- return start <= offset and finish >= offset - 1
+ return start <= offset and finish >= offset
end
function m.isBetween(source, tStart, tFinish)
@@ -479,7 +479,7 @@ function m.isBetween(source, tStart, tFinish)
if not start then
return false
end
- return start <= tFinish and finish >= tStart - 1
+ return start <= tFinish and finish >= tStart
end
function m.isBetweenRange(source, tStart, tFinish)
@@ -487,7 +487,7 @@ function m.isBetweenRange(source, tStart, tFinish)
if not start then
return false
end
- return start <= tFinish and finish >= tStart - 1
+ return start <= tFinish and finish >= tStart
end
--- 添加child
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 676480f5..7db54f2f 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -2060,6 +2060,23 @@ TEST [[
---@param x cc
local function f(x) end
+f({aaa = 1,$})
+]]
+{
+ {
+ label = 'bbb',
+ kind = define.CompletionItemKind.Property,
+ },
+}
+
+TEST [[
+---@class cc
+---@field aaa number # a1
+---@field bbb number # a2
+
+---@param x cc
+local function f(x) end
+
f({
{
$
diff --git a/test/highlight/init.lua b/test/highlight/init.lua
index 9f899113..2bf639fa 100644
--- a/test/highlight/init.lua
+++ b/test/highlight/init.lua
@@ -39,7 +39,7 @@ function TEST(script)
for _, enter in ipairs(target) do
local start, finish = enter.start, enter.finish
files.removeAll()
- local pos = (start + finish) // 2 + 1
+ local pos = (start + finish) // 2
local new_script = script:gsub('<[!?~]', ' '):gsub('[!?~]>', ' ')
files.setText('', new_script)