summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-15 20:04:42 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-15 20:04:42 +0800
commitc22679b21f0ed689dc269d49f05712fada02f7ce (patch)
tree8e7f0072082897fef2c5b71316eeec96a976d0d7 /script
parentd80a3db90e27f1c4598bb2bf316891857fe71bb9 (diff)
downloadlua-language-server-c22679b21f0ed689dc269d49f05712fada02f7ce.zip
resolve #589
Diffstat (limited to 'script')
-rw-r--r--script/core/completion.lua14
-rw-r--r--script/parser/guide.lua12
2 files changed, 16 insertions, 10 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index f2eb3356..285adb38 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -398,7 +398,7 @@ local function checkModule(ast, word, offset, results)
end
end
-local function checkFieldFromFieldToIndex(name, parent, word, start, offset)
+local function checkFieldFromFieldToIndex(name, src, parent, word, start, offset)
if name:match '^[%a_][%w_]*$' then
return nil
end
@@ -411,10 +411,16 @@ local function checkFieldFromFieldToIndex(name, parent, word, start, offset)
else
wordStart = offset - #word + 1
end
+ local newText
+ if vm.getKeyType(src) == 'string' then
+ newText = ('[%q]'):format(name)
+ else
+ newText = ('[%s]'):format(name)
+ end
textEdit = {
start = wordStart,
finish = offset,
- newText = ('[%q]'):format(name),
+ newText = newText,
}
local nxt = parent.next
if nxt then
@@ -487,7 +493,7 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul
newText = name,
}
else
- textEdit, additionalTextEdits = checkFieldFromFieldToIndex(name, parent, word, start, offset)
+ textEdit, additionalTextEdits = checkFieldFromFieldToIndex(name, src, parent, word, start, offset)
end
results[#results+1] = {
label = name,
@@ -509,7 +515,7 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res
local count = 0
for _, src in ipairs(refs) do
local name = vm.getKeyName(src)
- if not name or vm.getKeyType(src) ~= 'string' then
+ if not name then
goto CONTINUE
end
if isSameSource(ast, src, start) then
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 108bccf5..8d681fdc 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -888,11 +888,11 @@ function m.getKeyName(obj)
elseif tp == 'doc.alias' then
return obj.alias[1]
elseif tp == 'doc.field' then
- return obj.field[1]
+ return tostring(obj.field[1])
elseif tp == 'doc.field.name' then
- return obj[1]
+ return tostring(obj[1])
elseif tp == 'doc.type.field' then
- return obj.name[1]
+ return tostring(obj.name[1])
elseif tp == 'dummy' then
return obj[1]
end
@@ -952,14 +952,14 @@ function m.getKeyType(obj)
elseif tp == 'doc.alias' then
return 'string'
elseif tp == 'doc.field' then
- return 'string'
+ return type(obj.field[1])
elseif tp == 'doc.type.field' then
- return 'string'
+ return type(obj.name[1])
elseif tp == 'dummy' then
return 'string'
end
if tp == 'doc.field.name' then
- return 'string'
+ return type(obj[1])
end
return m.getKeyTypeOfLiteral(obj)
end