diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-08 17:15:38 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-08 17:15:38 +0800 |
commit | bdbe552e97098e617b8eecb5cd32ec229485fe8b (patch) | |
tree | dd322253b847464c4cca9b246f53c1a4f5173041 | |
parent | 94069457d8a91dc6b53850d2a4a52eaf160de955 (diff) | |
download | lua-language-server-bdbe552e97098e617b8eecb5cd32ec229485fe8b.zip |
部分跨文件
-rw-r--r-- | server/src/core/definition.lua | 67 | ||||
-rw-r--r-- | server/src/service.lua | 4 | ||||
-rw-r--r-- | server/src/vm/source.lua | 4 | ||||
-rw-r--r-- | server/src/vm/value.lua | 1 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 32 |
5 files changed, 87 insertions, 21 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua index 87ca5324..6d5fe93e 100644 --- a/server/src/core/definition.lua +++ b/server/src/core/definition.lua @@ -1,4 +1,56 @@ +local function parseValueCrossFile(vm, value, lsp) + local positions = {} + value:eachInfo(function (info) + if info.type == 'local' and info.source.uri == value.uri then + positions[#positions+1] = { + info.source.start, + info.source.finish, + value.uri, + } + return true + end + end) + if #positions > 0 then + return positions + end + value:eachInfo(function (info) + if info.type == 'set' and info.source.uri == value.uri then + positions[#positions+1] = { + info.source.start, + info.source.finish, + value.uri, + } + end + end) + if #positions > 0 then + return positions + end + local destVM = lsp:getVM(value.uri) + if not destVM then + positions[#positions+1] = { + 0, 0, value.uri, + } + return positions + end + local main = destVM.main + local mainValue = main:getFunction() + local mainSource = mainValue.source + local returnSource = mainSource[#mainSource] + if returnSource.type == 'return' then + positions[#positions+1] = { + returnSource[1].start, + returnSource[1].finish, + value.uri, + } + end + return positions +end + local function parseLocal(vm, loc, lsp) + local value = loc:getValue() + if value.uri ~= vm.uri then + return parseValueCrossFile(vm, value, lsp) + end local positions = {} positions[#positions+1] = { loc.source.start, @@ -11,6 +63,9 @@ local function parseLocal(vm, loc, lsp) end local function parseValue(vm, value, lsp) + if value.uri ~= vm.uri then + return parseValueCrossFile(vm, value, lsp) + end local positions = {} value:eachInfo(function (info) if info.type == 'set' then @@ -65,6 +120,15 @@ local function parseLabel(vm, label, lsp) return positions end +local function jumpUri(vm, source, lsp) + local uri = source:get 'target uri' + local positions = {} + positions[#positions+1] = { + 0, 0, uri, + } + return positions +end + return function (vm, source, lsp) if not source then return nil @@ -79,4 +143,7 @@ return function (vm, source, lsp) if source:bindLabel() then return parseLabel(vm, source:bindLabel(), lsp) end + if source:get 'target uri' then + return jumpUri(vm, source, lsp) + end end diff --git a/server/src/service.lua b/server/src/service.lua index aa85fc49..bb8f59b1 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -320,7 +320,7 @@ function mt:compileVM(uri) local version = obj.version obj.astCost = os.clock() - clock self:_clearChainNode(obj, uri) - self:_clearGlobal(uri, compiled) + --self:_clearGlobal(uri, compiled) local clock = os.clock() local vm = buildVM(ast, self, uri) @@ -350,7 +350,7 @@ function mt:compileVM(uri) end self:_compileChain(obj, compiled) - self:_compileGlobal(compiled) + --self:_compileGlobal(compiled) return obj end diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua index 98102bf7..8c80262a 100644 --- a/server/src/vm/source.lua +++ b/server/src/vm/source.lua @@ -55,11 +55,11 @@ function mt:action() end function mt:setUri(uri) - self._uri = uri + self.uri = uri end function mt:getUri() - return self._uri + return self.uri end function mt:set(name, v) diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index b520054c..39a6f1aa 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -12,6 +12,7 @@ end local mt = {} mt.__index = mt mt.type = 'value' +mt.uri = '' function mt:setType(tp, rate) if type(tp) == 'table' then diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 57b6c1cd..4ff5f372 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -155,13 +155,11 @@ end function mt:getRequire(strValue, destVM) -- 取出对方的主函数 - local main = destVM.results.main + local main = destVM.main -- 获取主函数返回值,注意不能修改对方的环境 - local mainValue - if main.returns then - mainValue = self:getFirstInMulti(main.returns) - else - mainValue = self:createValue('boolean', nil, true) + local mainValue = main:getFunction():getReturn(1) + if not mainValue then + mainValue = self:createValue('any', nil) mainValue.uri = destVM.uri end @@ -170,7 +168,7 @@ end function mt:getLoadFile(strValue, destVM) -- 取出对方的主函数 - local main = destVM.results.main + local main = destVM.main -- loadfile 的返回值就是对方的主函数 local mainValue = main @@ -185,26 +183,23 @@ function mt:tryRequireOne(strValue, mode) if type(str) == 'string' then -- 支持 require 'xxx' 的转到定义 local strSource = strValue.source - strSource.bind = strValue - self.results.sources[#self.results.sources+1] = strSource - strValue.isRequire = true - + self:instantSource(strSource) local uri if mode == 'require' then - uri = self.lsp.workspace:searchPath(self.chunk.func.uri, str) + uri = self.lsp.workspace:searchPath(self:getUri(), str) elseif mode == 'loadfile' then - uri = self.lsp.workspace:loadPath(self.chunk.func.uri, str) + uri = self.lsp.workspace:loadPath(self:getUri(), str) elseif mode == 'dofile' then - uri = self.lsp.workspace:loadPath(self.chunk.func.uri, str) + uri = self.lsp.workspace:loadPath(self:getUri(), str) end if not uri then return nil end - strValue.uri = uri + strSource:set('target uri', uri) -- 如果取不到VM(不编译),则做个标记,之后再取一次 local destVM = self.lsp:getVM(uri) - self.lsp:compileChain(self.chunk.func.uri, uri) + self.lsp:compileChain(self:getUri(), uri) if destVM then if mode == 'require' then return self:getRequire(strValue, destVM) @@ -331,6 +326,7 @@ end function mt:createValue(tp, source, literal) local value = createValue(tp, source, literal) + value.uri = self:getUri() return value end @@ -699,7 +695,8 @@ function mt:doReturn(action) local values = self:unpackList(action) local func = self:getCurrentFunction() values:eachValue(function (n, value) - func:setReturn(n, value) + value.uri = self:getUri() + func:setReturn(n, value, action[n]) end) end @@ -1088,6 +1085,7 @@ function mt:createLocal(key, source, value) loc = createLocal(key, source, value) self:saveLocal(key, loc) self:bindLocal(source, loc, 'local') + value:addInfo('local', source) return loc end |