diff options
-rw-r--r-- | server/main.lua | 2 | ||||
-rw-r--r-- | server/src/service.lua | 18 | ||||
-rw-r--r-- | server/src/vm/value.lua | 25 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 4 | ||||
-rw-r--r-- | server/test/crossfile/completion.lua | 35 |
5 files changed, 60 insertions, 24 deletions
diff --git a/server/main.lua b/server/main.lua index 35b75789..4f3dcf71 100644 --- a/server/main.lua +++ b/server/main.lua @@ -6,7 +6,7 @@ LANG = LANG or 'en-US' package.path = (ROOT / 'src' / '?.lua'):string() .. ';' .. (ROOT / 'src' / '?' / 'init.lua'):string() -collectgarbage('generational') +--collectgarbage('generational') log = require 'log' log.init(ROOT, ROOT / 'log' / 'service.log') diff --git a/server/src/service.lua b/server/src/service.lua index 5deae2bb..0edfe935 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -565,15 +565,15 @@ function mt:onTick() )) --TODO source测试 - local total = 0 - local alive = 0 - for source in pairs(CachedSource) do - if not source:isDead() then - alive = alive + 1 - end - total = total + 1 - end - log.debug(('CachedSource: %d/%d'):format(alive, total)) + --local total = 0 + --local alive = 0 + --for source in pairs(CachedSource) do + -- if not source:isDead() then + -- alive = alive + 1 + -- end + -- total = total + 1 + --end + --log.debug(('CachedSource: %d/%d'):format(alive, total)) end end diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index 84012b25..a2e6ba05 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -140,7 +140,17 @@ function mt:eachLibChild(callback) end end -function mt:getChild(index, source, mark) +function mt:getChild(index, source) + local value = self:_getChild(index) + if not value then + value = create('any', source) + self:setChild(index, value) + value.uri = self.uri + end + return value +end + +function mt:_getChild(index, source, mark) self:setType('table', 0.5) local value = self:rawGet(index) if value then @@ -149,25 +159,16 @@ function mt:getChild(index, source, mark) local method = self:getMetaMethod('__index') if not method then local v = self:getLibChild(index) - if v then - return v - end - v = create('any', source) - self:setChild(index, v) - v.uri = self.uri return v end if not mark then mark = {} end if mark[method] then - local v = create('any', source) - self:setChild(index, v) - v.uri = self.uri - return v + return nil end mark[method] = true - return method:getChild(index, source, mark) + return method:_getChild(index, source, mark) end function mt:bindChild(other) diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 555154b3..4435d7d5 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -9,7 +9,7 @@ local createMulti = require 'vm.multi' local libraryBuilder = require 'vm.library' -- TODO source测试 -rawset(_G, 'CachedSource', setmetatable({}, { __mode = 'kv' })) +--rawset(_G, 'CachedSource', setmetatable({}, { __mode = 'kv' })) local mt = {} mt.__index = mt @@ -1084,7 +1084,7 @@ function mt:instantSource(source) if sourceMgr.instant(source) then source:setUri(self:getUri()) self.sources[#self.sources+1] = source - CachedSource[source] = true + --CachedSource[source] = true end return source end diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua index 032991ef..b93e6ba8 100644 --- a/server/test/crossfile/completion.lua +++ b/server/test/crossfile/completion.lua @@ -374,3 +374,38 @@ TEST { }, } } + +TEST { + { + path = 'init.lua', + content = [[ + setmetatable(_G, {__index = {}}) + ]] + }, + { + path = 'a.lua', + content = [[ + print(abc) + ]] + }, + { + path = 'a.lua', + content = [[ + abcdef = 1 + ]] + }, + { + path = 'b.lua', + content = [[ + ab@ + ]], + main = true, + }, + completion = { + { + label = 'abcdef', + kind = CompletionItemKind.Enum, + detail = '= 1', + }, + } +} |