summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-01-11 21:01:17 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-01-11 21:01:17 +0800
commit12bc09de1e6c30c5c241a22640579268f51e07e4 (patch)
treefaaf9ef7d71b43583a74d72ef6cd56e87cdbc387
parent9cb0fa1098e466efac78401ff76c422ac27bfab8 (diff)
downloadlua-language-server-12bc09de1e6c30c5c241a22640579268f51e07e4.zip
add semantic configs
-rw-r--r--changelog.md8
-rw-r--r--script/config/config.lua3
-rw-r--r--script/core/semantic-tokens.lua139
3 files changed, 136 insertions, 14 deletions
diff --git a/changelog.md b/changelog.md
index e22ba0a3..4630d89c 100644
--- a/changelog.md
+++ b/changelog.md
@@ -2,9 +2,15 @@
## 2.5.7
* `NEW` supports multi-workspace in server side, for developers of language clients, please [read here](https://github.com/sumneko/lua-language-server/wiki/Multi-workspace-supports) to learn more.
-* `NEW` setting: `Lua.hint.arrayIndex`
+* `NEW` setting:
+ + `Lua.hint.arrayIndex`
+ + `Lua.semantic.enable`
+ + `Lua.semantic.variable`
+ + `Lua.semantic.annotation`
+ + `Lua.semantic.keyword`
* `CHG` diagnostic: smoother
* `CHG` completion: can be triggered in `LuaDoc` and strings
+* `CHG` settings `Lua.color.mode` removed
* `FIX` [#879](https://github.com/sumneko/lua-language-server/issues/879)
* `FIX` [#884](https://github.com/sumneko/lua-language-server/issues/884)
* `FIX` [#885](https://github.com/sumneko/lua-language-server/issues/885)
diff --git a/script/config/config.lua b/script/config/config.lua
index 9f731dc9..f72f5e57 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -197,6 +197,9 @@ local Template = {
['Lua.hover.previewFields'] = Type.Integer >> 20,
['Lua.hover.enumsLimit'] = Type.Integer >> 5,
['Lua.semantic.enable'] = Type.Boolean >> true,
+ ['Lua.semantic.variable'] = Type.Boolean >> true,
+ ['Lua.semantic.annotation'] = Type.Boolean >> true,
+ ['Lua.semantic.keyword'] = Type.Boolean >> false,
['Lua.hint.enable'] = Type.Boolean >> false,
['Lua.hint.paramType'] = Type.Boolean >> true,
['Lua.hint.setType'] = Type.Boolean >> false,
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua
index ad32e3fd..70d2cf14 100644
--- a/script/core/semantic-tokens.lua
+++ b/script/core/semantic-tokens.lua
@@ -14,6 +14,9 @@ local Care = util.switch()
: case 'getglobal'
: case 'setglobal'
: call(function (source, options, results)
+ if not options.variable then
+ return
+ end
local isLib = vm.isGlobalLibraryName(source[1])
local isFunc = infer.hasType(source, 'function')
@@ -30,6 +33,9 @@ local Care = util.switch()
: case 'getmethod'
: case 'setmethod'
: call(function (source, options, results)
+ if not options.variable then
+ return
+ end
local method = source.method
if method and method.type == 'method' then
results[#results+1] = {
@@ -42,6 +48,9 @@ local Care = util.switch()
end)
: case 'field'
: call(function (source, options, results)
+ if not options.variable then
+ return
+ end
local modifiers = 0
if source.parent and source.parent.type == 'tablefield' then
modifiers = define.TokenModifiers.declaration
@@ -87,22 +96,27 @@ local Care = util.switch()
: case 'getlocal'
: case 'setlocal'
: call(function (source, options, results)
- if source.locPos then
- results[#results+1] = {
- start = source.locPos,
- finish = source.locPos + #'local',
- type = define.TokenTypes.keyword,
- modifieres = define.TokenModifiers.declaration,
- }
- end
- if source.attrs then
- for _, attr in ipairs(source.attrs) do
+ if options.keyword then
+ if source.locPos then
results[#results+1] = {
- start = attr.start,
- finish = attr.finish,
- type = define.TokenTypes.typeParameter,
+ start = source.locPos,
+ finish = source.locPos + #'local',
+ type = define.TokenTypes.keyword,
+ modifieres = define.TokenModifiers.declaration,
}
end
+ if source.attrs then
+ for _, attr in ipairs(source.attrs) do
+ results[#results+1] = {
+ start = attr.start,
+ finish = attr.finish,
+ type = define.TokenTypes.typeParameter,
+ }
+ end
+ end
+ end
+ if not options.variable then
+ return
end
local loc = source.node or source
-- 1. 值为函数的局部变量 | Local variable whose value is a function
@@ -221,6 +235,9 @@ local Care = util.switch()
: case 'while'
: case 'repeat'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
local keyword = source.keyword
if keyword then
for i = 1, #keyword, 2 do
@@ -234,6 +251,9 @@ local Care = util.switch()
end)
: case 'if'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
local offset = guide.positionToOffset(options.state, source.finish)
if options.text:sub(offset - 2, offset) == 'end' then
results[#results+1] = {
@@ -245,6 +265,9 @@ local Care = util.switch()
end)
: case 'return'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.start + #'return',
@@ -253,6 +276,9 @@ local Care = util.switch()
end)
: case 'break'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.start + #'break',
@@ -261,6 +287,9 @@ local Care = util.switch()
end)
: case 'goto'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
results[#results+1] = {
start = source.keyStart,
finish = source.keyStart + #'goto',
@@ -274,6 +303,9 @@ local Care = util.switch()
end)
: case 'label'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -284,6 +316,9 @@ local Care = util.switch()
: case 'binary'
: case 'unary'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
results[#results+1] = {
start = source.op.start,
finish = source.op.finish,
@@ -293,6 +328,9 @@ local Care = util.switch()
: case 'boolean'
: case 'nil'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -302,6 +340,9 @@ local Care = util.switch()
end)
: case 'string'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -327,6 +368,9 @@ local Care = util.switch()
end)
: case 'integer'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -336,6 +380,9 @@ local Care = util.switch()
end)
: case 'number'
: call(function (source, options, results)
+ if not options.keyword then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -344,6 +391,9 @@ local Care = util.switch()
end)
: case 'doc.class.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -353,6 +403,9 @@ local Care = util.switch()
end)
: case 'doc.extends.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -361,6 +414,9 @@ local Care = util.switch()
end)
: case 'doc.type.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
if source.typeGeneric then
results[#results+1] = {
start = source.start,
@@ -378,6 +434,9 @@ local Care = util.switch()
end)
: case 'doc.alias.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -386,6 +445,9 @@ local Care = util.switch()
end)
: case 'doc.param.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -394,6 +456,9 @@ local Care = util.switch()
end)
: case 'doc.field'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
if source.visible then
results[#results+1] = {
start = source.start,
@@ -404,6 +469,9 @@ local Care = util.switch()
end)
: case 'doc.field.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -413,6 +481,9 @@ local Care = util.switch()
end)
: case 'doc.return.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -421,6 +492,9 @@ local Care = util.switch()
end)
: case 'doc.generic.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -430,6 +504,9 @@ local Care = util.switch()
end)
: case 'doc.type.enum'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -439,6 +516,9 @@ local Care = util.switch()
end)
: case 'doc.resume'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -454,6 +534,9 @@ local Care = util.switch()
end)
: case 'doc.type.function'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.start + #'fun',
@@ -470,6 +553,9 @@ local Care = util.switch()
end)
: case 'doc.type.table'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.start + #'table',
@@ -478,6 +564,9 @@ local Care = util.switch()
end)
: case 'doc.type.arg.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -487,6 +576,9 @@ local Care = util.switch()
end)
: case 'doc.version.unit'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -495,6 +587,9 @@ local Care = util.switch()
end)
: case 'doc.see.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -503,6 +598,9 @@ local Care = util.switch()
end)
: case 'doc.see.field'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -511,6 +609,9 @@ local Care = util.switch()
end)
: case 'doc.diagnostic'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.start + #source.mode,
@@ -519,6 +620,9 @@ local Care = util.switch()
end)
: case 'doc.diagnostic.name'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -528,6 +632,9 @@ local Care = util.switch()
end)
: case 'doc.module'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -537,6 +644,9 @@ local Care = util.switch()
end)
: case 'doc.tailcomment'
: call(function (source, options, results)
+ if not options.annotation then
+ return
+ end
results[#results+1] = {
start = source.start,
finish = source.finish,
@@ -689,6 +799,9 @@ return function (uri, start, finish)
uri = uri,
state = state,
text = files.getText(uri),
+ variable = config.get(uri, 'Lua.semantic.variable'),
+ annotation = config.get(uri, 'Lua.semantic.annotation'),
+ keyword = config.get(uri, 'Lua.semantic.keyword'),
}
local results = {}