summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-06-13 21:00:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-06-13 21:00:02 +0800
commit484f993c6a1026b7eb04d48ff4aee00e2dcafd54 (patch)
tree2ca3a0da2c4bc39a0c58a2983bb033a1fbefc7ec /script
parent2b5257d3d097c2726e5098a43c333aa20a461c2e (diff)
downloadlua-language-server-484f993c6a1026b7eb04d48ff4aee00e2dcafd54.zip
completion for quoted fields
fix #2088
Diffstat (limited to 'script')
-rw-r--r--script/core/hover/label.lua10
-rw-r--r--script/vm/infer.lua11
2 files changed, 14 insertions, 7 deletions
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua
index 6ce4dde9..62e51927 100644
--- a/script/core/hover/label.lua
+++ b/script/core/hover/label.lua
@@ -134,7 +134,7 @@ local function asField(source)
end
local function asDocFieldName(source)
- local name = source.field[1]
+ local name = vm.viewKey(source, guide.getUri(source)) or '?'
local class
for _, doc in ipairs(source.bindGroup) do
if doc.type == 'doc.class' then
@@ -143,10 +143,12 @@ local function asDocFieldName(source)
end
end
local view = vm.getInfer(source.extends):view(guide.getUri(source))
- if not class then
- return ('(field) ?.%s: %s'):format(name, view)
+ local className = class and class.class[1] or '?'
+ if name:match(guide.namePatternFull) then
+ return ('(field) %s.%s: %s'):format(className, name, view)
+ else
+ return ('(field) %s%s: %s'):format(className, name, view)
end
- return ('(field) %s.%s: %s'):format(class.class[1], name, view)
end
local function asString(source)
diff --git a/script/vm/infer.lua b/script/vm/infer.lua
index 94fdfd88..3bc0b3f7 100644
--- a/script/vm/infer.lua
+++ b/script/vm/infer.lua
@@ -565,11 +565,12 @@ function vm.viewKey(source, uri)
return vm.viewKey(source.types[1], uri)
else
local key = vm.getInfer(source):view(uri)
- return '[' .. key .. ']'
+ return '[' .. key .. ']', key
end
end
if source.type == 'tableindex'
- or source.type == 'setindex' then
+ or source.type == 'setindex'
+ or source.type == 'getindex' then
local index = source.index
local name = vm.getInfer(index):viewLiterals()
if not name then
@@ -587,7 +588,11 @@ function vm.viewKey(source, uri)
return vm.viewKey(source.name, uri)
end
if source.type == 'doc.type.name' then
- return '[' .. source[1] .. ']'
+ return '[' .. source[1] .. ']', source[1]
+ end
+ if source.type == 'doc.type.string' then
+ local name = util.viewString(source[1], source[2])
+ return ('[%s]'):format(name), name
end
local key = vm.getKeyName(source)
if key == nil then