diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-11 20:53:12 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-11 20:53:12 +0800 |
commit | 9cb0fa1098e466efac78401ff76c422ac27bfab8 (patch) | |
tree | a6b31712d7cc32a59f1c7242cf44d62a0d401314 | |
parent | d2f5980d688a2c075113bfe89c5effecb195b530 (diff) | |
download | lua-language-server-9cb0fa1098e466efac78401ff76c422ac27bfab8.zip |
change to `Lua.semantic.enable`
-rw-r--r-- | script/config/config.lua | 2 | ||||
-rw-r--r-- | script/core/semantic-tokens.lua | 62 | ||||
-rw-r--r-- | script/provider/semantic-tokens.lua | 6 |
3 files changed, 18 insertions, 52 deletions
diff --git a/script/config/config.lua b/script/config/config.lua index 7d6c7c01..9f731dc9 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -196,7 +196,7 @@ local Template = { ['Lua.hover.viewNumber'] = Type.Boolean >> true, ['Lua.hover.previewFields'] = Type.Integer >> 20, ['Lua.hover.enumsLimit'] = Type.Integer >> 5, - ['Lua.color.mode'] = Type.String >> 'Semantic', + ['Lua.semantic.enable'] = Type.Boolean >> true, ['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 4f0ccea8..ad32e3fd 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -15,16 +15,7 @@ local Care = util.switch() : case 'setglobal' : call(function (source, options, results) local isLib = vm.isGlobalLibraryName(source[1]) - local isFunc = false - local value = source.value - - if value and value.type == 'function' then - isFunc = true - elseif source.parent.type == 'call' then - isFunc = true - elseif options.isEnhanced then - isFunc = infer.hasType(source, 'function') - end + local isFunc = infer.hasType(source, 'function') local type = isFunc and define.TokenTypes['function'] or define.TokenTypes.variable local modifier = isLib and define.TokenModifiers.defaultLibrary or define.TokenModifiers.static @@ -67,7 +58,7 @@ local Care = util.switch() return end end - if options.isEnhanced and infer.hasType(source, 'function') then + if infer.hasType(source, 'function') then results[#results+1] = { start = source.start, finish = source.finish, @@ -157,7 +148,7 @@ local Care = util.switch() return end -- 5. References to other functions - if options.isEnhanced and infer.hasType(loc, 'function') then + if infer.hasType(loc, 'function') then results[#results+1] = { start = source.start, finish = source.finish, @@ -167,40 +158,18 @@ local Care = util.switch() return end -- 6. Class declaration - if options.isEnhanced then - -- search all defs - for _, def in ipairs(vm.getDefs(source)) do - if def.bindDocs then - for _, doc in ipairs(def.bindDocs) do - if doc.type == "doc.class" and doc.bindSources then - for _, src in ipairs(doc.bindSources) do - if src == def then - results[#results+1] = { - start = source.start, - finish = source.finish, - type = define.TokenTypes.class, - } - return - end - end - end - end - end - end - else -- only search this local - if loc.bindDocs then - for i, doc in ipairs(loc.bindDocs) do - if doc.type == "doc.class" and doc.bindSources then - for _, src in ipairs(doc.bindSources) do - if src == loc then - results[#results+1] = { - start = source.start, - finish = source.finish, - type = define.TokenTypes.class, - } - return - end + if loc.bindDocs then + for i, doc in ipairs(loc.bindDocs) do + if doc.type == "doc.class" and doc.bindSources then + for _, src in ipairs(doc.bindSources) do + if src == loc then + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.class, + } + return end end end @@ -708,7 +677,7 @@ end ---@async return function (uri, start, finish) - if config.get(uri, 'Lua.color.mode') == 'Grammar' then + if not config.get(uri, 'Lua.semantic.enable') then return nil end local state = files.getState(uri) @@ -720,7 +689,6 @@ return function (uri, start, finish) uri = uri, state = state, text = files.getText(uri), - isEnhanced = config.get(uri, 'Lua.color.mode') == 'SemanticEnhanced', } local results = {} diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua index 89c396f0..2fa75064 100644 --- a/script/provider/semantic-tokens.lua +++ b/script/provider/semantic-tokens.lua @@ -49,18 +49,16 @@ local function refresh() end log.debug('Refresh semantic tokens.') proto.request('workspace/semanticTokens/refresh', json.null) - check() + --check() end config.watch(function (uri, key, value, oldValue) if key == '' then refresh() end - if key == 'Lua.color.mode' then - refresh() - end if key:find '^Lua.runtime' or key:find '^Lua.workspace' + or key:find '^Lua.semantic' or key:find '^files' then refresh() end |