summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-31 11:13:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-31 11:13:35 +0800
commit97d11cb4643d6b2d032337594c387cd49576a68e (patch)
tree7870f90f46e2eb36f714749dfce80d12a0ce2db9
parentb4e36a946a42a35d49290e095ff044f2ffa051e9 (diff)
downloadlua-language-server-97d11cb4643d6b2d032337594c387cd49576a68e.zip
更新全局变量的标记
-rw-r--r--server/src/core/completion.lua26
-rw-r--r--server/src/core/document_symbol.lua50
-rw-r--r--server/src/core/hover.lua2
-rw-r--r--server/src/core/vm.lua12
-rw-r--r--server/src/utility.lua3
-rw-r--r--server/test/completion/init.lua2
-rw-r--r--server/test/document_symbol/init.lua56
-rw-r--r--server/test/hover/init.lua2
8 files changed, 71 insertions, 82 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 7e19b38f..98654a65 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -129,15 +129,15 @@ local function sortPairs(t)
end
end
-local function searchFields(name, parent, source, callback)
- if not parent or not parent.value then
+local function searchFields(name, parentValue, source, callback)
+ if not parentValue then
return
end
if type(name) ~= 'string' then
return
end
local map = {}
- parent.value:eachField(function (key, field)
+ parentValue:eachField(function (key, field)
if type(key) ~= 'string' then
goto CONTINUE
end
@@ -176,7 +176,7 @@ local function getKind(var, default)
return CompletionItemKind.Enum
end
if value:getType() == 'function' then
- if var.parent and var.parent.value and var.parent.value.GLOBAL ~= true then
+ if value.object then
return CompletionItemKind.Method
else
return CompletionItemKind.Function
@@ -236,7 +236,7 @@ local function getDocument(var, source)
end
local function searchAsLocal(vm, word, pos, result, source, callback)
- searchFields(word, vm.results.locals[1], source, function (var)
+ searchFields(word, vm.env, source, function (var)
callback(var, CompletionItemKind.Variable)
end)
@@ -247,7 +247,7 @@ local function searchAsLocal(vm, word, pos, result, source, callback)
end
local function searchAsArg(vm, word, pos, result, source, callback)
- searchFields(word, vm.results.locals[1], source, function (var)
+ searchFields(word, vm.env, source, function (var)
if var.value.lib then
return
end
@@ -262,7 +262,7 @@ local function searchAsGlobal(vm, word, pos, result, source, callback)
searchLocals(vm, pos, word, function (var)
callback(var, CompletionItemKind.Variable)
end)
- searchFields(word, vm.results.locals[1], source, function (var)
+ searchFields(word, result.parentValue, source, function (var)
callback(var, CompletionItemKind.Field)
end)
searchKeyWords(word, function (name)
@@ -271,7 +271,7 @@ local function searchAsGlobal(vm, word, pos, result, source, callback)
end
local function searchAsSuffix(result, source, word, callback)
- searchFields(word, result.parent, source, function (var)
+ searchFields(word, result.parentValue, source, function (var)
callback(var, CompletionItemKind.Field)
end)
end
@@ -336,7 +336,7 @@ local function searchAsIndex(vm, word, pos, result, source, callback)
end
end
end
- searchFields(word, vm.results.locals[1], source, function (var)
+ searchFields(word, result.parentValue, source, function (var)
callback(var, CompletionItemKind.Field)
end)
end
@@ -375,11 +375,13 @@ local function findClosePos(vm, pos)
start = pos,
finish = pos,
object = sep.type == ':' and parent,
+ isSuffix = true,
[1] = '',
}
local result = {
type = 'field',
parent = parent,
+ parentValue = parent.value,
key = '',
}
return result, source
@@ -485,10 +487,10 @@ local function searchInResult(result, word, source, vm, pos, callback)
elseif result.type == 'field' then
if source.isIndex then
searchAsIndex(vm, word, pos, result, source, callback)
- elseif result.parent and result.parent.value and result.parent.value.GLOBAL == true then
- searchAsGlobal(vm, word, pos, result, source, callback)
- else
+ elseif source.isSuffix then
searchAsSuffix(result, source, word, callback)
+ else
+ searchAsGlobal(vm, word, pos, result, source, callback)
end
end
end
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua
index 8d5059b3..199aab7b 100644
--- a/server/src/core/document_symbol.lua
+++ b/server/src/core/document_symbol.lua
@@ -31,39 +31,21 @@ local SymbolKind = {
TypeParameter = 26,
}
-local function buildFunction(vm, func)
- local source = func.source
- local declarat = func:getDeclarat()
- local name
- local var
- if declarat then
- if declarat.type == 'function' then
- var = declarat.name and declarat.name.bind
- else
- var = declarat.bind
- end
- end
- if var then
- name = hoverName(var, declarat)
- else
- name = ''
+local function buildFunction(vm, var, source)
+ local func = var.value
+ if func.source.start == 0 then
+ return nil
end
- local hvr = hoverFunction(name, func, declarat and declarat.object)
+ local name = hoverName(var, source)
+ local hvr = hoverFunction(name, func, source.object)
if not hvr then
return nil
end
- local selectionRange
- local range
+ local selectionRange = { source.start, source.finish }
+ local range = { math.min(source.start, func.source.start), func.source.finish }
local kind = SymbolKind.Function
- if var then
- range = { math.min(source.start, declarat.start), source.finish }
- selectionRange = { declarat.start, declarat.finish }
- if var.parent and var.parent.value and not var.parent.value.GLOBAL then
- kind = SymbolKind.Field
- end
- else
- range = { source.start, source.finish }
- selectionRange = { source.start, source.start }
+ if source.isSuffix then
+ kind = SymbolKind.Field
end
return {
@@ -96,7 +78,10 @@ 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
+ if var.value:getType() == 'function' then
+ return buildFunction(vm, var, source)
+ end
+ if not source.isLocal and not source.isIndex then
return nil
end
if var.hide then
@@ -170,14 +155,9 @@ end
return function (vm)
local symbols = {}
- for _, func in ipairs(vm.results.funcs) do
- symbols[#symbols+1] = buildFunction(vm, func)
- end
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
+ symbols[#symbols+1] = buildVar(vm, source.bind, source)
end
end
diff --git a/server/src/core/hover.lua b/server/src/core/hover.lua
index 82e2ed9c..120d65f5 100644
--- a/server/src/core/hover.lua
+++ b/server/src/core/hover.lua
@@ -318,7 +318,7 @@ local function getValueHover(name, valueType, result, lib)
local tp = result.type
if tp == 'field' then
- if result.parent and result.parent.value and result.parent.value.GLOBAL then
+ if result.GLOBAL then
tp = 'global'
end
end
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index 8359c470..66fdd2c6 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -99,6 +99,7 @@ function mt:createField(value, index, source)
if self.lsp and self:isGlobal(field) then
self.lsp.global:markSet(self.chunk.func.uri)
end
+ field.parentValue = value
return field
end
@@ -253,6 +254,9 @@ function mt:setValue(var, value, source)
self:addInfo(var, 'set', source, value)
value:addInfo('set', source)
end
+ if var.GLOBAL then
+ value.GLOBAL = true
+ end
var.value = value
return value
end
@@ -260,6 +264,9 @@ end
function mt:getValue(var, source)
if not var.value then
var.value = self:createValue('any', source or self:getDefaultSource())
+ if var.GLOBAL then
+ var.value.GLOBAL = true
+ end
end
return var.value
end
@@ -854,6 +861,7 @@ function mt:getSimple(simple, mode)
local obj = simple[i]
local tp = obj.type
obj.uri = self.chunk.func.uri
+ obj.isSuffix = true
value = self:selectList(value, 1)
if tp == 'call' then
@@ -883,13 +891,11 @@ function mt:getSimple(simple, mode)
local index = self:getIndex(child)
if mode == 'value' or i < #simple then
field = self:getField(value, index, obj) or self:createField(value, index, obj)
- field.parentValue = value
value = self:getValue(field, obj)
self:addInfo(field, 'get', obj)
value:addInfo('get', obj)
else
field = self:createField(value, index, obj)
- field.parentValue = value
value = self:getValue(field, obj)
end
field.parent = lastField
@@ -905,13 +911,11 @@ function mt:getSimple(simple, mode)
value:inference('string', 0.2)
if mode == 'value' or i < #simple then
field = self:getField(value, obj[1], obj) or self:createField(value, obj[1], obj)
- field.parentValue = value
value = self:getValue(field, obj)
self:addInfo(field, 'get', obj)
value:addInfo('get', obj)
else
field = self:createField(value, obj[1], obj)
- field.parentValue = value
value = self:getValue(field, obj)
end
field.parent = lastField
diff --git a/server/src/utility.lua b/server/src/utility.lua
index b0d44a60..3f0df110 100644
--- a/server/src/utility.lua
+++ b/server/src/utility.lua
@@ -29,6 +29,9 @@ function table.dump(tbl)
if table_mark[tbl] then
return '<Circle Table>'
end
+ if tab > 10 then
+ return '<Deep Table>'
+ end
table_mark[tbl] = true
local keys = {}
for key in pairs(tbl) do
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index 848162c3..c8089c50 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -287,7 +287,7 @@ xxx()
},
{
label = 'xxx',
- kind = CompletionItemKind.Method,
+ kind = CompletionItemKind.Function,
documentation = EXISTS,
},
}
diff --git a/server/test/document_symbol/init.lua b/server/test/document_symbol/init.lua
index 7d7a6b23..ff66cac2 100644
--- a/server/test/document_symbol/init.lua
+++ b/server/test/document_symbol/init.lua
@@ -98,19 +98,19 @@ end
}
}
-TEST [[
-return function ()
-end
-]]
-{
- [1] = {
- name = '',
- detail = 'function ()',
- kind = SymbolKind.Function,
- range = {8, 22},
- selectionRange = {8, 8},
- }
-}
+--TEST [[
+--return function ()
+--end
+--]]
+--{
+-- [1] = {
+-- name = '',
+-- detail = 'function ()',
+-- kind = SymbolKind.Function,
+-- range = {8, 22},
+-- selectionRange = {8, 8},
+-- }
+--}
TEST [[
f = function ()
@@ -320,21 +320,21 @@ local t = {
}
}
-TEST[[
-local function g()
-end
-
-g = 1
-]]{
- [1] = {
- name = 'g',
- detail = 'function g()',
- kind = SymbolKind.Function,
- range = {1, 22},
- selectionRange = {16, 16},
- children = EXISTS,
- }
-}
+--TEST[[
+--local function g()
+--end
+--
+--g = 1
+--]]{
+-- [1] = {
+-- name = 'g',
+-- detail = 'function g()',
+-- kind = SymbolKind.Function,
+-- range = {1, 22},
+-- selectionRange = {16, 16},
+-- children = EXISTS,
+-- }
+--}
TEST[[
function f(...)
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index c618e49e..ca8cf823 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -108,7 +108,7 @@ TEST [[
t = {}
t.<?x?> = 1
]]
-"field t.x: number = 1"
+"global t.x: number = 1"
TEST [[
local mt = {}