diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-09 19:33:28 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-09 19:33:28 +0800 |
commit | bc92c4dcefc0c87420c7d4b239c1eb4b9d14588c (patch) | |
tree | 80b442f8a0c82faf4d4af9a8484bb6cfca8c94ec /script | |
parent | f8f9b68d3e89e602bcfe80fa18b2f5cb0846e846 (diff) | |
download | lua-language-server-bc92c4dcefc0c87420c7d4b239c1eb4b9d14588c.zip |
add `doc.type.code`
Diffstat (limited to 'script')
-rw-r--r-- | script/core/semantic-tokens.lua | 9 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 45 | ||||
-rw-r--r-- | script/vm/compiler.lua | 1 | ||||
-rw-r--r-- | script/vm/infer.lua | 4 |
4 files changed, 49 insertions, 10 deletions
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index b16f55fd..c892aaac 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -675,6 +675,15 @@ local Care = util.switch() type = define.TokenTypes.variable, } end) + : case 'doc.type.code' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.string, + modifieres = define.TokenModifiers.abstract, + } + end) local function buildTokens(uri, results) local tokens = {} diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index d8e31950..99ef8781 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -12,11 +12,13 @@ local Parser = re.compile([[ Main <- (Token / Sp)* Sp <- %s+ X16 <- [a-fA-F0-9] -Token <- Integer / Name / String / Symbol +Token <- Integer / Name / String / Code / Symbol Name <- ({} {%name} {}) -> Name Integer <- ({} {[0-9]+} !'.' {}) -> Integer +Code <- ({} '`' { (!'`' .)*} '`' {}) + -> Code String <- ({} StringDef {}) -> String StringDef <- {'"'} @@ -48,7 +50,7 @@ EChar <- 'a' -> ea / ([0-9] [0-9]? [0-9]?) -> Char10 / ('u{' {X16*} '}') -> CharUtf8 Symbol <- ({} { - [:|,<>()?+#`{}] + [:|,<>()?+#{}] / '[]' / '...' / '[' @@ -114,6 +116,13 @@ Symbol <- ({} { TokenFinishs[Ci] = finish - 1 TokenContents[Ci] = math.tointeger(content) end, + Code = function (start, content, finish) + Ci = Ci + 1 + TokenTypes[Ci] = 'code' + TokenStarts[Ci] = start + TokenFinishs[Ci] = finish - 1 + TokenContents[Ci] = content + end, Symbol = function (start, content, finish) Ci = Ci + 1 TokenTypes[Ci] = 'symbol' @@ -534,6 +543,22 @@ local function parseString(parent) return str end +local function parseCode(parent) + local tp, content = peekToken() + if not tp or tp ~= 'code' then + return nil + end + nextToken() + local code = { + type = 'doc.type.code', + start = getStart(), + finish = getFinish(), + parent = parent, + [1] = content, + } + return code +end + local function parseInteger(parent) local tp, content = peekToken() if not tp or tp ~= 'integer' then @@ -584,23 +609,16 @@ function parseTypeUnit(parent) local result = parseFunction(parent) or parseTable(parent) or parseString(parent) + or parseCode(parent) or parseInteger(parent) or parseBoolean(parent) or parseDots('doc.type.name', parent) or parseParen(parent) if not result then - local literal = checkToken('symbol', '`', 1) - if literal then - nextToken() - end result = parseName('doc.type.name', parent) if not result then return nil end - if literal then - result.literal = true - nextSymbolOrError '`' - end end while true do local newResult = parseTypeUnitSign(parent, result) @@ -1418,6 +1436,13 @@ local function bindGeneric(binded) src.type = 'doc.generic.name' end end) + guide.eachSourceType(doc, 'doc.type.code', function (src) + local name = src[1] + if generics[name] then + src.type = 'doc.generic.name' + src.literal = true + end + end) end end end diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 1c3be7c8..9b871553 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1290,6 +1290,7 @@ local compilerSwitch = util.switch() : case 'doc.type.integer' : case 'doc.type.string' : case 'doc.type.boolean' + : case 'doc.type.code' : call(function (source) vm.setNode(source, source) end) diff --git a/script/vm/infer.lua b/script/vm/infer.lua index ef8c6f29..9db69b4d 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -135,6 +135,10 @@ local viewNodeSwitch = util.switch() : call(function (source, infer) return ('%q'):format(source[1]) end) + : case 'doc.type.code' + : call(function (source, infer) + return ('`%s`'):format(source[1]) + end) : case 'doc.type.function' : call(function (source, infer, uri) infer._hasDocFunction = true |