diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/core/semantic-tokens.lua | 37 | ||||
-rw-r--r-- | script/parser/guide.lua | 1 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 14 | ||||
-rw-r--r-- | script/parser/newparser.lua | 1 | ||||
-rw-r--r-- | script/vm/compiler.lua | 38 |
5 files changed, 71 insertions, 20 deletions
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 3b7b77ee..3b23cb95 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -794,27 +794,26 @@ return function (uri, start, finish) for _, comm in ipairs(state.comms) do if start <= comm.start and comm.finish <= finish then - if comm.type == 'comment.short' then - local head = comm.text:match '^%-%s*[@|]' - if head then - results[#results+1] = { - start = comm.start, - finish = comm.start + #head + 1, - type = define.TokenTypes.comment, - } - results[#results+1] = { - start = comm.start + #head + 1, - finish = comm.start + #head + 2 + #comm.text:match('%S*', #head + 1), - type = define.TokenTypes.keyword, - modifieres = define.TokenModifiers.documentation, - } + local headPos = (comm.type == 'comment.short' and comm.text:match '^%-%s*[@|]()') + or (comm.type == 'comment.long' and comm.text:match '^@()') + if headPos then + local atPos + if comm.type == 'comment.short' then + atPos = headPos + 2 else - results[#results+1] = { - start = comm.start, - finish = comm.finish, - type = define.TokenTypes.comment, - } + atPos = headPos + #comm.mark end + results[#results+1] = { + start = comm.start, + finish = comm.start + atPos - 2, + type = define.TokenTypes.comment, + } + results[#results+1] = { + start = comm.start + atPos - 2, + finish = comm.start + atPos - 1 + #comm.text:match('%S*', headPos), + type = define.TokenTypes.keyword, + modifieres = define.TokenModifiers.documentation, + } else results[#results+1] = { start = comm.start, diff --git a/script/parser/guide.lua b/script/parser/guide.lua index f15e6e72..e28a25e9 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -143,6 +143,7 @@ local childMap = { ['doc.see'] = {'name', 'field'}, ['doc.version'] = {'#versions'}, ['doc.diagnostic'] = {'#names'}, + ['doc.as'] = {'as'}, } ---@type table<string, fun(obj: parser.object, list: parser.object[])> diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index a5b84fe1..f44b789b 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -125,6 +125,8 @@ Symbol <- ({} { ---@class parser.object ---@field literal boolean ---@field signs parser.object[] +---@field originalComment parser.object +---@field as parser.object local function trim(str) return str:match '^%s*(%S+)%s*$' @@ -1192,7 +1194,17 @@ local docSwitch = util.switch() finish = getFinish(), } end) - + : case 'as' + : call(function () + local result = { + type = 'doc.as', + start = getFinish(), + finish = getFinish(), + } + result.as = parseType(result) + result.finish = getFinish() + return result + end) local function convertTokens() local tp, text = nextToken() diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index e226417f..fe7b2343 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -537,6 +537,7 @@ local function skipComment(isAction) if longComment then longComment.type = 'comment.long' longComment.text = longComment[1] + longComment.mark = longComment[2] longComment[1] = nil longComment[2] = nil State.comms[#State.comms+1] = longComment diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 94968292..aee28366 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -478,6 +478,23 @@ local function getReturn(func, index, args) return result end +---@param source parser.object +---@return boolean +local function bindAs(source) + local root = guide.getRoot(source) + local docs = root.docs + if not docs then + return + end + for _, doc in ipairs(docs) do + if doc.type == 'doc.as' and doc.originalComment.start == source.finish + 2 then + vm.setNode(source, vm.compileNode(doc.as), true) + return true + end + end + return false +end + local function bindDocs(source) local isParam = source.parent.type == 'funcargs' or source.parent.type == 'in' @@ -894,6 +911,9 @@ local compilerSwitch = util.switch() end) : case 'paren' : call(function (source) + if bindAs(source) then + return + end if source.exp then vm.setNode(source, vm.compileNode(source.exp)) end @@ -924,6 +944,9 @@ local compilerSwitch = util.switch() end return vm.getNode(src) elseif src.type == 'getlocal' then + if bindAs(src) then + return + end vm.setNode(src, node, true) end end) @@ -944,6 +967,9 @@ local compilerSwitch = util.switch() end) : case 'getlocal' : call(function (source) + if bindAs(source) then + return + end vm.compileNode(source.node) end) : case 'setfield' @@ -966,6 +992,9 @@ local compilerSwitch = util.switch() : case 'getmethod' : case 'getindex' : call(function (source) + if bindAs(source) then + return + end compileByLocalID(source) local key = guide.getKeyName(source) if key == nil and source.index then @@ -1001,6 +1030,9 @@ local compilerSwitch = util.switch() end) : case 'getglobal' : call(function (source) + if bindAs(source) then + return + end if source.node[1] ~= '_ENV' then return end @@ -1275,6 +1307,9 @@ local compilerSwitch = util.switch() end) : case 'unary' : call(function (source) + if bindAs(source) then + return + end if source.op.type == 'not' then local result = vm.test(source[1]) if result == nil then @@ -1330,6 +1365,9 @@ local compilerSwitch = util.switch() end) : case 'binary' : call(function (source) + if bindAs(source) then + return + end if source.op.type == 'and' then local r1 = vm.test(source[1]) if r1 == true then |