From 6c4f440d86783deda607e147824285ecd88de4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 29 Apr 2021 20:38:00 +0800 Subject: update parser --- script/parser/ast.lua | 70 ++++++++++++++++++++++++----------------------- script/parser/grammar.lua | 43 ++++++++++++++--------------- 2 files changed, 56 insertions(+), 57 deletions(-) (limited to 'script') diff --git a/script/parser/ast.lua b/script/parser/ast.lua index 45801cf6..38c4e51b 100644 --- a/script/parser/ast.lua +++ b/script/parser/ast.lua @@ -983,19 +983,7 @@ local Defs = { finish = start, } end, - Function = function (functionStart, functionFinish, args, actions, endStart, endFinish) - actions.type = 'function' - actions.start = functionStart - actions.finish = endFinish - 1 - actions.args = args - actions.keyword= { - functionStart, functionFinish - 1, - endStart, endFinish - 1, - } - checkMissEnd(functionStart) - return actions - end, - NamedFunction = function (functionStart, functionFinish, name, args, actions, endStart, endFinish) + Function = function (functionStart, functionFinish, name, args, actions, endStart, endFinish) actions.type = 'function' actions.start = functionStart actions.finish = endFinish - 1 @@ -1006,7 +994,7 @@ local Defs = { } checkMissEnd(functionStart) if not name then - return + return actions end if name.type == 'getname' then name.type = 'setname' @@ -1030,35 +1018,49 @@ local Defs = { name.vstart = functionStart return name end, - LocalFunction = function (start, functionStart, functionFinish, name, args, actions, endStart, endFinish) - actions.type = 'function' - actions.start = start - actions.finish = endFinish - 1 - actions.args = args - actions.keyword= { - functionStart, functionFinish - 1, - endStart, endFinish - 1, - } - checkMissEnd(start) - - if not name then - return + LocalFunction = function (start, name) + if name.type == 'function' then + PushError { + type = 'MISS_NAME', + start = name.keyword[2] + 1, + finish = name.keyword[2] + 1, + } + return name end - - if name.type ~= 'getname' then + if name.type ~= 'setname' then PushError { type = 'UNEXPECT_LFUNC_NAME', start = name.start, finish = name.finish, } - return + return name end - local loc = createLocal(name, name.start, actions) + local loc = createLocal(name, name.start, name.value) loc.localfunction = true - loc.vstart = functionStart - - return loc + loc.vstart = name.value.start + return name + end, + NamedFunction = function (name) + if name.type == 'function' then + PushError { + type = 'MISS_NAME', + start = name.keyword[2] + 1, + finish = name.keyword[2] + 1, + } + end + return name + end, + ExpFunction = function (func) + if func.type ~= 'function' then + PushError { + type = 'UNEXPECT_EFUNC_NAME', + start = func.start, + finish = func.finish, + } + return func.value + end + return func end, Table = function (start, tbl, finish) tbl.type = 'table' diff --git a/script/parser/grammar.lua b/script/parser/grammar.lua index 53d174f3..ea9a25e0 100644 --- a/script/parser/grammar.lua +++ b/script/parser/grammar.lua @@ -319,7 +319,7 @@ ExpUnit <- Nil / Number / Dots / Table - / Function + / ExpFunction / Simple Simple <- {| Prefix (Sp Suffix)* |} @@ -327,7 +327,7 @@ Simple <- {| Prefix (Sp Suffix)* |} Prefix <- Sp ({} PL DirtyExp DirtyPR {}) -> Paren / Single -Single <- Name +Single <- !FUNCTION Name -> Single Suffix <- SuffixWithoutCall / ({} PL SuffixCall DirtyPR {}) @@ -377,8 +377,21 @@ NewIndex <- Sp ({} Index NeedAssign DirtyExp {}) NewField <- Sp ({} MustName ASSIGN DirtyExp {}) -> NewField +ExpFunction <- Function + -> ExpFunction Function <- FunctionBody -> Function +FunctionBody + <- FUNCTION FuncName FuncArgs + {| (!END Action)* |} + NeedEnd + / FUNCTION FuncName FuncArgsMiss + {| %nil |} + NeedEnd +FuncName <- !END {| Single (Sp SuffixWithoutCall)* |} + -> Simple + / %nil + FuncArgs <- Sp ({} PL {| FuncArg+ |} DirtyPR {}) -> FuncArgs / PL DirtyPR %nil @@ -386,12 +399,6 @@ FuncArgsMiss<- {} -> MissPL DirtyPR %nil FuncArg <- DOTS / Name / COMMA -FunctionBody<- FUNCTION FuncArgs - {| (!END Action)* |} - NeedEnd - / FUNCTION FuncArgsMiss - {| %nil |} - NeedEnd -- 纯占位,修改了 `relabel.lua` 使重复定义不抛错 Action <- !END . @@ -515,26 +522,16 @@ LocalNameList LocalName <- (MustName LocalAttr?) -> LocalName +NamedFunction + <- Function + -> NamedFunction + Call <- Simple -> SimpleCall LocalFunction - <- Sp ({} LOCAL FunctionNamedBody) + <- Sp ({} LOCAL Function) -> LocalFunction - -NamedFunction - <- FunctionNamedBody - -> NamedFunction -FunctionNamedBody - <- FUNCTION FuncName FuncArgs - {| (!END Action)* |} - NeedEnd - / FUNCTION FuncName FuncArgsMiss - {| %nil |} - NeedEnd -FuncName <- {| Single (Sp SuffixWithoutCall)* |} - -> Simple - / {} -> MissName %nil ]] grammar 'Lua' [[ -- cgit v1.2.3 From d5f2c21d65f1cabe577ff8e6e259e546f3c969d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 30 Apr 2021 11:23:16 +0800 Subject: #514 supports `-- #region` --- script/core/folding.lua | 2 ++ script/utility.lua | 37 +++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'script') diff --git a/script/core/folding.lua b/script/core/folding.lua index 77cb39e7..15678995 100644 --- a/script/core/folding.lua +++ b/script/core/folding.lua @@ -1,5 +1,6 @@ local files = require "files" local guide = require "core.guide" +local util = require 'utility' local Care = { ['function'] = function (source, text, results) @@ -92,6 +93,7 @@ local Care = { end, ['comment.short'] = function (source, text, results, status) local ltext = source.text:lower() + ltext = util.trim(ltext, 'left') if ltext:sub(1, #'region') == 'region' or ltext:sub(1, #'#region') == '#region' then if not status.regions then diff --git a/script/utility.lua b/script/utility.lua index a98bef92..04597a39 100644 --- a/script/utility.lua +++ b/script/utility.lua @@ -23,6 +23,14 @@ local utf8 = utf8 _ENV = nil +local function isInteger(n) + if mathType then + return mathType(n) == 'integer' + else + return type(n) == 'number' and n % 1 == 0 + end +end + local function formatNumber(n) if n == inf or n == -inf @@ -30,7 +38,7 @@ local function formatNumber(n) or n ~= n then -- IEEE 标准中,NAN 不等于自己。但是某些实现中没有遵守这个规则 return ('%q'):format(n) end - if mathType(n) == 'integer' then + if isInteger(n) then return tostring(n) end local str = ('%.10f'):format(n) @@ -38,14 +46,6 @@ local function formatNumber(n) return str end -local function isInteger(n) - if mathType then - return mathType(n) == 'integer' - else - return type(n) == 'number' and n % 1 == 0 - end -end - local TAB = setmetatable({}, { __index = function (self, n) self[n] = stringRep(' ', n) return self[n] @@ -204,7 +204,10 @@ function m.equal(a, b) end return true elseif tp1 == 'number' then - return mathAbs(a - b) <= 1e-10 + if mathAbs(a - b) <= 1e-10 then + return true + end + return tostring(a) == tostring(b) else return a == b end @@ -617,4 +620,18 @@ function m.sortByScore(tbl, callbacks) end) end +---裁剪字符串 +---@param str string +---@param mode? '"left"'|'"right"' +---@return string +function m.trim(str, mode) + if mode == "left" then + return str:gsub('^%s+', '') + end + if mode == "right" then + return str:gsub('%s+$', '') + end + return str:match '^%s*(%S+)%s*$' +end + return m -- cgit v1.2.3 From 6b106652fb3b8497f777d18dbb70ffc33de0667d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 30 Apr 2021 14:33:41 +0800 Subject: highlight region --- script/core/highlight.lua | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'script') diff --git a/script/core/highlight.lua b/script/core/highlight.lua index e79bb797..12ec114f 100644 --- a/script/core/highlight.lua +++ b/script/core/highlight.lua @@ -3,6 +3,7 @@ local files = require 'files' local vm = require 'vm' local define = require 'proto.define' local findSource = require 'core.find-source' +local util = require 'utility' local function eachRef(source, callback) local results = guide.requestReference(source) @@ -138,6 +139,88 @@ local function findKeyWord(ast, text, offset, callback) end) end +local function isRegion(str) + if str:sub(1, #'region') == 'region' + or str:sub(1, #'#region') == '#region' then + return true + end + return false +end + +local function isEndRegion(str) + if str:sub(1, #'endregion') == 'endregion' + or str:sub(1, #'#endregion') == '#endregion' then + return true + end + return false +end + +local function checkRegion(ast, text, offset, callback) + local count + local start, finish + local selected + for i, comment in ipairs(ast.comms) do + if comment.type == 'comment.short' then + if comment.start <= offset + and comment.finish >= offset then + local ltext = comment.text:lower() + ltext = util.trim(ltext, 'left') + if isRegion(ltext) then + start = comment.start - 2 + count = 1 + selected = i + elseif isEndRegion(ltext) then + finish = comment.finish + count = 1 + selected = i + else + return + end + break + end + end + end + if not selected then + return + end + if start then + for i = selected + 1, #ast.comms do + local comment = ast.comms[i] + if comment.type == 'comment.short' then + local ltext = comment.text:lower() + ltext = util.trim(ltext, 'left') + if isRegion(ltext) then + count = count + 1 + elseif isEndRegion(ltext) then + count = count - 1 + if count == 0 then + callback(start, comment.finish) + return + end + end + end + end + end + if finish then + for i = selected - 1, 1, -1 do + local comment = ast.comms[i] + if comment.type == 'comment.short' then + local ltext = comment.text:lower() + ltext = util.trim(ltext, 'left') + if isEndRegion(ltext) then + count = count + 1 + elseif isRegion(ltext) then + count = count - 1 + if count == 0 then + callback(comment.start - 2, finish) + return + end + end + end + end + end +end + local accept = { ['label'] = true, ['goto'] = true, @@ -255,6 +338,14 @@ return function (uri, offset) } end) + checkRegion(ast, text, offset, function (start, finish) + results[#results+1] = { + start = start, + finish = finish, + kind = define.DocumentHighlightKind.Text + } + end) + if #results == 0 then return nil end -- cgit v1.2.3 From 69a3ce64e5032f036d054ae435a8c523996567ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 30 Apr 2021 14:43:16 +0800 Subject: resolve #514 --- script/config.lua | 1 + script/core/completion.lua | 3 +++ 2 files changed, 4 insertions(+) (limited to 'script') diff --git a/script/config.lua b/script/config.lua index 7991e1ad..a133cf1c 100644 --- a/script/config.lua +++ b/script/config.lua @@ -164,6 +164,7 @@ local ConfigTemplate = { keywordSnippet = {'Replace', String}, displayContext = {6, Integer}, workspaceWord = {true, Boolean}, + autoRequire = {true, Boolean}, }, signatureHelp = { enable = {true, Boolean}, diff --git a/script/core/completion.lua b/script/core/completion.lua index 59bba005..6ee4d61d 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -292,6 +292,9 @@ local function checkLocal(ast, word, offset, results) end local function checkModule(ast, word, offset, results) + if not config.config.completion.autoRequire then + return + end local locals = guide.getVisibleLocals(ast.ast, offset) for uri in files.eachFile() do if files.eq(uri, guide.getUri(ast.ast)) then -- cgit v1.2.3 From 908feedce35b056c38fab57fd4e32727b117479c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 30 Apr 2021 15:54:20 +0800 Subject: resolve #507 new setting `hover.enumsLimit` --- script/config.lua | 1 + script/core/guide.lua | 11 ++++++++++- script/proto/define.lua | 3 --- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'script') diff --git a/script/config.lua b/script/config.lua index a133cf1c..8bc05b98 100644 --- a/script/config.lua +++ b/script/config.lua @@ -176,6 +176,7 @@ local ConfigTemplate = { viewNumber = {true, Boolean}, fieldInfer = {3000, Integer}, previewFields = {100, Integer}, + enumsLimit = {5, Integer}, }, color = { mode = {'Semantic', String}, diff --git a/script/core/guide.lua b/script/core/guide.lua index b80a3628..367b91e2 100644 --- a/script/core/guide.lua +++ b/script/core/guide.lua @@ -1,4 +1,6 @@ local util = require 'utility' +local config = require 'config' +local lang = require 'language' local error = error local type = type local next = next @@ -3396,7 +3398,14 @@ function m.mergeTypes(types) end end) - return tableConcat(results, '|') + local enumsLimit = config.config.hover.enumsLimit + if #results > enumsLimit then + return tableConcat(results, '|', 1, enumsLimit) + .. lang.script('HOVER_MORE_ENUMS', #results - enumsLimit) + else + return tableConcat(results, '|') + end + end function m.getClassExtends(class) diff --git a/script/proto/define.lua b/script/proto/define.lua index 15e434de..abfaa9b0 100644 --- a/script/proto/define.lua +++ b/script/proto/define.lua @@ -1,6 +1,3 @@ -local guide = require 'core.guide' -local util = require 'utility' - local m = {} ---@alias location table -- cgit v1.2.3 From e30e02d51f80b0d48e85fcc110d907ae4a6cbccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 30 Apr 2021 17:55:10 +0800 Subject: fix completion: details may be suspended --- script/core/completion.lua | 4 +--- script/provider/provider.lua | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'script') diff --git a/script/core/completion.lua b/script/core/completion.lua index 6ee4d61d..98a9250f 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -48,9 +48,7 @@ local function resolveStack(id) return nil end - -- 当进行新的 resolve 时,放弃当前的 resolve - await.close('completion.resolve') - return await.await(callback, 'completion.resolve') + return callback() end local function trim(str) diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 65993940..a6f4d9cc 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -550,6 +550,8 @@ proto.on('completionItem/resolve', function (item) if not item.data then return item end + await.close 'completion.resolve' + await.setID 'completion.resolve' local id = item.data.id local uri = item.data.uri --await.setPriority(1000) -- cgit v1.2.3 From 4ad097f786df90286c6212c8fc3c6472e8fd1368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 30 Apr 2021 17:59:09 +0800 Subject: stash --- script/config.lua | 1 + script/core/completion.lua | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'script') diff --git a/script/config.lua b/script/config.lua index 8bc05b98..97df7c17 100644 --- a/script/config.lua +++ b/script/config.lua @@ -165,6 +165,7 @@ local ConfigTemplate = { displayContext = {6, Integer}, workspaceWord = {true, Boolean}, autoRequire = {true, Boolean}, + showParams = {true, Boolean}, }, signatureHelp = { enable = {true, Boolean}, diff --git a/script/core/completion.lua b/script/core/completion.lua index 98a9250f..6f1a2952 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -199,7 +199,6 @@ local function buildFunction(results, source, oop, data) if snipType == 'Both' or snipType == 'Replace' then local snipData = util.deepCopy(data) snipData.kind = define.CompletionItemKind.Snippet - snipData.label = snipData.label .. '()' snipData.insertText = buildFunctionSnip(source, oop) snipData.insertTextFormat = 2 snipData.id = stack(function () @@ -401,7 +400,8 @@ end local function checkFieldThen(name, src, word, start, offset, parent, oop, results) local value = guide.getObjectValue(src) or src local kind = define.CompletionItemKind.Field - if value.type == 'function' then + if value.type == 'function' + or value.type == 'doc.type.function' then if oop then kind = define.CompletionItemKind.Method else @@ -453,6 +453,20 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul } end +local function getParams(func) + local args = {} + for _, arg in ipairs(func.args) do + if arg.type == '...' then + args[#args+1] = '...' + elseif arg.type == 'doc.type.arg' then + args[#args+1] = arg.name[1] + else + args[#args+1] = arg[1] + end + end + return '(' .. table.concat(args, ', ') .. ')' +end + local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals, isGlobal) local fields = {} local count = 0 @@ -470,8 +484,20 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res if not matchKey(word, name, count >= 100) then goto CONTINUE end + local funcLabel + if config.config.completion.showParams then + local value = guide.getObjectValue(src) or src + if value.type == 'function' + or value.type == 'doc.type.function' then + funcLabel = name .. getParams(value) + fields[funcLabel] = src + fields[name] = false + count = count + 1 + goto CONTINUE + end + end local last = fields[name] - if not last then + if last == nil then fields[name] = src count = count + 1 goto CONTINUE @@ -491,7 +517,9 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res ::CONTINUE:: end for name, src in util.sortPairs(fields) do - checkFieldThen(name, src, word, start, offset, parent, oop, results) + if src then + checkFieldThen(name, src, word, start, offset, parent, oop, results) + end end end -- cgit v1.2.3 From d948291c63ea17804b37bd4e3e5f123ac63730d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 May 2021 15:24:22 +0800 Subject: stash --- script/core/completion.lua | 64 +++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) (limited to 'script') diff --git a/script/core/completion.lua b/script/core/completion.lua index 6f1a2952..bab0f452 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -252,6 +252,26 @@ local function isSameSource(ast, source, pos) return source.start <= pos and source.finish >= pos end +local function getParams(func, oop) + if not func.args then + return '' + end + local args = {} + for _, arg in ipairs(func.args) do + if arg.type == '...' then + args[#args+1] = '...' + elseif arg.type == 'doc.type.arg' then + args[#args+1] = arg.name[1] + else + args[#args+1] = arg[1] + end + end + if oop and args[1] ~= '...' then + table.remove(args, 1) + end + return '(' .. table.concat(args, ', ') .. ')' +end + local function checkLocal(ast, word, offset, results) local locals = guide.getVisibleLocals(ast.ast, offset) for name, source in pairs(locals) do @@ -262,16 +282,22 @@ local function checkLocal(ast, word, offset, results) goto CONTINUE end if vm.hasType(source, 'function') then - buildFunction(results, source, false, { - label = name, - kind = define.CompletionItemKind.Function, - id = stack(function () - return { - detail = buildDetail(source), - description = buildDesc(source), - } - end), - }) + for _, def in ipairs(vm.getDefs(source, 0)) do + if def.type == 'function' + or def.type == 'doc.type.function' then + local funcLabel = name .. getParams(def, false) + buildFunction(results, source, false, { + label = funcLabel, + kind = define.CompletionItemKind.Function, + id = stack(function () + return { + detail = buildDetail(source), + description = buildDesc(source), + } + end), + }) + end + end else results[#results+1] = { label = name, @@ -453,20 +479,6 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul } end -local function getParams(func) - local args = {} - for _, arg in ipairs(func.args) do - if arg.type == '...' then - args[#args+1] = '...' - elseif arg.type == 'doc.type.arg' then - args[#args+1] = arg.name[1] - else - args[#args+1] = arg[1] - end - end - return '(' .. table.concat(args, ', ') .. ')' -end - local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals, isGlobal) local fields = {} local count = 0 @@ -489,7 +501,7 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res local value = guide.getObjectValue(src) or src if value.type == 'function' or value.type == 'doc.type.function' then - funcLabel = name .. getParams(value) + funcLabel = name .. getParams(value, oop) fields[funcLabel] = src fields[name] = false count = count + 1 @@ -572,7 +584,7 @@ local function checkCommon(myUri, word, text, offset, results) results.enableCommon = true local used = {} for _, result in ipairs(results) do - used[result.label] = true + used[result.label:match '^[^(]*'] = true end for _, data in ipairs(keyWordMap) do used[data[1]] = true -- cgit v1.2.3 From 6c0fc0d438154f2164e10674f5c1a4b983382039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 May 2021 15:28:37 +0800 Subject: stash --- script/core/completion.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'script') diff --git a/script/core/completion.lua b/script/core/completion.lua index bab0f452..624ea0a6 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -254,7 +254,7 @@ end local function getParams(func, oop) if not func.args then - return '' + return '()' end local args = {} for _, arg in ipairs(func.args) do -- cgit v1.2.3 From d0f2fff90e56a6e2b1448217174e29fb0d17d05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 May 2021 16:20:35 +0800 Subject: resolve #478 new setting: `completion.showParams` --- script/core/completion.lua | 8 ++++++++ script/core/guide.lua | 2 ++ 2 files changed, 10 insertions(+) (limited to 'script') diff --git a/script/core/completion.lua b/script/core/completion.lua index 624ea0a6..03d17a22 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -505,6 +505,14 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res fields[funcLabel] = src fields[name] = false count = count + 1 + if value.type == 'function' and value.bindDocs then + for _, doc in ipairs(value.bindDocs) do + if doc.type == 'doc.overload' then + funcLabel = name .. getParams(doc.overload, oop) + fields[funcLabel] = doc.overload + end + end + end goto CONTINUE end end diff --git a/script/core/guide.lua b/script/core/guide.lua index 367b91e2..e4871060 100644 --- a/script/core/guide.lua +++ b/script/core/guide.lua @@ -1842,6 +1842,8 @@ function m.checkSameSimpleByBindDocs(status, obj, start, pushQueue, mode) if obj.type == '...' then results[#results+1] = doc end + elseif doc.type == 'doc.overload' then + results[#results+1] = doc.overload end end for _, res in ipairs(results) do -- cgit v1.2.3 From 24b83882cfca469a797bf5536f2d5c68762189bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 May 2021 16:25:30 +0800 Subject: fix insertText --- script/core/completion.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'script') diff --git a/script/core/completion.lua b/script/core/completion.lua index 03d17a22..60c3e16d 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -288,6 +288,7 @@ local function checkLocal(ast, word, offset, results) local funcLabel = name .. getParams(def, false) buildFunction(results, source, false, { label = funcLabel, + insertText = name, kind = define.CompletionItemKind.Function, id = stack(function () return { @@ -436,6 +437,7 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul buildFunction(results, src, oop, { label = name, kind = kind, + insertText = name:match '^[^(]+', deprecated = vm.isDeprecated(src) or nil, id = stack(function () return { -- cgit v1.2.3 From a8c95b64d7e8a8481cbe961b8b872ef0710d618f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 May 2021 16:37:29 +0800 Subject: fix call snip --- script/core/completion.lua | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'script') diff --git a/script/core/completion.lua b/script/core/completion.lua index 60c3e16d..ee61029d 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -121,17 +121,9 @@ local function findParentInStringIndex(ast, text, offset) return parent.node, false end -local function buildFunctionSnip(source, oop) +local function buildFunctionSnip(source, value, oop) local name = getName(source):gsub('^.+[$.:]', '') - local defs = vm.getDefs(source, 0) - local args = '' - for _, def in ipairs(defs) do - local defArgs = getArg(def, oop) - if defArgs ~= '' then - args = defArgs - break - end - end + local args = getArg(value, oop) local id = 0 args = args:gsub('[^,]+', function (arg) id = id + 1 @@ -191,7 +183,7 @@ local function buildDesc(source) return md:string() end -local function buildFunction(results, source, oop, data) +local function buildFunction(results, source, value, oop, data) local snipType = config.config.completion.callSnippet if snipType == 'Disable' or snipType == 'Both' then results[#results+1] = data @@ -199,7 +191,7 @@ local function buildFunction(results, source, oop, data) if snipType == 'Both' or snipType == 'Replace' then local snipData = util.deepCopy(data) snipData.kind = define.CompletionItemKind.Snippet - snipData.insertText = buildFunctionSnip(source, oop) + snipData.insertText = buildFunctionSnip(source, value, oop) snipData.insertTextFormat = 2 snipData.id = stack(function () return { @@ -286,7 +278,7 @@ local function checkLocal(ast, word, offset, results) if def.type == 'function' or def.type == 'doc.type.function' then local funcLabel = name .. getParams(def, false) - buildFunction(results, source, false, { + buildFunction(results, source, def, false, { label = funcLabel, insertText = name, kind = define.CompletionItemKind.Function, @@ -434,7 +426,7 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul else kind = define.CompletionItemKind.Function end - buildFunction(results, src, oop, { + buildFunction(results, src, value, oop, { label = name, kind = kind, insertText = name:match '^[^(]+', -- cgit v1.2.3 From 56e30b07fffee79e6c0612f0f099eb590c7be558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 May 2021 17:10:37 +0800 Subject: resolve #476 supports multiline comments --- script/parser/ast.lua | 6 +++--- script/parser/grammar.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'script') diff --git a/script/parser/ast.lua b/script/parser/ast.lua index 38c4e51b..3ac4d27f 100644 --- a/script/parser/ast.lua +++ b/script/parser/ast.lua @@ -277,7 +277,7 @@ local Defs = { type = 'comment.long', start = start, finish = finish - 1, - text = '', + text = str, } if not close then local endSymbol = ']' .. ('='):rep(afterEq-beforeEq) .. ']' @@ -318,7 +318,7 @@ local Defs = { } end end, - CLongComment = function (start1, finish1, start2, finish2) + CLongComment = function (start1, finish1, str, start2, finish2) if State.options.nonstandardSymbol and State.options.nonstandardSymbol['/**/'] then else PushError { @@ -344,7 +344,7 @@ local Defs = { type = 'comment.clong', start = start1, finish = finish2 - 1, - text = '', + text = str, } end, CCommentPrefix = function (start, finish, commentFinish) diff --git a/script/parser/grammar.lua b/script/parser/grammar.lua index ea9a25e0..01756c2a 100644 --- a/script/parser/grammar.lua +++ b/script/parser/grammar.lua @@ -88,13 +88,13 @@ end grammar 'Comment' [[ Comment <- LongComment / '--' ShortComment -LongComment <- ({} '--[' {} {:eq: '='* :} {} '[' +LongComment <- ({} '--[' {} {:eq: '='* :} {} '[' %nl? {(!CommentClose .)*} ((CommentClose / %nil) {})) -> LongComment / ( - {} '/*' {} - (!'*/' .)* + {} '/*' {} %nl? + {(!'*/' .)*} {} '*/' {} ) -> CLongComment -- cgit v1.2.3 From 8123dd362c1991ac87a26822729f24a53ef6b35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 May 2021 17:48:31 +0800 Subject: resolve #455 tail comments support lua string --- script/parser/luadoc.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'script') diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 74e53718..3ab9f6a1 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -2,6 +2,7 @@ local m = require 'lpeglabel' local re = require 'parser.relabel' local lines = require 'parser.lines' local guide = require 'core.guide' +local grammar = require 'parser.grammar' local TokenTypes, TokenStarts, TokenFinishs, TokenContents local Ci, Offset, pushError, Ct, NextComment, Lines @@ -999,16 +1000,23 @@ local function convertTokens() end local function trimTailComment(text) + local comment = text if text:sub(1, 1) == '@' then - return text:sub(2) + comment = text:sub(2) end if text:sub(1, 1) == '#' then - return text:sub(2) + comment = text:sub(2) end if text:sub(1, 2) == '--' then - return text:sub(3) + comment = text:sub(3) end - return text + if comment:find '^%s*[\'"[]' then + local result = grammar(nil, comment:gsub('^%s+', ''), 'string') + if result then + comment = result[1][1] + end + end + return comment end local function buildLuaDoc(comment) @@ -1185,7 +1193,7 @@ local function bindDoc(sources, lns, binded) end bindGeneric(binded) local row = guide.positionOf(lns, lastDoc.finish) - local cstart, cfinish = guide.lineRange(lns, row) + local cstart, cfinish = guide.lineRange(lns, row) local nstart, nfinish = guide.lineRange(lns, row + 1) bindDocsBetween(sources, binded, bindSources, cstart, cfinish) if #bindSources == 0 then -- cgit v1.2.3 From d130e76f0c8da3db5a94acd61254757811a85e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 8 May 2021 14:04:57 +0800 Subject: fix #529 --- script/parser/ast.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'script') diff --git a/script/parser/ast.lua b/script/parser/ast.lua index 3ac4d27f..45d77631 100644 --- a/script/parser/ast.lua +++ b/script/parser/ast.lua @@ -9,7 +9,12 @@ local tableSort = table.sort _ENV = nil -local State +local DefaultState = { + lua = '', + options = {}, +} + +local State = DefaultState local PushError local PushDiag local PushComment @@ -1925,7 +1930,7 @@ local function init(state) end local function close() - State = nil + State = DefaultState PushError = function (...) end PushDiag = function (...) end PushComment = function (...) end -- cgit v1.2.3 From 6b2287cba3bd55ce3c8b49e00042b3748bd7bd6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 8 May 2021 14:12:43 +0800 Subject: dont convert nl --- script/core/hover/description.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'script') diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 14da4fcf..401ca5a7 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -170,7 +170,7 @@ local function buildEnumChunk(docType, name) or (enum.additional and '+>') or ' |', enum[1], - enum.comment and (' -- %s'):format(enum.comment:gsub('[\r\n]+', ' ')) or '' + enum.comment and (' -- %s'):format(enum.comment) or '' ) end return table.concat(lines, '\n') @@ -264,7 +264,7 @@ local function getFunctionComment(source) comments[#comments+1] = '\n' comments[#comments+1] = ('@*param* `%s` — %s'):format( doc.param[1], - doc.comment.text:gsub('[\r\n]+', ' ') + doc.comment.text ) comments[#comments+1] = '\n' end @@ -280,9 +280,9 @@ local function getFunctionComment(source) end if doc.comment then if #name == 0 then - comments[#comments+1] = ('@*return* — %s'):format(doc.comment.text:gsub('[\r\n]+', ' ')) + comments[#comments+1] = ('@*return* — %s'):format(doc.comment.text) else - comments[#comments+1] = ('@*return* `%s` — %s'):format(table.concat(name, ','), doc.comment.text:gsub('[\r\n]+', ' ')) + comments[#comments+1] = ('@*return* `%s` — %s'):format(table.concat(name, ','), doc.comment.text) end else if #name == 0 then -- cgit v1.2.3