summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-30 15:51:13 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-30 15:51:13 +0800
commitcfbeb125b642836f88052a67826599b2912b2311 (patch)
treed6c66356331e56900a955a31a6e7964f35a100c7 /server/src
parentb4ac3e62ed182b5706e172323cd81cf11275818b (diff)
downloadlua-language-server-cfbeb125b642836f88052a67826599b2912b2311.zip
使用source来找field
Diffstat (limited to 'server/src')
-rw-r--r--server/src/core/completion.lua9
-rw-r--r--server/src/core/document_symbol.lua33
-rw-r--r--server/src/core/vm.lua2
3 files changed, 23 insertions, 21 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 5e6bd5d6..7e19b38f 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -328,9 +328,12 @@ local function searchAsIndex(vm, word, pos, result, source, callback)
searchLocals(vm, pos, word, function (var)
callback(var, CompletionItemKind.Variable)
end)
- for _, index in ipairs(vm.results.indexs) do
- if matchKey(word, index.key) then
- callback(index.key, CompletionItemKind.Property)
+ for _, source in ipairs(vm.results.sources) do
+ if source.isIndex then
+ local index = source.bind
+ if matchKey(word, index.key) then
+ callback(index.key, CompletionItemKind.Property)
+ end
end
end
searchFields(word, vm.results.locals[1], source, function (var)
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua
index 5c7e059b..8d5059b3 100644
--- a/server/src/core/document_symbol.lua
+++ b/server/src/core/document_symbol.lua
@@ -76,24 +76,24 @@ local function buildFunction(vm, func)
}
end
-local function isLocalTable(var)
+local function isLocalTable(var, source)
if not var.value or var.value:getType() ~= 'table' then
return false
end
if var.value.source.start == 0 then
return false
end
- if var.source ~= var.value:getDeclarat() then
+ if source ~= var.value:getDeclarat() then
return false
end
- if var.value.source.finish < var.source.finish then
+ if var.value.source.finish < source.finish then
return false
end
return true
end
-local function buildVar(vm, var)
- if var.source.start == 0 then
+local function buildVar(vm, var, source)
+ if source.start == 0 then
return nil
end
if var.value and var.value:getType() == 'function' and var.value.uri == vm.uri then
@@ -110,17 +110,17 @@ local function buildVar(vm, var)
key = ('[%s]'):format(key)
end
local range
- if isLocalTable(var) then
- range = { var.source.start, var.value.source.finish }
+ if isLocalTable(var, source) then
+ range = { source.start, var.value.source.finish }
else
- range = { var.source.start, var.source.finish }
+ range = { source.start, source.finish }
end
- local hvr = hover(var, var.source)
+ local hvr = hover(var, source)
if not hvr then
return nil
end
local kind
- if var.source.isIndex then
+ if source.isIndex then
kind = SymbolKind.Class
else
kind = SymbolKind.Variable
@@ -131,7 +131,7 @@ local function buildVar(vm, var)
detail = hvr.label:gsub('[\r\n]', ''),
kind = kind,
range = range,
- selectionRange = { var.source.start, var.source.finish },
+ selectionRange = { source.start, source.finish },
}
end
@@ -173,11 +173,12 @@ return function (vm)
for _, func in ipairs(vm.results.funcs) do
symbols[#symbols+1] = buildFunction(vm, func)
end
- for _, loc in ipairs(vm.results.locals) do
- symbols[#symbols+1] = buildVar(vm, loc)
- end
- for _, index in ipairs(vm.results.indexs) do
- symbols[#symbols+1] = buildVar(vm, index)
+ for _, source in ipairs(vm.results.sources) do
+ if source.bind then
+ if source.isLocal or source.isIndex then
+ symbols[#symbols+1] = buildVar(vm, source.bind, source)
+ end
+ end
end
local packedSymbols = packSymbols(symbols)
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index dbc2df65..df096ee4 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -195,7 +195,6 @@ function mt:buildTable(source)
else
if key.type == 'name' then
local field = self:createField(tbl, key[1], key)
- self.results.indexs[#self.results.indexs+1] = field
key.isIndex = true
if value.type == 'list' then
self:setValue(field, value[1], key)
@@ -1435,7 +1434,6 @@ local function compile(ast, lsp, uri)
funcs = {},
calls = {},
strings= {},
- indexs = {},
infos = {},
sources= {},
main = nil,