summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-06 23:34:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-06 23:34:54 +0800
commit79cc877095745be377b9dd189ee5e38cf35a3c5e (patch)
tree9e5f0e07741c8c5022d08672fef2ba137e352703 /script
parent27dcfa8d1463936d0b2514cd82eebe1910ab3bb7 (diff)
downloadlua-language-server-79cc877095745be377b9dd189ee5e38cf35a3c5e.zip
semantic and completion description
Diffstat (limited to 'script')
-rw-r--r--script/config/template.lua4
-rw-r--r--script/core/completion/completion.lua21
-rw-r--r--script/core/diagnostics/unknown-operator.lua7
-rw-r--r--script/core/semantic-tokens.lua8
-rw-r--r--script/utility.lua8
-rw-r--r--script/vm/operator.lua9
6 files changed, 46 insertions, 11 deletions
diff --git a/script/config/template.lua b/script/config/template.lua
index 4a58c17b..c9ad2f4c 100644
--- a/script/config/template.lua
+++ b/script/config/template.lua
@@ -52,6 +52,10 @@ local function register(name, default, checker, loader, caller)
}
end
+---@class config.template
+---@field [string] config.template
+---@operator shl: config.template
+---@operator shr: config.template
local Type = setmetatable({}, { __index = function (_, name)
local unit = {}
for k, v in pairs(units[name]) do
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index ae1d7f9e..bc3760d9 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1566,6 +1566,7 @@ local function tryluaDocCate(word, results)
'async',
'nodiscard',
'cast',
+ 'operator',
} do
if matchKey(word, docType) then
results[#results+1] = {
@@ -1740,16 +1741,18 @@ local function tryluaDocBySource(state, position, source, results)
for _, name in ipairs(vm.UNARY_OP) do
if matchKey(source[1], name) then
results[#results+1] = {
- label = name,
- kind = define.CompletionItemKind.Operator,
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ description = ('```lua\n%s\n```'):format(vm.UNARY_MAP[name]),
}
end
end
for _, name in ipairs(vm.BINARY_OP) do
if matchKey(source[1], name) then
results[#results+1] = {
- label = name,
- kind = define.CompletionItemKind.Operator,
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ description = ('```lua\n%s\n```'):format(vm.BINARY_MAP[name]),
}
end
end
@@ -1866,14 +1869,16 @@ local function tryluaDocByErr(state, position, err, docState, results)
elseif err.type == 'LUADOC_MISS_OPERATOR_NAME' then
for _, name in ipairs(vm.UNARY_OP) do
results[#results+1] = {
- label = name,
- kind = define.CompletionItemKind.Operator,
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ description = ('```lua\n%s\n```'):format(vm.UNARY_MAP[name]),
}
end
for _, name in ipairs(vm.BINARY_OP) do
results[#results+1] = {
- label = name,
- kind = define.CompletionItemKind.Operator,
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ description = ('```lua\n%s\n```'):format(vm.BINARY_MAP[name]),
}
end
end
diff --git a/script/core/diagnostics/unknown-operator.lua b/script/core/diagnostics/unknown-operator.lua
index 29a86eaa..5e8177c3 100644
--- a/script/core/diagnostics/unknown-operator.lua
+++ b/script/core/diagnostics/unknown-operator.lua
@@ -20,12 +20,13 @@ return function (uri, callback)
if doc.type == 'doc.operator' then
local op = doc.op
if op then
- if not util.arrayHas(vm.UNARY_OP, op[1])
- and not util.arrayHas(vm.BINARY_OP, op[1]) then
+ local opName = op[1]
+ if not vm.BINARY_MAP[opName]
+ and not vm.UNARY_MAP[opName] then
callback {
start = doc.op.start,
finish = doc.op.finish,
- message = lang.script('DIAG_UNKNOWN_OPERATOR', op[1])
+ message = lang.script('DIAG_UNKNOWN_OPERATOR', opName)
}
end
end
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua
index 5596245b..5f9a137b 100644
--- a/script/core/semantic-tokens.lua
+++ b/script/core/semantic-tokens.lua
@@ -692,6 +692,14 @@ local Care = util.switch()
modifieres = define.TokenModifiers.abstract,
}
end)
+ : case 'doc.operator.name'
+ : call(function (source, options, results)
+ results[#results+1] = {
+ start = source.start,
+ finish = source.finish,
+ type = define.TokenTypes.operator,
+ }
+ end)
local function buildTokens(uri, results)
local tokens = {}
diff --git a/script/utility.lua b/script/utility.lua
index e7aabaca..8e6c6a88 100644
--- a/script/utility.lua
+++ b/script/utility.lua
@@ -524,6 +524,14 @@ function m.revertTable(t)
return t
end
+function m.revertMap(t)
+ local nt = {}
+ for k, v in pairs(t) do
+ nt[v] = k
+ end
+ return nt
+end
+
function m.randomSortTable(t, max)
local len = #t
if len <= 1 then
diff --git a/script/vm/operator.lua b/script/vm/operator.lua
index 9a8e255d..35910f94 100644
--- a/script/vm/operator.lua
+++ b/script/vm/operator.lua
@@ -25,6 +25,12 @@ vm.BINARY_OP = {
'concat',
}
+local unaryMap = {
+ ['-'] = 'unm',
+ ['~'] = 'bnot',
+ ['#'] = 'len',
+}
+
local binaryMap = {
['+'] = 'add',
['-'] = 'sub',
@@ -41,6 +47,9 @@ local binaryMap = {
['..'] = 'concat',
}
+vm.UNARY_MAP = util.revertMap(unaryMap)
+vm.BINARY_MAP = util.revertMap(binaryMap)
+
---@param operators parser.object[]
---@param op string
---@param value? parser.object