diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-12-24 17:20:27 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-12-24 17:20:27 +0800 |
commit | 38a2f5ae4e7e5a5ba48289db6a2972e15d3d53cf (patch) | |
tree | 281d4acb7ab88d2751b71f8286d4a0b0c9f8bbf1 /script | |
parent | ef6c3fe05addbd299e4fc6e45cec94a83886c18f (diff) | |
download | lua-language-server-38a2f5ae4e7e5a5ba48289db6a2972e15d3d53cf.zip |
update
Diffstat (limited to 'script')
-rw-r--r-- | script/core/collector.lua | 4 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 110 | ||||
-rw-r--r-- | script/workspace/require-path.lua | 2 | ||||
-rw-r--r-- | script/workspace/scope.lua | 3 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 12 |
5 files changed, 6 insertions, 125 deletions
diff --git a/script/core/collector.lua b/script/core/collector.lua index 947f4059..5ccbcaee 100644 --- a/script/core/collector.lua +++ b/script/core/collector.lua @@ -70,9 +70,7 @@ function m.each(uri, name) ---@type scope local scp = scope.getFolder(uri) or scope.getLinkedScope(uri) - if not scp then - return DUMMY_FUNCTION - end + or scope.fallback local curi, value local function getNext() diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index d0bf5164..21f6ea0c 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1928,88 +1928,6 @@ local function tryComment(state, position, results) checkCommon(state, word, position, results) end -local function makeCache(uri, position, results) - local cache = workspace.getCache 'completion' - if not uri then - cache.results = nil - return - end - local text = files.getText(uri) - local state = files.getState(uri) - local word = lookBackward.findWord(text, guide.positionToOffset(state, position)) - if not word or #word < 2 then - cache.results = nil - return - end - cache.results = results - cache.position= position - cache.word = word:lower() - cache.length = #word - cache.uri = uri -end - -local function isValidCache(word, result) - if result.kind == define.CompletionItemKind.Text then - return false - end - local match = result.match or result.label - if matchKey(word, match) then - return true - end - if result.textEdit then - match = result.textEdit.newText:match '[%w_]+' - if match and matchKey(word, match) then - return true - end - end - return false -end - -local function getCache(uri, position) - local cache = workspace.getCache 'completion' - if not cache.results then - return nil - end - if cache.uri ~= uri then - return nil - end - local text = files.getText(uri) - local state = files.getState(uri) - local word = lookBackward.findWord(text, guide.positionToOffset(state, position)) - if not word then - return nil - end - if word:sub(1, #cache.word):lower() ~= cache.word then - return nil - end - - local ext = #word - cache.length - cache.length = #word - local results = cache.results - for i = #results, 1, -1 do - local result = results[i] - if isValidCache(word, result) then - if result.textEdit then - result.textEdit.finish = result.textEdit.finish + ext - end - else - results[i] = results[#results] - results[#results] = nil - end - end - - if results.enableCommon then - checkCommon(state, word, position, results) - end - - return cache.results -end - -local function clearCache() - local cache = workspace.getCache 'completion' - cache.results = nil -end - ---@async local function tryCompletions(state, position, triggerCharacter, results) local text = state.lua @@ -2039,56 +1957,30 @@ end ---@async local function completion(uri, position, triggerCharacter) - tracy.ZoneBeginN 'completion cache' - local results = getCache(uri, position) - tracy.ZoneEnd() - if results then - return results - end - await.delay() - tracy.ZoneBeginN 'completion #1' local state = files.getState(uri) if not state then return nil end - results = {} clearStack() - tracy.ZoneEnd() + local results = {} tracy.ZoneBeginN 'completion #2' tryCompletions(state, position, triggerCharacter, results) tracy.ZoneEnd() if #results == 0 then - clearCache() return nil end - tracy.ZoneBeginN 'completion #3' - makeCache(uri, position, results) - tracy.ZoneEnd() return results end ---@async local function resolve(id) local item = resolveStack(id) - local cache = workspace.getCache 'completion' - if item and cache.results then - for _, res in ipairs(cache.results) do - if res and res.id == id then - for k, v in pairs(item) do - res[k] = v - end - res.id = nil - break - end - end - end return item end return { completion = completion, resolve = resolve, - clearCache = clearCache, } diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index 04c8abf8..a6af2612 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -86,7 +86,7 @@ function m.findUrisByRequirePath(path) if type(path) ~= 'string' then return {} end - local separator = config.get 'Lua.completion.requireSeparator' + local separator = config.get(nil, 'Lua.completion.requireSeparator') local fspath = path:gsub('%' .. separator, '/') local vm = require 'vm' local cache = vm.getCache 'findUrisByRequirePath' diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua index 6abf30d5..fc71e60c 100644 --- a/script/workspace/scope.lua +++ b/script/workspace/scope.lua @@ -25,6 +25,9 @@ end ---@param uri uri ---@return boolean function mt:isChildUri(uri) + if not self.uri then + return true + end return uri:sub(1, #self.uri) == self.uri end diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index a2f99b3e..8e26b1df 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -348,18 +348,6 @@ function m.getRelativePath(uriOrPath) end end ---- 获取工作区等级的缓存 -function m.getCache(name) - if not m.cache[name] then - m.cache[name] = {} - end - return m.cache[name] -end - -function m.flushCache() - m.cache = {} -end - ---@param scp scope function m.reload(scp) if not m.inited then |