diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-22 20:18:27 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-22 20:18:27 +0800 |
commit | 659cc0e395719b2816615f1f8efc750292105144 (patch) | |
tree | 27546a483adf6353ee9d8ceff51b9c2e8646440f /server/src | |
parent | 57eefd5142fab69c1e575917945fd3aded42f5ca (diff) | |
download | lua-language-server-659cc0e395719b2816615f1f8efc750292105144.zip |
更新 EmmyTypeUnit
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/definition.lua | 68 | ||||
-rw-r--r-- | server/src/emmy/class.lua | 3 | ||||
-rw-r--r-- | server/src/emmy/manager.lua | 9 | ||||
-rw-r--r-- | server/src/emmy/type.lua | 15 | ||||
-rw-r--r-- | server/src/emmy/typeUnit.lua | 51 | ||||
-rw-r--r-- | server/src/method/textDocument/references.lua | 2 | ||||
-rw-r--r-- | server/src/vm/emmy.lua | 7 | ||||
-rw-r--r-- | server/src/vm/local.lua | 1 | ||||
-rw-r--r-- | server/src/vm/value.lua | 19 |
9 files changed, 140 insertions, 35 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua index a9b9469d..f6440e81 100644 --- a/server/src/core/definition.lua +++ b/server/src/core/definition.lua @@ -23,15 +23,27 @@ local function parseValueSimily(callback, vm, source) end local function parseLocal(callback, vm, source) + ---@type Local local loc = source:bindLocal() - local locSource = loc:getSource() - callback(locSource) + loc:eachInfo(function (info, src) + if Mode == 'definition' then + if info.type == 'set' or info.type == 'local' then + if src.id < source.id then + callback(src) + end + end + elseif Mode == 'reference' then + if info.type == 'set' or info.type == 'local' or info.type == 'return' or info.type == 'get' then + callback(src) + end + end + end) end local function parseValueByValue(callback, vm, source, value, isGlobal) value:eachInfo(function (info, src) - if info.type == 'set' or info.type == 'local' or info.type == 'return' then - if Mode == 'definition' then + if Mode == 'definition' then + if info.type == 'set' or info.type == 'local' or info.type == 'return' then if vm.uri == src:getUri() then if isGlobal or source.id > src.id then callback(src) @@ -39,7 +51,9 @@ local function parseValueByValue(callback, vm, source, value, isGlobal) elseif value.uri == src:getUri() then callback(src) end - elseif Mode == 'reference' then + end + elseif Mode == 'reference' then + if info.type == 'set' or info.type == 'local' or info.type == 'return' or info.type == 'get' then callback(src) end end @@ -54,10 +68,13 @@ local function parseValue(callback, vm, source) parseValueByValue(callback, vm, source, value, isGlobal) local emmy = value:getEmmy() if emmy and emmy.type == 'emmy.type' then - local class = emmy:getClass() - if class and class:getValue() then - parseValueByValue(callback, vm, source, class:getValue(), isGlobal) - end + ---@type EmmyType + local emmyType = emmy + emmyType:eachClass(function (class) + if class and class:getValue() then + parseValueByValue(callback, vm, source, class:getValue(), isGlobal) + end + end) end end local parent = source:get 'parent' @@ -111,19 +128,39 @@ end local function parseClass(callback, vm, source) local className = source:get 'target class' vm.emmyMgr:eachClass(className, function (class) - if class.type == 'emmy.class' then - local src = class:getSource() - callback(src) + if Mode == 'definition' then + if class.type == 'emmy.class' then + local src = class:getSource() + callback(src) + end + elseif Mode == 'reference' then + if class.type == 'emmy.class' or class.type == 'emmy.typeUnit' then + local src = class:getSource() + callback(src) + end end end) end +local function parseFunction(callback, vm, source) + if Mode == 'reference' then + callback(source:bindFunction():getSource()) + source:bindFunction():eachInfo(function (info, src) + if info.type == 'set' or info.type == 'local' or info.type == 'get' then + callback(src) + end + end) + end +end + local function makeList(source) local list = {} local mark = {} return list, function (src) - if source == src then - return + if Mode == 'definition' then + if source == src then + return + end end if mark[src] then return @@ -159,6 +196,9 @@ return function (vm, pos, mode) if source:bindLabel() then parseLabel(callback, vm, source:bindLabel()) end + if source:bindFunction() then + parseFunction(callback, vm, source) + end if source:get 'target uri' then jumpUri(callback, vm, source) end diff --git a/server/src/emmy/class.lua b/server/src/emmy/class.lua index fe67cf40..84854fc5 100644 --- a/server/src/emmy/class.lua +++ b/server/src/emmy/class.lua @@ -1,5 +1,6 @@ local listMgr = require 'vm.list' +---@class EmmyClass local mt = {} mt.__index = mt mt.type = 'emmy.class' @@ -26,7 +27,7 @@ end function mt:eachChild(callback) self._manager:eachClass(self.name, function (obj) - if obj.type == 'emmy.type' then + if obj.type == 'emmy.typeUnit' then callback(obj) end end) diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua index ecc344bf..b86da6d2 100644 --- a/server/src/emmy/manager.lua +++ b/server/src/emmy/manager.lua @@ -1,6 +1,7 @@ local listMgr = require 'vm.list' local newClass = require 'emmy.class' local newType = require 'emmy.type' +local newTypeUnit = require 'emmy.typeUnit' local mt = {} mt.__index = mt @@ -81,10 +82,14 @@ end function mt:addType(source) local typeObj = newType(self, source) - for _, obj in ipairs(source) do + for i, obj in ipairs(source) do + local typeUnit = newTypeUnit(self, obj) local className = obj[1] local list = self:getClass(className) - list[source.id] = typeObj + typeUnit:setParent(typeObj) + list[source.id] = typeUnit + typeObj._childs[i] = typeUnit + obj:set('emmy.typeUnit', typeUnit) end return typeObj end diff --git a/server/src/emmy/type.lua b/server/src/emmy/type.lua index 63653bad..54680977 100644 --- a/server/src/emmy/type.lua +++ b/server/src/emmy/type.lua @@ -8,6 +8,7 @@ local function buildName(source) return table.concat(names, '|') end +---@class EmmyType local mt = {} mt.__index = mt mt.type = 'emmy.type' @@ -24,13 +25,12 @@ function mt:getSource() return listMgr.get(self.source) end -function mt:getClass() - local class = self._manager:eachClass(self.name, function (class) - if class.type == 'emmy.class' then - return class - end - end) - return class +function mt:eachClass(callback) + for _, typeUnit in ipairs(self._childs) do + ---@type EmmyTypeUnit + local emmyTypeUnit = typeUnit + emmyTypeUnit:getClass(callback) + end end function mt:setValue(value) @@ -46,6 +46,7 @@ return function (manager, source) name = buildName(source), source = source.id, _manager = manager, + _childs = {}, }, mt) return self end diff --git a/server/src/emmy/typeUnit.lua b/server/src/emmy/typeUnit.lua new file mode 100644 index 00000000..73d7ea6b --- /dev/null +++ b/server/src/emmy/typeUnit.lua @@ -0,0 +1,51 @@ +local listMgr = require 'vm.list' + +---@class EmmyTypeUnit +local mt = {} +mt.__index = mt +mt.type = 'emmy.typeUnit' + +function mt:getType() + return self.name +end + +function mt:getName() + return self.name +end + +function mt:getSource() + return listMgr.get(self.source) +end + +function mt:getClass(callback) + self._manager:eachClass(self:getName(), function (class) + if class.type == 'emmy.class' then + callback(class) + end + end) +end + +function mt:setValue(value) + self.value = value +end + +function mt:getValue() + return self.value +end + +function mt:setParent(parent) + self.parent = parent +end + +function mt:getParent() + return self.parent +end + +return function (manager, source) + local self = setmetatable({ + name = source[1], + source = source.id, + _manager = manager, + }, mt) + return self +end diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua index 4a876121..ca4bed87 100644 --- a/server/src/method/textDocument/references.lua +++ b/server/src/method/textDocument/references.lua @@ -4,7 +4,7 @@ local LastTask local function findReferences(lsp, uri, position, declarat) local vm = lsp:getVM(uri) - local positions, isGlobal = core.references(vm, position, 'reference') + local positions, isGlobal = core.definition(vm, position, 'reference') if not positions then return nil end diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua index c542cf4b..6ce61c40 100644 --- a/server/src/vm/emmy.lua +++ b/server/src/vm/emmy.lua @@ -36,7 +36,9 @@ function mt:doEmmyClass(action) ---@type emmyMgr local emmyMgr = self.emmyMgr self:instantSource(action) + self:instantSource(action[1]) local class = emmyMgr:addClass(action) + action[1]:set('target class', class:getName()) local extends = action[2] if extends then self:instantSource(extends) @@ -53,13 +55,12 @@ function mt:doEmmyType(action) ---@type emmyMgr local emmyMgr = self.emmyMgr self:instantSource(action) - local type = emmyMgr:addType(action) - self._emmy = type - action:set('emmy.type', type) for _, obj in ipairs(action) do self:instantSource(obj) obj:set('target class', obj[1]) end + local type = emmyMgr:addType(action) + self._emmy = type if self.lsp then self.lsp.global:markGet(self:getUri()) end diff --git a/server/src/vm/local.lua b/server/src/vm/local.lua index 618214ff..c20224de 100644 --- a/server/src/vm/local.lua +++ b/server/src/vm/local.lua @@ -3,6 +3,7 @@ local listMgr = require 'vm.list' local Sort = 0 local Watch = setmetatable({}, {__mode = 'kv'}) +---@class Local local mt = {} mt.__index = mt mt.type = 'local' diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index 63e15cc8..8a0b0861 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -530,19 +530,24 @@ function mt:setEmmy(emmy) return end if emmy.type == 'emmy.class' then - emmy:setValue(self) - emmy:eachChild(function (obj) + ---@type EmmyClass + local emmyClass = emmy + emmyClass:setValue(self) + emmyClass:eachChild(function (obj) local value = obj:getValue() if value then value:mergeValue(self) end end) elseif emmy.type == 'emmy.type' then - emmy:setValue(self) - local class = emmy:getClass() - if class then - self:mergeValue(class:getValue()) - end + ---@type EmmyType + local emmyType = emmy + emmyType:setValue(self) + emmyType:eachClass(function (class) + if class then + self:mergeValue(class:getValue()) + end + end) else return end |