summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-19 01:43:31 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-11-19 01:43:31 +0800
commit15a474bfd6785d9857a68df60963f6c327f1f478 (patch)
treefcd795dcc24b44fb3965b2f8f4827b1439ab188e
parentb137f3faf9225e4e4279e0aefc1d98bfb6aa4724 (diff)
downloadlua-language-server-15a474bfd6785d9857a68df60963f6c327f1f478.zip
cleanup
-rw-r--r--script/vm/compiler.lua8
-rw-r--r--script/vm/node.lua1
-rw-r--r--script/vm/runner.lua8
-rw-r--r--test/tclient/tests/recursive-runner.lua42
4 files changed, 38 insertions, 21 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 70a46677..aa5ffb6e 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -567,7 +567,6 @@ local function matchCall(source)
local newNode = myNode:copy()
newNode:removeNode(needRemove)
newNode:setData('originNode', myNode)
- newNode:setData('hasResolved', true)
vm.setNode(source, newNode, true)
end
end
@@ -642,7 +641,7 @@ local function bindAs(source)
local doc = ases[index]
if doc and doc.touch == source.finish then
local asNode = vm.compileNode(doc.as)
- asNode:setData 'hasResolved'
+ asNode.resolved = true
vm.setNode(source, asNode, true)
return true
end
@@ -1207,7 +1206,7 @@ local compilerSwitch = util.switch()
end
compileLocal(source)
- myNode:setData('hasResolved', true)
+ myNode.resolved = true
end, function ()
local myNode = vm.getNode(source)
---@cast myNode -?
@@ -1251,7 +1250,7 @@ local compilerSwitch = util.switch()
return
end
vm.setNode(src, node, true)
- node:setData('hasResolved', true)
+ node.resolved = true
matchCall(src)
end
end)
@@ -1978,5 +1977,6 @@ function vm.compileNode(source)
local node = vm.getNode(source)
---@cast node -?
+ node.resolved = true
return node
end
diff --git a/script/vm/node.lua b/script/vm/node.lua
index c07269ab..58784d24 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -19,6 +19,7 @@ mt.id = 0
mt.type = 'vm.node'
mt.optional = nil
mt.data = nil
+mt.resolved = nil
---@param node vm.node | vm.node.object
---@return vm.node
diff --git a/script/vm/runner.lua b/script/vm/runner.lua
index 13370ac7..8e264521 100644
--- a/script/vm/runner.lua
+++ b/script/vm/runner.lua
@@ -371,7 +371,7 @@ local function waitResolve(info)
break
end
local node = vm.getNode(info.target)
- if node and node:getData('hasResolved') then
+ if node and node.resolved then
break
end
coroutine.yield()
@@ -403,7 +403,7 @@ local function resolveDeadLock()
local firstTarget = infos[1].target
---@cast firstTarget -?
local firstNode = vm.setNode(firstTarget, vm.getNode(firstTarget):copy(), true)
- firstNode:setData('hasResolved', true)
+ firstNode.resolved = true
firstNode:setData('resolvedByDeadLock', true)
end
@@ -521,7 +521,7 @@ end
---@param source parser.object
function vm.waitResolveRunner(source)
local myNode = vm.getNode(source)
- if myNode and myNode:getData('hasResolved') then
+ if myNode and myNode.resolved then
return
end
@@ -555,7 +555,7 @@ end
---@param source parser.object
function vm.storeWaitingRunner(source)
local sourceNode = vm.getNode(source)
- if sourceNode and sourceNode:getData 'hasResolved' then
+ if sourceNode and sourceNode.resolved then
return
end
diff --git a/test/tclient/tests/recursive-runner.lua b/test/tclient/tests/recursive-runner.lua
index 5ecae705..e824f23a 100644
--- a/test/tclient/tests/recursive-runner.lua
+++ b/test/tclient/tests/recursive-runner.lua
@@ -2,6 +2,9 @@ local lclient = require 'lclient'
local ws = require 'workspace'
local await = require 'await'
local config = require 'config'
+local vm = require 'vm'
+local guide = require 'parser.guide'
+local files = require 'files'
---@async
lclient():start(function (client)
@@ -14,7 +17,7 @@ lclient():start(function (client)
client:notify('textDocument/didOpen', {
textDocument = {
- uri = 'file://test.lua',
+ uri = 'file:///test.lua',
languageId = 'lua',
version = 0,
text = [[
@@ -34,12 +37,12 @@ y = x
await.sleep(0.1)
local hover1 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 1, character = 7 },
})
local hover2 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 8, character = 1 },
})
@@ -48,7 +51,7 @@ y = x
client:notify('textDocument/didOpen', {
textDocument = {
- uri = 'file://test.lua',
+ uri = 'file:///test.lua',
languageId = 'lua',
version = 1,
text = [[
@@ -76,37 +79,37 @@ y = x
await.sleep(0.1)
local hover1 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 9, character = 0 },
})
local hover2 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 10, character = 0 },
})
local hover3 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 11, character = 0 },
})
local hover4 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 12, character = 0 },
})
local hover5 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 13, character = 0 },
})
local hover6 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 14, character = 0 },
})
local hover7 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 15, character = 0 },
})
@@ -120,7 +123,7 @@ y = x
client:notify('textDocument/didOpen', {
textDocument = {
- uri = 'file://test.lua',
+ uri = 'file:///test.lua',
languageId = 'lua',
version = 2,
text = [[
@@ -155,7 +158,20 @@ end
})
local hover1 = client:awaitRequest('textDocument/hover', {
- textDocument = { uri = 'file://test.lua' },
+ textDocument = { uri = 'file:///test.lua' },
+ position = { line = 20, character = 11 },
+ })
+ assert(hover1.contents.value:find 'vector3')
+
+ vm.clearNodeCache()
+ local state = files.getState('file:///test.lua')
+ assert(state)
+ guide.eachSourceType(state.ast, 'call', function (src)
+ vm.compileNode(src)
+ end)
+
+ local hover1 = client:awaitRequest('textDocument/hover', {
+ textDocument = { uri = 'file:///test.lua' },
position = { line = 20, character = 11 },
})
assert(hover1.contents.value:find 'vector3')