summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-13 17:18:32 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-13 17:18:32 +0800
commit628a272b7babbeab995cf582ff4337b897ac09e6 (patch)
treede859adf802e7ea941cf990007e40d98a1fee77b /server
parent42ec4d53d770a053c0909f14b5aa7c8cd42bbcdb (diff)
downloadlua-language-server-628a272b7babbeab995cf582ff4337b897ac09e6.zip
解除value->info->source的循环引用
Diffstat (limited to 'server')
-rw-r--r--server/src/core/definition.lua30
-rw-r--r--server/src/core/document_symbol.lua11
-rw-r--r--server/src/core/hover/name.lua6
-rw-r--r--server/src/core/implementation.lua36
-rw-r--r--server/src/core/references.lua12
-rw-r--r--server/src/core/rename.lua8
-rw-r--r--server/src/vm/source.lua17
-rw-r--r--server/src/vm/value.lua51
-rw-r--r--server/src/vm/vm.lua4
9 files changed, 96 insertions, 79 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 1ae6b97e..b7aadb44 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -30,11 +30,11 @@ end
local function parseValueCrossFile(vm, source, lsp)
local value = source:bindValue()
local positions = {}
- value:eachInfo(function (info)
- if info.type == 'local' and info.source.uri == value.uri then
+ value:eachInfo(function (info, src)
+ if info.type == 'local' and src.uri == value.uri then
positions[#positions+1] = {
- info.source.start,
- info.source.finish,
+ src.start,
+ src.finish,
value.uri,
}
return true
@@ -44,11 +44,11 @@ local function parseValueCrossFile(vm, source, lsp)
return positions
end
- value:eachInfo(function (info)
- if info.type == 'set' and info.source.uri == value.uri then
+ value:eachInfo(function (info, src)
+ if info.type == 'set' and src.uri == value.uri then
positions[#positions+1] = {
- info.source.start,
- info.source.finish,
+ src.start,
+ src.finish,
value.uri,
}
end
@@ -57,11 +57,11 @@ local function parseValueCrossFile(vm, source, lsp)
return positions
end
- value:eachInfo(function (info)
- if info.type == 'return' and info.source.uri == value.uri then
+ value:eachInfo(function (info, src)
+ if info.type == 'return' and src.uri == value.uri then
positions[#positions+1] = {
- info.source.start,
- info.source.finish,
+ src.start,
+ src.finish,
value.uri,
}
end
@@ -115,11 +115,11 @@ local function parseValue(vm, source, lsp)
return parseValueCrossFile(vm, source, lsp)
end
local positions = {}
- value:eachInfo(function (info)
+ value:eachInfo(function (info, src)
if info.type == 'set' then
positions[#positions+1] = {
- info.source.start,
- info.source.finish,
+ src.start,
+ src.finish,
}
end
end)
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua
index 2b1ecfbf..8225fdb9 100644
--- a/server/src/core/document_symbol.lua
+++ b/server/src/core/document_symbol.lua
@@ -35,18 +35,15 @@ local function isFirstSet(source, value)
if source:action() ~= 'set' then
return false
end
- local firstSet = value:eachInfo(function (info)
+ local firstSrc = value:eachInfo(function (info, src)
if info.type == 'set' then
- return info
+ return src
end
end)
- if not firstSet then
+ if not firstSrc then
return false
end
- if firstSet.type ~= 'set' then
- return false
- end
- if firstSet.source ~= source then
+ if firstSrc ~= source then
return false
end
return true
diff --git a/server/src/core/hover/name.lua b/server/src/core/hover/name.lua
index bd35f946..b363f653 100644
--- a/server/src/core/hover/name.lua
+++ b/server/src/core/hover/name.lua
@@ -12,10 +12,10 @@ return function (source)
end
if not declarat then
-- 如果声明者没有给名字,则找一个合适的名字
- local name = value:eachInfo(function (info)
+ local name = value:eachInfo(function (info, src)
if info.type == 'local' or info.type == 'set' or info.type == 'return' then
- if info.source.type == 'name' and info.source.uri == value.uri then
- return info.source[1]
+ if src.type == 'name' and src.uri == value.uri then
+ return src[1]
end
end
end)
diff --git a/server/src/core/implementation.lua b/server/src/core/implementation.lua
index b7ca2c6e..5385d9f9 100644
--- a/server/src/core/implementation.lua
+++ b/server/src/core/implementation.lua
@@ -30,11 +30,11 @@ end
local function parseValueCrossFile(vm, source, lsp)
local value = source:bindValue()
local positions = {}
- value:eachInfo(function (info)
- if info.type == 'local' and info.source.uri == value.uri then
+ value:eachInfo(function (info, src)
+ if info.type == 'local' and src.uri == value.uri then
positions[#positions+1] = {
- info.source.start,
- info.source.finish,
+ src.start,
+ src.finish,
value.uri,
}
return true
@@ -44,11 +44,11 @@ local function parseValueCrossFile(vm, source, lsp)
return positions
end
- value:eachInfo(function (info)
- if info.type == 'set' and info.source.uri == value.uri then
+ value:eachInfo(function (info, src)
+ if info.type == 'set' and src.uri == value.uri then
positions[#positions+1] = {
- info.source.start,
- info.source.finish,
+ src.start,
+ src.finish,
value.uri,
}
end
@@ -57,11 +57,11 @@ local function parseValueCrossFile(vm, source, lsp)
return positions
end
- value:eachInfo(function (info)
- if info.type == 'return' and info.source.uri == value.uri then
+ value:eachInfo(function (info, src)
+ if info.type == 'return' and src.uri == value.uri then
positions[#positions+1] = {
- info.source.start,
- info.source.finish,
+ src.start,
+ src.finish,
value.uri,
}
end
@@ -98,11 +98,11 @@ local function parseValue(vm, source, lsp)
return parseValueCrossFile(vm, source, lsp)
end
local positions = {}
- value:eachInfo(function (info)
+ value:eachInfo(function (info, src)
if info.type == 'set' then
positions[#positions+1] = {
- info.source.start,
- info.source.finish,
+ src.start,
+ src.finish,
}
end
end)
@@ -114,11 +114,11 @@ end
local function parseLabel(vm, label, lsp)
local positions = {}
- label:eachInfo(function (info)
+ label:eachInfo(function (info, src)
if info.type == 'set' then
positions[#positions+1] = {
- info.source.start,
- info.source.finish,
+ src.start,
+ src.finish,
}
end
end)
diff --git a/server/src/core/references.lua b/server/src/core/references.lua
index 2cc14abb..0f9c73ab 100644
--- a/server/src/core/references.lua
+++ b/server/src/core/references.lua
@@ -16,24 +16,24 @@ local function parseResult(vm, source, declarat, callback)
callback(info.source)
end
end)
- loc:getValue():eachInfo(function (info)
+ loc:getValue():eachInfo(function (info, src)
if declarat or info.type == 'get' then
- callback(info.source)
+ callback(src)
end
end)
return
end
if source:bindValue() then
- source:bindValue():eachInfo(function (info)
+ source:bindValue():eachInfo(function (info, src)
if declarat or info.type == 'get' then
- callback(info.source)
+ callback(src)
end
end)
local parent = source:get 'parent'
- parent:eachInfo(function (info)
+ parent:eachInfo(function (info, src)
if info[1] == source[1] then
if (declarat and info.type == 'set child') or info.type == 'get child' then
- callback(info.source)
+ callback(src)
end
end
end)
diff --git a/server/src/core/rename.lua b/server/src/core/rename.lua
index 349ec96b..4e8e574b 100644
--- a/server/src/core/rename.lua
+++ b/server/src/core/rename.lua
@@ -47,12 +47,12 @@ local function parseResult(source, newName)
end
local parent = source:get 'parent'
local mark = {}
- parent:eachInfo(function (info)
- if not mark[info.source] then
- mark[info.source] = info
+ parent:eachInfo(function (info, src)
+ if not mark[src] then
+ mark[src] = info
if info.type == 'get child' or info.type == 'set child' then
if info[1] == source[1] then
- positions[#positions+1] = {info.source.start, info.source.finish}
+ positions[#positions+1] = {src.start, src.finish}
end
end
end
diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua
index d53019c7..8f65da8b 100644
--- a/server/src/vm/source.lua
+++ b/server/src/vm/source.lua
@@ -1,6 +1,8 @@
local mt = {}
mt.__index = mt
-mt._hasInstant = true
+
+local Id = 0
+local List = {}
function mt:bindLocal(loc, action)
if loc then
@@ -87,16 +89,25 @@ function mt:kill()
self._bindCall = nil
self._bindFunction = nil
self._bindCallArgs = nil
+ List[self.id] = nil
end
function mt:isDead()
return self._dead
end
-return function (vm, source)
- if source._hasInstant then
+local function instant(vm, source)
+ if source.id then
return false
end
+ Id = Id + 1
+ source.id = Id
+ List[Id] = source
setmetatable(source, mt)
return true
end
+
+return {
+ instant = instant,
+ list = List,
+}
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index 2463e646..f8d3c4b2 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -1,5 +1,6 @@
local libraryBuilder = require 'vm.library'
local library = require 'core.library'
+local sourceMgr = require 'vm.source'
local function getDefaultSource()
return {
@@ -229,13 +230,14 @@ function mt:mergeValue(value)
end
end
- for source, info in pairs(value._info) do
- if source:isDead() then
- value._info[source] = nil
- value._infoCount = value._infoCount - 1
- else
+ for srcId, info in pairs(value._info) do
+ local src = sourceMgr.list[srcId]
+ if src then
self._infoCount = self._infoCount + 1
- self._info[source] = info
+ self._info[srcId] = info
+ else
+ value._info[srcId] = nil
+ value._infoCount = value._infoCount - 1
end
end
if value._meta then
@@ -253,29 +255,34 @@ function mt:mergeValue(value)
end
function mt:addInfo(tp, source, ...)
- if source and not source.start then
+ if not source then
+ return
+ end
+ if not source.start then
error('Miss start: ' .. table.dump(source))
end
- if self._info[source] then
- return
+ local id = source.id
+ if not id then
+ error('Not instanted source')
end
- if not source or not source._hasInstant then
+ if self._info[id] then
return
end
Sort = Sort + 1
local info = {
type = tp,
- source = source,
+ source = id,
_sort = Sort,
...
}
- self._info[source] = info
+ self._info[id] = info
self._infoCount = self._infoCount + 1
if self._infoCount > self._infoLimit then
- for src in pairs(self._info) do
- if src:isDead() then
- self._info[src] = nil
+ for srcId in pairs(self._info) do
+ local src = sourceMgr.list[srcId]
+ if not src then
+ self._info[srcId] = nil
self._infoCount = self._infoCount - 1
end
end
@@ -288,19 +295,21 @@ end
function mt:eachInfo(callback)
local list = {}
- for source, info in pairs(self._info) do
- if source:isDead() then
- self._info[source] = nil
- self._infoCount = self._infoCount - 1
- else
+ for srcId, info in pairs(self._info) do
+ local src = sourceMgr.list[srcId]
+ if src then
list[#list+1] = info
+ else
+ self._info[srcId] = nil
+ self._infoCount = self._infoCount - 1
end
end
table.sort(list, function (a, b)
return a._sort < b._sort
end)
for i = 1, #list do
- local res = callback(list[i])
+ local info = list[i]
+ local res = callback(info, sourceMgr.list[info.source])
if res ~= nil then
return res
end
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index d9d29886..d89a9a56 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -3,7 +3,7 @@ local createValue = require 'vm.value'
local createLocal = require 'vm.local'
local createLabel = require 'vm.label'
local createFunction = require 'vm.function'
-local instantSource = require 'vm.source'
+local sourceMgr = require 'vm.source'
local buildGlobal = require 'vm.global'
local createMulti = require 'vm.multi'
local libraryBuilder = require 'vm.library'
@@ -1074,7 +1074,7 @@ function mt:getUri()
end
function mt:instantSource(source)
- if instantSource(self, source) then
+ if sourceMgr.instant(self, source) then
source:setUri(self:getUri())
self.sources[#self.sources+1] = source
CachedSource[source] = true