Skip to content

Commit 9cb0fa1

Browse files
committed
change to Lua.semantic.enable
1 parent d2f5980 commit 9cb0fa1

File tree

3 files changed

+18
-52
lines changed

3 files changed

+18
-52
lines changed

script/config/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ local Template = {
196196
['Lua.hover.viewNumber'] = Type.Boolean >> true,
197197
['Lua.hover.previewFields'] = Type.Integer >> 20,
198198
['Lua.hover.enumsLimit'] = Type.Integer >> 5,
199-
['Lua.color.mode'] = Type.String >> 'Semantic',
199+
['Lua.semantic.enable'] = Type.Boolean >> true,
200200
['Lua.hint.enable'] = Type.Boolean >> false,
201201
['Lua.hint.paramType'] = Type.Boolean >> true,
202202
['Lua.hint.setType'] = Type.Boolean >> false,

script/core/semantic-tokens.lua

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,7 @@ local Care = util.switch()
1515
: case 'setglobal'
1616
: call(function (source, options, results)
1717
local isLib = vm.isGlobalLibraryName(source[1])
18-
local isFunc = false
19-
local value = source.value
20-
21-
if value and value.type == 'function' then
22-
isFunc = true
23-
elseif source.parent.type == 'call' then
24-
isFunc = true
25-
elseif options.isEnhanced then
26-
isFunc = infer.hasType(source, 'function')
27-
end
18+
local isFunc = infer.hasType(source, 'function')
2819

2920
local type = isFunc and define.TokenTypes['function'] or define.TokenTypes.variable
3021
local modifier = isLib and define.TokenModifiers.defaultLibrary or define.TokenModifiers.static
@@ -67,7 +58,7 @@ local Care = util.switch()
6758
return
6859
end
6960
end
70-
if options.isEnhanced and infer.hasType(source, 'function') then
61+
if infer.hasType(source, 'function') then
7162
results[#results+1] = {
7263
start = source.start,
7364
finish = source.finish,
@@ -157,7 +148,7 @@ local Care = util.switch()
157148
return
158149
end
159150
-- 5. References to other functions
160-
if options.isEnhanced and infer.hasType(loc, 'function') then
151+
if infer.hasType(loc, 'function') then
161152
results[#results+1] = {
162153
start = source.start,
163154
finish = source.finish,
@@ -167,40 +158,18 @@ local Care = util.switch()
167158
return
168159
end
169160
-- 6. Class declaration
170-
if options.isEnhanced then
171-
-- search all defs
172-
for _, def in ipairs(vm.getDefs(source)) do
173-
if def.bindDocs then
174-
for _, doc in ipairs(def.bindDocs) do
175-
if doc.type == "doc.class" and doc.bindSources then
176-
for _, src in ipairs(doc.bindSources) do
177-
if src == def then
178-
results[#results+1] = {
179-
start = source.start,
180-
finish = source.finish,
181-
type = define.TokenTypes.class,
182-
}
183-
return
184-
end
185-
end
186-
end
187-
end
188-
end
189-
end
190-
else
191161
-- only search this local
192-
if loc.bindDocs then
193-
for i, doc in ipairs(loc.bindDocs) do
194-
if doc.type == "doc.class" and doc.bindSources then
195-
for _, src in ipairs(doc.bindSources) do
196-
if src == loc then
197-
results[#results+1] = {
198-
start = source.start,
199-
finish = source.finish,
200-
type = define.TokenTypes.class,
201-
}
202-
return
203-
end
162+
if loc.bindDocs then
163+
for i, doc in ipairs(loc.bindDocs) do
164+
if doc.type == "doc.class" and doc.bindSources then
165+
for _, src in ipairs(doc.bindSources) do
166+
if src == loc then
167+
results[#results+1] = {
168+
start = source.start,
169+
finish = source.finish,
170+
type = define.TokenTypes.class,
171+
}
172+
return
204173
end
205174
end
206175
end
@@ -708,7 +677,7 @@ end
708677

709678
---@async
710679
return function (uri, start, finish)
711-
if config.get(uri, 'Lua.color.mode') == 'Grammar' then
680+
if not config.get(uri, 'Lua.semantic.enable') then
712681
return nil
713682
end
714683
local state = files.getState(uri)
@@ -720,7 +689,6 @@ return function (uri, start, finish)
720689
uri = uri,
721690
state = state,
722691
text = files.getText(uri),
723-
isEnhanced = config.get(uri, 'Lua.color.mode') == 'SemanticEnhanced',
724692
}
725693

726694
local results = {}

script/provider/semantic-tokens.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,16 @@ local function refresh()
4949
end
5050
log.debug('Refresh semantic tokens.')
5151
proto.request('workspace/semanticTokens/refresh', json.null)
52-
check()
52+
--check()
5353
end
5454

5555
config.watch(function (uri, key, value, oldValue)
5656
if key == '' then
5757
refresh()
5858
end
59-
if key == 'Lua.color.mode' then
60-
refresh()
61-
end
6259
if key:find '^Lua.runtime'
6360
or key:find '^Lua.workspace'
61+
or key:find '^Lua.semantic'
6462
or key:find '^files' then
6563
refresh()
6664
end

0 commit comments

Comments
 (0)