diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-08 13:26:27 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-08 13:26:27 +0800 |
commit | 2ce73841e83f44212c20bfd997bc1874cda9e3c0 (patch) | |
tree | 49c32b171b54ef126f867b802e3693831089779e /server-beta/src | |
parent | fe9dfabffeb6460f41c9f74fbeb4093db67bed4a (diff) | |
download | lua-language-server-2ce73841e83f44212c20bfd997bc1874cda9e3c0.zip |
整理代码
Diffstat (limited to 'server-beta/src')
23 files changed, 47 insertions, 1258 deletions
diff --git a/server-beta/src/core/diagnostics/undefined-global.lua b/server-beta/src/core/diagnostics/undefined-global.lua index 6c9abaca..8476df61 100644 --- a/server-beta/src/core/diagnostics/undefined-global.lua +++ b/server-beta/src/core/diagnostics/undefined-global.lua @@ -32,7 +32,7 @@ return function (uri, callback) searcher.eachGlobal(ast.ast, function (info) local source = info.source local key = info.key - local skey = key:match '^s|(.+)$' + local skey = key and key:match '^s|(.+)$' if not skey then return end diff --git a/server-beta/src/parser/ast.lua b/server-beta/src/parser/ast.lua index 953cac67..a54ef937 100644 --- a/server-beta/src/parser/ast.lua +++ b/server-beta/src/parser/ast.lua @@ -80,7 +80,12 @@ local function checkMissEnd(start) if not finish then return end - err.info.related = { start, finish } + err.info.related = { + { + start = start, + finish = finish, + } + } PushError { type = 'MISS_END', start = start, diff --git a/server-beta/src/pub/pub.lua b/server-beta/src/pub/pub.lua index 1591ba31..0888dbc3 100644 --- a/server-beta/src/pub/pub.lua +++ b/server-beta/src/pub/pub.lua @@ -69,7 +69,7 @@ function m.pushTask(brave, info) end brave.taskpad:push(info.name, info.id, info.params) brave.taskMap[info.id] = info - log.info(('Push task %q(%d) to # %d, queue length %d'):format(info.name, info.id, brave.id, #m.taskQueue)) + --log.info(('Push task %q(%d) to # %d, queue length %d'):format(info.name, info.id, brave.id, #m.taskQueue)) return true end @@ -81,7 +81,7 @@ function m.popTask(brave, id, result) return end brave.taskMap[id] = nil - log.info(('Pop task %q(%d) from # %d'):format(info.name, info.id, brave.id)) + --log.info(('Pop task %q(%d) from # %d'):format(info.name, info.id, brave.id)) m.checkWaitingTask(brave) if not info.removed then info.removed = true @@ -125,7 +125,7 @@ function m.task(name, params) -- 当有勇者提交任务反馈后,尝试把按顺序将堆积任务 -- 交给该勇者 m.taskQueue[#m.taskQueue+1] = info - log.info(('Add task %q(%d) in queue, length %d.'):format(name, info.id, #m.taskQueue)) + --log.info(('Add task %q(%d) in queue, length %d.'):format(name, info.id, #m.taskQueue)) return await.wait(function (waker) info.callback = waker end) @@ -153,7 +153,7 @@ function m.syncTask(name, params, callback) -- 当有勇者提交任务反馈后,尝试把按顺序将堆积任务 -- 交给该勇者 m.taskQueue[#m.taskQueue+1] = info - log.info(('Add task %q(%d) in queue, length %d.'):format(name, info.id, #m.taskQueue)) + --log.info(('Add task %q(%d) in queue, length %d.'):format(name, info.id, #m.taskQueue)) return info end diff --git a/server-beta/src/searcher-old/boolean.lua b/server-beta/src/searcher-old/boolean.lua deleted file mode 100644 index f92670e1..00000000 --- a/server-beta/src/searcher-old/boolean.lua +++ /dev/null @@ -1,43 +0,0 @@ -local guide = require 'parser.guide' - -local m = {} - -function m:eachDef(source, callback) - local parent = source.parent - if not parent then - return - end - if parent.type ~= 'setindex' and parent.type ~= 'getindex' then - return - end - local node = parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, function (info) - if info.mode == 'set' then - callback(info) - end - end) -end - -function m:eachRef(source, callback) - local parent = source.parent - if not parent then - return - end - if parent.type ~= 'setindex' and parent.type ~= 'getindex' then - return - end - local node = parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, function (info) - if info.mode == 'set' or info.mode == 'get' then - callback(info) - end - end) -end - -function m:getValue(source) - return source -end - -return m diff --git a/server-beta/src/searcher-old/field.lua b/server-beta/src/searcher-old/field.lua deleted file mode 100644 index c5667b04..00000000 --- a/server-beta/src/searcher-old/field.lua +++ /dev/null @@ -1,38 +0,0 @@ -local guide = require 'parser.guide' -local checkSMT = require 'searcher.setmetatable' - -local m = {} - -function m:eachDef(source, callback) - local parent = source.parent - local key = guide.getKeyName(source) - self:eachField(parent, key, function (info) - if info.mode == 'set' then - callback(info) - end - end) -end - -function m:eachRef(source, callback) - local parent = source.parent - local key = guide.getKeyName(source) - self:eachField(parent, key, function (info) - if info.mode == 'set' or info.mode == 'set' then - callback(info) - end - end) -end - -function m:eachField(source, key, callback) - self:eachField(source.parent, key, callback) -end - -function m:eachValue(source, callback) - self:eachValue(source.parent, callback) -end - -function m:getValue(source) - return self:getValue(source.parent) -end - -return m diff --git a/server-beta/src/searcher-old/getfield.lua b/server-beta/src/searcher-old/getfield.lua deleted file mode 100644 index 2fcd2d4b..00000000 --- a/server-beta/src/searcher-old/getfield.lua +++ /dev/null @@ -1,77 +0,0 @@ -local guide = require 'parser.guide' -local checkSMT = require 'searcher.setmetatable' - -local m = {} - -function m:eachRef(source, callback) - local node = source.node - if node.type == 'setfield' - or node.type == 'getfield' - or node.type == 'setmethod' - or node.type == 'getmethod' - or node.type == 'setindex' - or node.type == 'getindex' then - local key = guide.getKeyName(node) - self:eachField(node.node, key, function (info) - if info.mode == 'set' or info.mode == 'get' then - callback(info) - end - end) - else - self:eachRef(node, callback) - end -end - -function m:eachField(source, key, callback) - local used = {} - local found = false - used[source] = true - - self:eachRef(source, function (info) - local src = info.source - used[src] = true - local child, mode, value = self:childMode(src) - if child then - if key == guide.getKeyName(child) then - callback { - uri = self.uri, - source = child, - mode = mode, - } - end - if value then - info.searcher:eachField(value, key, callback) - end - return - end - if src.type == 'getglobal' then - local parent = src.parent - child, mode = info.searcher:childMode(parent) - if child then - if key == guide.getKeyName(child) then - callback { - uri = self.uri, - source = child, - mode = mode, - } - end - end - elseif src.type == 'setglobal' then - info.searcher:eachField(src.value, key, callback) - else - info.searcher:eachField(src, key, callback) - end - end) - - checkSMT(self, key, used, found, callback) -end - -function m:getValue(source) - if source.type == 'setfield' - or source.type == 'setmethod' - or source.type == 'setindex' then - return source.value and self:getValue(source.value) - end -end - -return m diff --git a/server-beta/src/searcher-old/getglobal.lua b/server-beta/src/searcher-old/getglobal.lua deleted file mode 100644 index 1295d769..00000000 --- a/server-beta/src/searcher-old/getglobal.lua +++ /dev/null @@ -1,157 +0,0 @@ -local guide = require 'parser.guide' -local checkSMT = require 'searcher.setmetatable' - -local m = {} - -function m:eachDef(source, callback) - -- _ENV - local key = guide.getKeyName(source) - self:eachField(source.node, key, function (info) - if info.mode == 'set' then - callback(info) - end - end) - self:eachSpecial(function (name, src) - if name == '_G' then - local parent = src.parent - if guide.getKeyName(parent) == key then - callback { - source = parent, - uri = self.uri, - mode = 'set', - } - end - elseif name == 'rawset' then - local t, k = self:callArgOf(src.parent) - if self:getSpecialName(t) == '_G' - and guide.getKeyName(k) == key then - callback { - source = src.parent, - uri = self.uri, - mode = 'set', - } - end - end - end) -end - -function m:eachRef(source, callback) - -- _ENV - local key = guide.getKeyName(source) - self:eachField(source.node, key, function (info) - if info.mode == 'set' or info.mode == 'get' then - callback(info) - end - end) - self:eachSpecial(function (name, src) - if name == '_G' then - local parent = src.parent - if guide.getKeyName(parent) == key then - if parent.type:sub(1, 3) == 'set' then - callback { - source = parent, - uri = self.uri, - mode = 'set', - } - else - callback { - source = parent, - uri = self.uri, - mode = 'get', - } - end - end - elseif name == 'rawset' then - local t, k = self:callArgOf(src.parent) - if self:getSpecialName(t) == '_G' - and guide.getKeyName(k) == key then - callback { - source = src.parent, - uri = self.uri, - mode = 'set', - } - end - elseif name == 'rawget' then - local t, k = self:callArgOf(src.parent) - if self:getSpecialName(t) == '_G' - and guide.getKeyName(k) == key then - callback { - source = src.parent, - uri = self.uri, - mode = 'set', - } - end - end - end) -end - -function m:eachField(source, key, callback) - local used = {} - local found = false - used[source] = true - - self:eachRef(source, function (info) - local src = info.source - used[src] = true - local child, mode, value = info.searcher:childMode(src) - if child then - if key == guide.getKeyName(child) then - callback { - source = child, - uri = info.uri, - mode = mode, - } - end - if value then - info.searcher:eachField(value, key, callback) - end - return - end - if src.type == 'getglobal' then - local parent = src.parent - child, mode, value = info.searcher:childMode(parent) - if child then - if key == guide.getKeyName(child) then - callback { - source = child, - uri = info.uri, - mode = mode, - } - end - if value then - info.searcher:eachField(value, key, callback) - end - end - elseif src.type == 'setglobal' then - info.searcher:eachField(src.value, key, callback) - else - info.searcher:eachField(src, key, callback) - end - end) - - checkSMT(self, key, used, found, callback) -end - -function m:eachValue(source, callback) - callback { - source = source, - uri = self.uri, - } - self:eachDef(source, function (info) - local src = info.source - if src.value then - callback { - source = src.value, - uri = info.uri, - } - end - end) -end - -function m:getValue(source) - if source.type == 'setglobal' then - return source.value and self:getValue(source.value) - end -end - -return m diff --git a/server-beta/src/searcher-old/getlocal.lua b/server-beta/src/searcher-old/getlocal.lua deleted file mode 100644 index 4ffc871f..00000000 --- a/server-beta/src/searcher-old/getlocal.lua +++ /dev/null @@ -1,23 +0,0 @@ -local m = {} - -function m:eachDef(source, callback) - self:eachDef(source.loc, callback) -end - -function m:eachRef(source, callback) - self:eachRef(source.loc, callback) -end - -function m:eachField(source, key, callback) - self:eachField(source.loc, key, callback) -end - -function m:eachValue(source, callback) - self:eachValue(source.loc, callback) -end - -function m:getValue(source) - return self:getValue(source.loc) -end - -return m diff --git a/server-beta/src/searcher-old/goto.lua b/server-beta/src/searcher-old/goto.lua deleted file mode 100644 index 8698eef1..00000000 --- a/server-beta/src/searcher-old/goto.lua +++ /dev/null @@ -1,16 +0,0 @@ -local guide = require 'parser.guide' - -local m = {} - -function m:eachDef(source, callback) - local name = source[1] - local label = guide.getLabel(source, name) - if label then - callback { - source = label, - uri = self.uri, - } - end -end - -return m diff --git a/server-beta/src/searcher-old/index.lua b/server-beta/src/searcher-old/index.lua deleted file mode 100644 index f05a57e6..00000000 --- a/server-beta/src/searcher-old/index.lua +++ /dev/null @@ -1,3 +0,0 @@ -local m = {} - -return m diff --git a/server-beta/src/searcher-old/init.lua b/server-beta/src/searcher-old/init.lua deleted file mode 100644 index b5f0a3f8..00000000 --- a/server-beta/src/searcher-old/init.lua +++ /dev/null @@ -1,400 +0,0 @@ -local guide = require 'parser.guide' -local files = require 'files' -local methods = require 'searcher.methods' -local tableUnpack = table.unpack -local error = error -local setmetatable = setmetatable -local assert = assert - -_ENV = nil -local specials = { - ['_G'] = true, - ['rawset'] = true, - ['rawget'] = true, - ['setmetatable'] = true, - ['require'] = true, - ['dofile'] = true, - ['loadfile'] = true, -} - ----@class searcher_old -local mt = {} -mt.__index = mt -mt.__name = 'searcher' - ---- 获取特殊对象的名字 -function mt:getSpecialName(source) - local spName = self.cache.specialName[source] - if spName ~= nil then - if spName then - return spName - end - return nil - end - local function getName(info) - local src = info.source - if src.type == 'getglobal' then - local node = src.node - if node.tag ~= '_ENV' then - return nil - end - local name = guide.getKeyName(src) - if name:sub(1, 2) ~= 's|' then - return nil - end - spName = name:sub(3) - if not specials[spName] then - spName = nil - end - elseif src.type == 'local' then - if src.tag == '_ENV' then - spName = '_G' - end - elseif src.type == 'getlocal' then - local loc = src.loc - if loc.tag == '_ENV' then - spName = '_G' - end - end - end - self:eachValue(source, getName) - self.cache.specialName[source] = spName or false - return spName -end - ---- 遍历特殊对象 ----@param callback fun(name:string, source:table) -function mt:eachSpecial(callback) - local cache = self.cache.special - if cache then - for i = 1, #cache do - callback(cache[i][1], cache[i][2]) - end - return - end - cache = {} - self.cache.special = cache - guide.eachSource(self.ast, function (source) - if source.type == 'getlocal' - or source.type == 'getglobal' - or source.type == 'local' - or source.type == 'field' - or source.type == 'string' then - local name = self:getSpecialName(source) - if name then - cache[#cache+1] = { name, source } - end - end - end) - for i = 1, #cache do - callback(cache[i][1], cache[i][2]) - end -end - ---- 遍历元素 ----@param source table ----@param key string ----@param callback fun(info:table) -function mt:eachField(source, key, callback) - local cache = self.cache.field[source] - if cache and cache[key] then - for i = 1, #cache[key] do - callback(cache[key][i]) - end - return - end - local tp = source.type - local d = methods[tp] - if not d then - return - end - local f = d.eachField - if not f then - return - end - if self.step >= 100 then - error('Stack overflow!') - return - end - self.step = self.step + 1 - local mark = {} - if not cache then - cache = {} - self.cache.field[source] = cache - end - cache[key] = {} - f(self, source, key, function (info) - local src = info.source - local uri = info.uri - assert(src and uri) - if mark[src] then - return - end - mark[src] = true - info.searcher = files.getSearcher(uri) - cache[key][#cache[key]+1] = info - end) - for i = 1, #cache[key] do - callback(cache[key][i]) - end - self.step = self.step - 1 -end - ---- 遍历引用 ----@param source table ----@param callback fun(info:table) -function mt:eachRef(source, callback) - local cache = self.cache.ref[source] - if cache then - for i = 1, #cache do - callback(cache[i]) - end - return - end - local tp = source.type - local d = methods[tp] - if not d then - return - end - local f = d.eachRef - if not f then - return - end - if self.step >= 100 then - error('Stack overflow!') - return - end - self.step = self.step + 1 - cache = {} - self.cache.ref[source] = cache - local mark = {} - f(self, source, function (info) - local src = info.source - local uri = info.uri - assert(src and uri) - if mark[src] then - return - end - mark[src] = true - info.searcher = files.getSearcher(uri) - cache[#cache+1] = info - end) - for i = 1, #cache do - callback(cache[i]) - end - self.step = self.step - 1 -end - ---- 遍历定义 ----@param source table ----@param callback fun(info:table) -function mt:eachDef(source, callback) - local cache = self.cache.def[source] - if cache then - for i = 1, #cache do - callback(cache[i]) - end - return - end - local tp = source.type - local d = methods[tp] - if not d then - return - end - local f = d.eachDef - if not f then - return - end - if self.step >= 100 then - error('Stack overflow!') - return - end - self.step = self.step + 1 - cache = {} - self.cache.def[source] = cache - local mark = {} - f(self, source, function (info) - local src = info.source - local uri = info.uri - assert(src and uri) - if mark[src] then - return - end - mark[src] = true - info.searcher = files.getSearcher(uri) - cache[#cache+1] = info - end) - for i = 1, #cache do - callback(cache[i]) - end - self.step = self.step - 1 -end - ---- 遍历value ----@param source table ----@param callback fun(info:table) -function mt:eachValue(source, callback) - local cache = self.cache.value[source] - if cache then - for i = 1, #cache do - callback(cache[i]) - end - return - end - local tp = source.type - local d = methods[tp] - if not d then - return - end - local f = d.eachValue - if not f then - return - end - if self.step >= 100 then - error('Stack overflow!') - return - end - self.step = self.step + 1 - cache = {} - self.cache.value[source] = cache - local mark = {} - f(self, source, function (info) - local src = info.source - local uri = info.uri - assert(src and uri) - if mark[src] then - return - end - mark[src] = true - info.searcher = files.getSearcher(uri) - cache[#cache+1] = info - end) - for i = 1, #cache do - callback(cache[i]) - end - self.step = self.step - 1 -end - ---- 获取value ----@param source table ----@return value table -function mt:getValue(source) - local tp = source.type - local d = methods[tp] - if not d then - return - end - local f = d.getValue - if not f then - return - end - if self.step >= 100 then - error('Stack overflow!') - return - end - self.step = self.step + 1 - local value = f(self, source) - self.step = self.step - 1 - return value -end - ---- 获取函数的参数 ----@param source table ----@return table arg1 ----@return table arg2 -function mt:callArgOf(source) - if not source or source.type ~= 'call' then - return - end - local args = source.args - if not args then - return - end - return tableUnpack(args) -end - ---- 获取调用函数的返回值 ----@param source table ----@return table return1 ----@return table return2 -function mt:callReturnOf(source) - if not source or source.type ~= 'call' then - return - end - local parent = source.parent - local extParent = source.extParent - if extParent then - local returns = {parent.parent} - for i = 1, #extParent do - returns[i+1] = extParent[i].parent - end - return tableUnpack(returns) - elseif parent then - return parent.parent - end -end - ---- 获取函数定义的返回值 ----@param source table ----@param callback fun(source:table) -function mt:functionReturnOf(source, callback) - if not source or source.type ~= 'function' then - return - end - local returns = guide.getReturns(source) - for i = 1, #returns do - local src = returns[i] - callback() - end -end - ---- 获取source的索引,模式与值 ----@param source table ----@return table field ----@return string mode ----@return table value -function mt:childMode(source) - if source.type == 'getfield' then - return source.field, 'get' - elseif source.type == 'setfield' then - return source.field, 'set', source.value - elseif source.type == 'getmethod' then - return source.method, 'get' - elseif source.type == 'setmethod' then - return source.method, 'set', source.value - elseif source.type == 'getindex' then - return source.index, 'get' - elseif source.type == 'setindex' then - return source.index, 'set', source.value - elseif source.type == 'field' then - return self:childMode(source.parent) - elseif source.type == 'method' then - return self:childMode(source.parent) - end - return nil, nil -end - ----@class engineer_old -local m = {} - ---- 新建搜索器 ----@param uri string ----@return searcher_old -function m.create(uri) - local ast = files.getAst(uri) - local searcher = setmetatable({ - step = 0, - ast = ast.ast, - uri = uri, - cache = { - def = {}, - ref = {}, - field = {}, - value = {}, - specialName = {}, - }, - }, mt) - return searcher -end - -return m diff --git a/server-beta/src/searcher-old/label.lua b/server-beta/src/searcher-old/label.lua deleted file mode 100644 index f05a57e6..00000000 --- a/server-beta/src/searcher-old/label.lua +++ /dev/null @@ -1,3 +0,0 @@ -local m = {} - -return m diff --git a/server-beta/src/searcher-old/local.lua b/server-beta/src/searcher-old/local.lua deleted file mode 100644 index 0213ee58..00000000 --- a/server-beta/src/searcher-old/local.lua +++ /dev/null @@ -1,179 +0,0 @@ -local guide = require 'parser.guide' -local checkSMT = require 'searcher.setmetatable' - -local m = {} - -function m:eachDef(source, callback) - if source.tag ~= 'self' then - callback { - source = source, - uri = self.uri, - mode = 'local', - } - end - if source.ref then - for _, ref in ipairs(source.ref) do - if ref.type == 'setlocal' then - callback { - source = ref, - uri = self.uri, - mode = 'set', - } - end - end - end - if source.tag == 'self' then - local method = source.method - local node = method.node - self:eachDef(node, callback) - end - if source.value then - self:eachDef(source.value, callback) - end -end - -function m:eachRef(source, callback) - if source.tag ~= 'self' then - callback { - source = source, - uri = self.uri, - mode = 'local', - } - end - if source.ref then - for _, ref in ipairs(source.ref) do - if ref.type == 'setlocal' then - callback { - source = ref, - uri = self.uri, - mode = 'set', - } - elseif ref.type == 'getlocal' then - callback { - source = ref, - uri = self.uri, - mode = 'get', - } - end - end - end - if source.tag == 'self' then - local method = source.method - local node = method.node - self:eachRef(node, callback) - end -end - -function m:eachField(source, key, callback) - local used = {} - used[source] = true - local found = false - local refs = source.ref - if refs then - for i = 1, #refs do - local ref = refs[i] - if ref.type == 'getlocal' then - used[ref] = true - local parent = ref.parent - if key == guide.getKeyName(parent) then - if parent.type:sub(1, 3) == 'set' then - callback { - source = parent, - uri = self.uri, - mode = 'set', - } - found = true - else - callback { - source = parent, - uri = self.uri, - mode = 'get', - } - end - end - elseif ref.type == 'getglobal' then - used[ref] = true - if key == guide.getKeyName(ref) then - -- _ENV.XXX - callback { - source = ref, - uri = self.uri, - mode = 'get', - } - end - elseif ref.type == 'setglobal' then - used[ref] = true - -- _ENV.XXX = XXX - if key == guide.getKeyName(ref) then - callback { - source = ref, - uri = self.uri, - mode = 'set', - } - found = true - end - end - end - end - if source.tag == 'self' then - local method = source.method - local node = method.node - self:eachField(node, key, function (info) - callback(info) - if info.mode == 'set' then - found = true - end - end) - end - self:eachValue(source, function (info) - local src = info.source - if source ~= src then - info.searcher:eachField(src, key, function (info) - callback(info) - if info.mode == 'set' then - found = true - end - end) - end - end) - checkSMT(self, key, used, found, callback) -end - -function m:eachValue(source, callback) - callback { - source = source, - uri = self.uri, - } - local refs = source.ref - if refs then - for i = 1, #refs do - local ref = refs[i] - if ref.type == 'setlocal' then - self:eachValue(ref.value, callback) - elseif ref.type == 'getlocal' then - local parent = ref.parent - if parent.type == 'setmethod' then - local func = parent.value - if func and func.locals then - callback { - source = func.locals[1], - uri = self.uri, - } - end - end - end - end - end - if source.value then - self:eachValue(source.value, callback) - end -end - -function m:getValue(source) - if source.type == 'local' - or source.type == 'setlocal' then - return source.value or source - end -end - -return m diff --git a/server-beta/src/searcher-old/method.lua b/server-beta/src/searcher-old/method.lua deleted file mode 100644 index c05fba76..00000000 --- a/server-beta/src/searcher-old/method.lua +++ /dev/null @@ -1,37 +0,0 @@ -local guide = require 'parser.guide' - -local m = {} - -function m:eachDef(source, callback) - local node = source.parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, function (info) - if info.mode == 'set' then - callback(info) - end - end) -end - -function m:eachRef(source, callback) - local node = source.parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, function (info) - if info.mode == 'set' or info.mode == 'get' then - callback(info) - end - end) -end - -function m:eachField(source, key, callback) - self:eachField(source.parent, key, callback) -end - -function m:eachValue(source, callback) - self:eachValue(source.parent, callback) -end - -function m:getValue(source) - return self:getValue(source.parent) -end - -return m diff --git a/server-beta/src/searcher-old/methods.lua b/server-beta/src/searcher-old/methods.lua deleted file mode 100644 index 498978dd..00000000 --- a/server-beta/src/searcher-old/methods.lua +++ /dev/null @@ -1,26 +0,0 @@ -local methods = {} - -methods['local'] = require 'searcher.local' -methods['getlocal'] = require 'searcher.getlocal' -methods['setlocal'] = methods['getlocal'] -methods['getglobal'] = require 'searcher.getglobal' -methods['setglobal'] = methods['getglobal'] -methods['getfield'] = require 'searcher.getfield' -methods['setfield'] = methods['getfield'] -methods['tablefield'] = require 'searcher.tablefield' -methods['getmethod'] = methods['getfield'] -methods['setmethod'] = methods['getfield'] -methods['getindex'] = methods['getfield'] -methods['setindex'] = methods['getfield'] -methods['field'] = require 'searcher.field' -methods['method'] = require 'searcher.method' -methods['index'] = require 'searcher.index' -methods['number'] = require 'searcher.number' -methods['boolean'] = require 'searcher.boolean' -methods['string'] = require 'searcher.string' -methods['table'] = require 'searcher.table' -methods['select'] = require 'searcher.select' -methods['goto'] = require 'searcher.goto' -methods['label'] = require 'searcher.label' - -return methods diff --git a/server-beta/src/searcher-old/number.lua b/server-beta/src/searcher-old/number.lua deleted file mode 100644 index f92670e1..00000000 --- a/server-beta/src/searcher-old/number.lua +++ /dev/null @@ -1,43 +0,0 @@ -local guide = require 'parser.guide' - -local m = {} - -function m:eachDef(source, callback) - local parent = source.parent - if not parent then - return - end - if parent.type ~= 'setindex' and parent.type ~= 'getindex' then - return - end - local node = parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, function (info) - if info.mode == 'set' then - callback(info) - end - end) -end - -function m:eachRef(source, callback) - local parent = source.parent - if not parent then - return - end - if parent.type ~= 'setindex' and parent.type ~= 'getindex' then - return - end - local node = parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, function (info) - if info.mode == 'set' or info.mode == 'get' then - callback(info) - end - end) -end - -function m:getValue(source) - return source -end - -return m diff --git a/server-beta/src/searcher-old/select.lua b/server-beta/src/searcher-old/select.lua deleted file mode 100644 index f7da7bfc..00000000 --- a/server-beta/src/searcher-old/select.lua +++ /dev/null @@ -1,34 +0,0 @@ -local guide = require 'parser.guide' - -local m = {} - -function m:eachDef(source, callback) - local vararg = source.vararg - if vararg.type == 'call' then - local func = vararg.node - self:eachValue(func, function (info) - self:functionReturnOf(info.source, function () - - end) - end) - end -end - -function m:eachValue(source, callback) - local vararg = source.vararg - if vararg.type == 'call' then - local func = vararg.node - if self:getSpecialName(func) == 'setmetatable' - and source.index == 1 then - local t, mt = self:callArgOf(vararg) - self:eachValue(t, callback) - self:eachField(mt, 's|__index', function (info) - if info.mode == 'set' then - info.searcher:eachValue(info.source, callback) - end - end) - end - end -end - -return m diff --git a/server-beta/src/searcher-old/setmetatable.lua b/server-beta/src/searcher-old/setmetatable.lua deleted file mode 100644 index 7489bf6f..00000000 --- a/server-beta/src/searcher-old/setmetatable.lua +++ /dev/null @@ -1,63 +0,0 @@ -local guide = require 'parser.guide' - -local function checkIndex(info, key, t, used, call, callback) - if info.mode ~= 'set' then - return - end - local src = info.source - -- t.field -> mt.__index.field - if used[t] then - info.searcher:eachValue(src, function (info) - info.searcher:eachField(info.source, key, callback) - end) - end - -- mt.__index.field -> t.field - info.searcher:eachValue(src, function (info) - local value = info.source - if used[value] then - info.searcher:eachValue(t, function (info) - info.searcher:eachField(info.source, key, callback) - end) - local obj = info.searcher:callReturnOf(call) - if obj then - info.searcher:eachValue(obj, function (info) - info.searcher:eachField(info.source, key, callback) - end) - end - end - end) -end - -return function (self, key, used, found, callback) - self:eachSpecial(function (name, src) - local call = src.parent - if name == 'rawset' then - local t, k = self:callArgOf(call) - if used[t] and guide.getKeyName(k) == key then - callback { - source = call, - uri = self.uri, - mode = 'set', - } - end - elseif name == 'rawget' then - local t, k, v = self:callArgOf(call) - if used[t] and guide.getKeyName(k) == key then - callback { - source = call, - uri = self.uri, - mode = 'get', - } - self:eachField(v, key, callback) - end - elseif name == 'setmetatable' and not found then - -- 如果已经找到值,则不检查meta表 - local t, mt = self:callArgOf(call) - if mt then - self:eachField(mt, 's|__index', function (info) - checkIndex(info, key, t, used, call, callback) - end) - end - end - end) -end diff --git a/server-beta/src/searcher-old/string.lua b/server-beta/src/searcher-old/string.lua deleted file mode 100644 index 94907116..00000000 --- a/server-beta/src/searcher-old/string.lua +++ /dev/null @@ -1,43 +0,0 @@ -local guide = require 'parser.guide' - -local m = {} - -function m:eachDef(source, callback) - local parent = source.parent - if not parent then - return - end - if parent.type ~= 'setindex' and parent.type ~= 'getindex' then - return - end - local node = parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, function (info) - if info.mode == 'set' then - callback(info) - end - end) -end - -function m:eachRef(source, callback) - local parent = source.parent - if not parent then - return - end - if parent.type ~= 'setindex' and parent.type ~= 'getindex' then - return - end - local node = parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, function (info) - if info.mode == 'set' or info.mode == 'get' then - callback(info) - end - end) -end - -function m:getValue(source, callback) - return source -end - -return m diff --git a/server-beta/src/searcher-old/table.lua b/server-beta/src/searcher-old/table.lua deleted file mode 100644 index fa9a064a..00000000 --- a/server-beta/src/searcher-old/table.lua +++ /dev/null @@ -1,30 +0,0 @@ -local guide = require 'parser.guide' - -local m = {} - -function m:eachField(source, key, callback) - for i = 1, #source do - local src = source[i] - if key == guide.getKeyName(src) then - if src.type == 'tablefield' then - callback { - source = src, - uri = self.uri, - mode = 'set', - } - elseif src.type == 'tableindex' then - callback { - source = src, - uri = self.uri, - mode = 'set', - } - end - end - end -end - -function m:getValue(source) - return source -end - -return m diff --git a/server-beta/src/searcher-old/tablefield.lua b/server-beta/src/searcher-old/tablefield.lua deleted file mode 100644 index 09456029..00000000 --- a/server-beta/src/searcher-old/tablefield.lua +++ /dev/null @@ -1,19 +0,0 @@ -local m = {} - -function m:eachField(source, key, callback) - if source.value then - self:eachField(source.value, key, callback) - end -end - -function m:eachValue(source, callback) - if source.value then - self:eachValue(source.value, callback) - end -end - -function m:getValue(source) - return source.value and self:getValue(source.value) or source -end - -return m diff --git a/server-beta/src/service/diagnostic.lua b/server-beta/src/service/diagnostic.lua index f6b0c1a0..b7d6be02 100644 --- a/server-beta/src/service/diagnostic.lua +++ b/server-beta/src/service/diagnostic.lua @@ -9,6 +9,7 @@ local core = require 'core.diagnostics' local m = {} m.version = 0 +m._start = false local function concat(t, sep) if type(t) ~= 'table' then @@ -35,8 +36,14 @@ local function buildSyntaxError(uri, err) if related then relatedInformation = {} for _, rel in ipairs(related) do + local rmessage + if rel.message then + rmessage = lang.script('PARSER_'..rel.message) + else + rmessage = text:sub(rel.start, rel.finish) + end relatedInformation[#relatedInformation+1] = { - message = lang.script('PARSER_'..rel.message), + message = rmessage, location = define.location(uri, define.range(lines, text, rel.start, rel.finish)), } end @@ -67,7 +74,7 @@ local function buildDiagnostic(uri, diag) } end end - + return { range = define.range(lines, text, diag.start, diag.finish), source = lang.script.DIAG_DIAGNOSTICS, @@ -91,12 +98,13 @@ function m.doDiagnostic(uri) diagnostics[#diagnostics+1] = buildSyntaxError(uri, err) end - local diags = core(uri) - for _, diag in ipairs(diags) do - diagnostics[#diagnostics+1] = buildDiagnostic(uri, diag) + if m._start then + local diags = core(uri) + for _, diag in ipairs(diags) do + diagnostics[#diagnostics+1] = buildDiagnostic(uri, diag) + end end - proto.notify('textDocument/publishDiagnostics', { uri = uri, diagnostics = diagnostics, @@ -107,10 +115,13 @@ end function m.refresh(uri) m.version = m.version + 1 local myVersion = m.version + if uri then + m.doDiagnostic(files.getOriginUri(uri)) + end + if not m._start then + return + end await.create(function () - if uri then - m.doDiagnostic(files.getOriginUri(uri)) - end await.sleep(1.0) if myVersion ~= m.version then return @@ -127,4 +138,9 @@ function m.refresh(uri) end) end +function m.start() + m._start = true + m.refresh() +end + return m diff --git a/server-beta/src/workspace/workspace.lua b/server-beta/src/workspace/workspace.lua index f65fb178..c8deb001 100644 --- a/server-beta/src/workspace/workspace.lua +++ b/server-beta/src/workspace/workspace.lua @@ -1,11 +1,12 @@ -local pub = require 'pub' -local fs = require 'bee.filesystem' -local furi = require 'file-uri' -local files = require 'files' -local config = require 'config' -local glob = require 'glob' -local platform = require 'bee.platform' -local await = require 'await' +local pub = require 'pub' +local fs = require 'bee.filesystem' +local furi = require 'file-uri' +local files = require 'files' +local config = require 'config' +local glob = require 'glob' +local platform = require 'bee.platform' +local await = require 'await' +local diagnostic = require 'service.diagnostic' local m = {} m.type = 'workspace' @@ -115,7 +116,7 @@ function m.preload() max = max + 1 pub.syncTask('loadFile', uri, function (text) read = read + 1 - log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #text / 1000.0)) + --log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #text / 1000.0)) files.setText(uri, text) end) end) @@ -130,6 +131,7 @@ function m.preload() end log.info('Preload finish.') + diagnostic.start() end --- 查找符合指定file path的所有uri |