summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-01-09 20:14:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-01-09 20:14:02 +0800
commit6f889136264e39a9c47e8cce569274414c9b4a50 (patch)
treeccfa83257aeec26c03ad42c10e0ddac459d48acf /script
parent1ca3b7d67c0c30af1f67fae71b5c770b9008e4d5 (diff)
downloadlua-language-server-6f889136264e39a9c47e8cce569274414c9b4a50.zip
cast global
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/cast-type-mismatch.lua4
-rw-r--r--script/core/diagnostics/unknown-cast-variable.lua10
-rw-r--r--script/parser/guide.lua2
-rw-r--r--script/parser/luadoc.lua2
-rw-r--r--script/vm/tracer.lua20
5 files changed, 26 insertions, 12 deletions
diff --git a/script/core/diagnostics/cast-type-mismatch.lua b/script/core/diagnostics/cast-type-mismatch.lua
index b2d2bdf3..d86443c5 100644
--- a/script/core/diagnostics/cast-type-mismatch.lua
+++ b/script/core/diagnostics/cast-type-mismatch.lua
@@ -16,9 +16,9 @@ return function (uri, callback)
end
for _, doc in ipairs(state.ast.docs) do
- if doc.type == 'doc.cast' and doc.loc then
+ if doc.type == 'doc.cast' and doc.name then
await.delay()
- local defs = vm.getDefs(doc.loc)
+ local defs = vm.getDefs(doc.name)
local loc = defs[1]
if loc then
local defNode = vm.compileNode(loc)
diff --git a/script/core/diagnostics/unknown-cast-variable.lua b/script/core/diagnostics/unknown-cast-variable.lua
index 3f082a50..7c12e4d3 100644
--- a/script/core/diagnostics/unknown-cast-variable.lua
+++ b/script/core/diagnostics/unknown-cast-variable.lua
@@ -16,15 +16,15 @@ return function (uri, callback)
end
for _, doc in ipairs(state.ast.docs) do
- if doc.type == 'doc.cast' and doc.loc then
+ if doc.type == 'doc.cast' and doc.name then
await.delay()
- local defs = vm.getDefs(doc.loc)
+ local defs = vm.getDefs(doc.name)
local loc = defs[1]
if not loc then
callback {
- start = doc.loc.start,
- finish = doc.loc.finish,
- message = lang.script('DIAG_UNKNOWN_CAST_VARIABLE', doc.loc[1])
+ start = doc.name.start,
+ finish = doc.name.finish,
+ message = lang.script('DIAG_UNKNOWN_CAST_VARIABLE', doc.name[1])
}
end
end
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 0cf41389..3ab06aee 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -165,7 +165,7 @@ local childMap = {
['doc.version'] = {'#versions'},
['doc.diagnostic'] = {'#names'},
['doc.as'] = {'as'},
- ['doc.cast'] = {'loc', '#casts'},
+ ['doc.cast'] = {'name', '#casts'},
['doc.cast.block'] = {'extends'},
['doc.operator'] = {'op', 'exp', 'extends'},
}
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 8e94f24d..1a88d385 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -1316,7 +1316,7 @@ local docSwitch = util.switch()
return result
end
- result.loc = loc
+ result.name = loc
result.finish = loc.finish
while true do
diff --git a/script/vm/tracer.lua b/script/vm/tracer.lua
index 5aa5f63e..7999eaaa 100644
--- a/script/vm/tracer.lua
+++ b/script/vm/tracer.lua
@@ -8,6 +8,7 @@ local util = require 'utility'
---@field package _casts? parser.object[]
---@class vm.tracer
+---@field name string
---@field source parser.object
---@field assigns parser.object[]
---@field assignMap table<parser.object, true>
@@ -30,7 +31,7 @@ function mt:getCasts()
root._casts = {}
local docs = root.docs
for _, doc in ipairs(docs) do
- if doc.type == 'doc.cast' and doc.loc then
+ if doc.type == 'doc.cast' and doc.name then
root._casts[#root._casts+1] = doc
end
end
@@ -113,10 +114,10 @@ function mt:collectLocal()
local casts = self:getCasts()
for _, cast in ipairs(casts) do
- if cast.loc[1] == self.source[1]
+ if cast.name[1] == self.name
and cast.start > startPos
and cast.finish < finishPos
- and guide.getLocal(self.source, self.source[1], cast.start) == self.source then
+ and guide.getLocal(self.source, self.name, cast.start) == self.source then
self.casts[#self.casts+1] = cast
end
end
@@ -153,6 +154,17 @@ function mt:collectGlobal()
finishPos = get.finish
end
end
+
+ local casts = self:getCasts()
+ for _, cast in ipairs(casts) do
+ if cast.name[1] == self.name then
+ self.casts[#self.casts+1] = cast
+ end
+ end
+
+ if #self.casts > 0 then
+ self.fastCalc = false
+ end
end
---@param start integer
@@ -794,8 +806,10 @@ local function createTracer(source)
if source.type == 'local'
or source.type == 'self' then
+ tracer.name = source[1]
tracer:collectLocal()
else
+ tracer.name = source.global:getName()
tracer:collectGlobal()
end