summaryrefslogtreecommitdiff
path: root/server/src/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-29 16:27:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-29 16:27:01 +0800
commit054351ecf1471c0d0ec3a94bddb0831bf050db82 (patch)
treef6bf16b92d785f64d8192cc9f4f4cdd357591d50 /server/src/core
parentc2762dc29612aa37aa19a0cf3f362449e44dc9f8 (diff)
downloadlua-language-server-054351ecf1471c0d0ec3a94bddb0831bf050db82.zip
更新自动完成
Diffstat (limited to 'server/src/core')
-rw-r--r--server/src/core/completion.lua28
-rw-r--r--server/src/core/vm.lua35
2 files changed, 29 insertions, 34 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index fad75bbe..bff1bd33 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -472,6 +472,9 @@ end
local function searchInResult(result, word, source, vm, pos, callback)
if result.type == 'local' then
+ if result.link then
+ result = result.link
+ end
if source.isArg then
searchAsArg(vm, word, pos, result, callback)
elseif source.isLocal then
@@ -509,30 +512,13 @@ end
local function searchSpecial(vm, pos, callback)
-- 尝试 #
local result, source = findResult(vm, pos, 2)
- if source and source.type == 'index'
- and result.source and result.source.op == '#'
+ if source and source.indexSource and result.source.op == '#'
then
- local name = {}
- local var = result
- while true do
- var = var.parent
- if not var then
- break
- end
- if var.value and var.value.GLOBAL then
- break
- end
- local key = var.key
- if type(key) ~= 'string' or key == '' then
- return
- end
- table.insert(name, 1, key)
- end
- local label = table.concat(name, '.') .. '+1'
+ local label = source.indexSource.indexName .. '+1'
callback(label, CompletionItemKind.Snippet, {
textEdit = {
- start = result.source.start + 1,
- finish = source.finish,
+ start = source.start + 1,
+ finish = source.indexSource.finish,
newText = ('%s] = '):format(label),
}
})
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index 24d75363..42893dd2 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -81,11 +81,21 @@ local mt = {}
mt.__index = mt
function mt:createDummyVar(source, value)
+ if source and source.bind then
+ return source.bind
+ end
local loc = {
type = 'local',
key = '',
source = source or DefaultSource,
}
+
+ if source then
+ source.bind = loc
+ self.results.sources[#self.results.sources+1] = source
+ source.isLocal = true
+ end
+
self:setValue(loc, value, source)
return loc
end
@@ -338,7 +348,7 @@ function mt:runFunction(func)
local index = 0
if func.object then
- local var = self:createArg('self', func.object.colon, self:getValue(func.object))
+ local var = self:createArg('self', func.colon, self:getValue(func.object))
var.hide = true
var.link = func.object
self:setValue(var, func.argValues[1] or self:createValue('nil'))
@@ -354,7 +364,6 @@ function mt:runFunction(func)
index = index + 1
if arg.type == 'name' then
local var = self:createArg(arg[1], arg)
- arg.isArg = true
self:setValue(var, func.argValues[index] or self:createValue('nil'))
func.args[index] = var
elseif arg.type == '...' then
@@ -373,7 +382,7 @@ function mt:runFunction(func)
self:scopePop()
end
-function mt:buildFunction(exp, object)
+function mt:buildFunction(exp, object, colon)
if exp and exp.func then
return exp.func
end
@@ -389,6 +398,7 @@ function mt:buildFunction(exp, object)
func.built = exp
func.upvalues = {}
func.object = object
+ func.colon = colon
exp.func = func
for name, loc in pairs(self.scope.locals) do
func.upvalues[name] = loc
@@ -484,7 +494,7 @@ function mt:tryRequireOne(strValue, mode)
if type(str) == 'string' then
-- 支持 require 'xxx' 的转到定义
local strSource = strValue.source
- strSource.object = strValue
+ strSource.bind = strValue
self.results.sources[#self.results.sources+1] = strSource
strValue.isRequire = true
@@ -902,6 +912,7 @@ function mt:getSimple(simple, mode)
parentName = '?'
end
local object
+ local colon
local lastField = field
for i = 2, #simple do
local obj = simple[i]
@@ -928,6 +939,8 @@ function mt:getSimple(simple, mode)
parentName = parentName .. '(...)'
elseif tp == 'index' then
local child = obj[1]
+ child.indexSource = obj
+ obj.indexName = parentName
local index = self:getIndex(child)
if mode == 'value' or i < #simple then
field = self:getField(value, index, child) or self:createField(value, index, child)
@@ -939,10 +952,6 @@ function mt:getSimple(simple, mode)
field.parentValue = value
value = self:getValue(field)
end
- field.parent = lastField
- lastField = field
- obj.object = object
- obj.parentName = parentName
if obj[1].type == 'string' then
parentName = ('%s[%q]'):format(parentName, index)
elseif obj[1].type == 'number' or obj[1].type == 'boolean' then
@@ -968,8 +977,8 @@ function mt:getSimple(simple, mode)
parentName = parentName .. '.' .. field.key
elseif tp == ':' then
object = field
- object.colon = obj
simple[i-1].colon = obj
+ colon = colon
elseif tp == '.' then
simple[i-1].dot = obj
end
@@ -977,7 +986,7 @@ function mt:getSimple(simple, mode)
if mode == 'value' then
return value, object
elseif mode == 'field' then
- return field, object
+ return field, object, colon
end
error('Unknow simple mode: ' .. mode)
end
@@ -1332,18 +1341,18 @@ end
function mt:doFunction(action)
local name = action.name
- local var, object
+ local var, object, colon
local source
if name then
if name.type == 'simple' then
- var, object = self:getSimple(name, 'field')
+ var, object, colon = self:getSimple(name, 'field')
source = name[#name]
else
var = self:getName(name[1], name)
source = name
end
end
- local func = self:buildFunction(action, object)
+ local func = self:buildFunction(action, object, colon)
if var then
self:setValue(var, func, source)
end