summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-03-04 17:54:53 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-03-04 17:54:53 +0800
commit80aea7f979bbbacad94d10a88514c7bddf6d11cf (patch)
tree5d2501d8683935d3e37f40620fc8e8ea9870f80d /script/vm
parent399c008ba189fe22716d46d2974de1569b1d39e8 (diff)
downloadlua-language-server-80aea7f979bbbacad94d10a88514c7bddf6d11cf.zip
update
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/compiler.lua90
-rw-r--r--script/vm/getDef.lua19
2 files changed, 65 insertions, 44 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 7053e61c..1f93f130 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -109,9 +109,15 @@ function m.getClassFields(node, key, pushResult)
if set.bindSources then
for _, src in ipairs(set.bindSources) do
if searchFieldMap[src.type] then
- searchFieldMap[src.type](src, key, function (src)
+ searchFieldMap[src.type](src, key, function (field)
hasFounded = true
- pushResult(src)
+ pushResult(field)
+ end)
+ end
+ if src._globalNode then
+ searchFieldMap['global'](src._globalNode, key, function (field)
+ hasFounded = true
+ pushResult(field)
end)
end
end
@@ -172,14 +178,52 @@ local function getReturn(func, index, source, args)
end
end
+local function bindDocs(source)
+ local hasFounded = false
+ local isParam = source.parent.type == 'funcargs'
+ for _, doc in ipairs(source.bindDocs) do
+ if doc.type == 'doc.type' then
+ if not isParam then
+ hasFounded = true
+ m.setNode(source, m.compileNode(doc))
+ end
+ end
+ if doc.type == 'doc.class' then
+ if source.type == 'local'
+ or (source._globalNode and guide.isSet(source)) then
+ hasFounded = true
+ m.setNode(source, m.compileNode(doc))
+ end
+ end
+ if doc.type == 'doc.param' then
+ if isParam and source[1] == doc.param[1] then
+ hasFounded = true
+ m.setNode(source, m.compileNode(doc))
+ end
+ end
+ end
+ return hasFounded
+end
+
local function compileByLocalID(source)
local sources = localID.getSources(source)
if not sources then
return
end
+ local hasMarkDoc
+ for _, src in ipairs(sources) do
+ if src.bindDocs then
+ if bindDocs(src) then
+ hasMarkDoc = true
+ m.setNode(source, m.compileNode(src))
+ end
+ end
+ end
for _, src in ipairs(sources) do
if src.value then
- m.setNode(source, m.compileNode(src.value))
+ if not hasMarkDoc or guide.isLiteral(src.value) then
+ m.setNode(source, m.compileNode(src.value))
+ end
end
end
end
@@ -228,33 +272,6 @@ local function selectNode(source, list, index)
return m.compileNode(exp)
end
-local function bindDocs(source)
- local hasFounded = false
- local isParam = source.parent.type == 'funcargs'
- for _, doc in ipairs(source.bindDocs) do
- if doc.type == 'doc.type' then
- if not isParam then
- hasFounded = true
- m.setNode(source, m.compileNode(doc))
- end
- end
- if doc.type == 'doc.class' then
- if source.type == 'local'
- or (source._globalNode and guide.isSet(source)) then
- hasFounded = true
- m.setNode(source, m.compileNode(doc))
- end
- end
- if doc.type == 'doc.param' then
- if isParam and source[1] == doc.param[1] then
- hasFounded = true
- m.setNode(source, m.compileNode(doc))
- end
- end
- end
- return hasFounded
-end
-
local compilerMap = util.switch()
: case 'boolean'
: case 'table'
@@ -427,9 +444,20 @@ local function compileByGlobal(source)
if source._globalNode then
m.setNode(source, source._globalNode)
if source._globalNode.cate == 'variable' then
+ local hasMarkDoc
+ for _, set in ipairs(source._globalNode:getSets()) do
+ if set.bindDocs then
+ if bindDocs(set) then
+ m.setNode(source, m.compileNode(set))
+ hasMarkDoc = true
+ end
+ end
+ end
for _, set in ipairs(source._globalNode:getSets()) do
if set.value then
- m.setNode(source, m.compileNode(set.value))
+ if not hasMarkDoc or guide.isLiteral(set.value) then
+ m.setNode(source, m.compileNode(set.value))
+ end
end
end
end
diff --git a/script/vm/getDef.lua b/script/vm/getDef.lua
index b454ad48..e9bd3748 100644
--- a/script/vm/getDef.lua
+++ b/script/vm/getDef.lua
@@ -163,18 +163,6 @@ end
---@param source parser.object
---@param pushResult fun(src: parser.object)
-local function searchByGlobal(source, pushResult)
- local global = globalMgr.getNode(source)
- if not global then
- return
- end
- for _, src in ipairs(global:getSets()) do
- pushResult(src)
- end
-end
-
----@param source parser.object
----@param pushResult fun(src: parser.object)
local function searchByID(source, pushResult)
local idSources = localID.getSources(source)
if not idSources then
@@ -228,6 +216,12 @@ function vm.getDefs(source)
end
if not mark[src] then
mark[src] = true
+ if src.type == 'global' then
+ for _, set in ipairs(src:getSets()) do
+ pushResult(set)
+ end
+ return
+ end
if guide.isSet(src)
or guide.isLiteral(src) then
results[#results+1] = src
@@ -236,7 +230,6 @@ function vm.getDefs(source)
end
searchBySimple(source, pushResult)
- searchByGlobal(source, pushResult)
searchByID(source, pushResult)
searchByParentNode(source, pushResult)
searchByNode(source, pushResult)