diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-21 18:22:41 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-21 18:22:41 +0800 |
commit | 8ba44c3e21ac761b88226fec0cc8a5347a4a5804 (patch) | |
tree | dcc3ef284b0eb7f08f91899eb6d3eb48cd55c997 /script | |
parent | cc6142db768430288fa71e144ba479a7a0e6e420 (diff) | |
download | lua-language-server-8ba44c3e21ac761b88226fec0cc8a5347a4a5804.zip |
#1080 using `---@overload` as class constructor
Diffstat (limited to 'script')
-rw-r--r-- | script/core/semantic-tokens.lua | 26 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 3 | ||||
-rw-r--r-- | script/vm/compiler.lua | 12 |
3 files changed, 25 insertions, 16 deletions
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 568bb222..3b7b77ee 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -165,21 +165,17 @@ local Care = util.switch() -- 5. Class declaration -- only search this local if loc.bindDocs then - for i = #loc.bindDocs, 1, -1 do - local doc = loc.bindDocs[i] - if doc.type == 'doc.type' then - break - end - if doc.type == "doc.class" and doc.bindSources then - for _, src in ipairs(doc.bindSources) do - if src == loc then - results[#results+1] = { - start = source.start, - finish = source.finish, - type = define.TokenTypes.class, - } - return - end + local isParam = source.parent.type == 'funcargs' + or source.parent.type == 'in' + if not isParam then + for _, doc in ipairs(loc.bindDocs) do + if doc.type == 'doc.class' then + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.class, + } + return end end end diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 7c669d1f..4cb8b520 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -1320,7 +1320,8 @@ local function isNextLine(binded, doc) if lastDoc.type == 'doc.class' or lastDoc.type == 'doc.field' then if doc.type ~= 'doc.field' - and doc.type ~= 'doc.comment' then + and doc.type ~= 'doc.comment' + and doc.type ~= 'doc.overload' then return false end end diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index eea6e093..ef91b4b1 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -840,6 +840,18 @@ local function compileLocalBase(source) vm.setNode(source, globalMgr.getGlobal('type', 'integer')) end + if source.bindDocs then + local isParam = source.parent.type == 'funcargs' + or source.parent.type == 'in' + for _, doc in ipairs(source.bindDocs) do + if doc.type == 'doc.overload' then + if not isParam then + vm.setNode(source, vm.compileNode(doc)) + end + end + end + end + baseNode:merge(vm.getNode(source)) vm.removeNode(source) |