From 85cf8a5843e3c2e5c3bd4e17cf32eb1c1ba8a05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 10 Jun 2021 20:25:16 +0800 Subject: fix --- .vscode/settings.json | 3 ++- script/core/command/removeSpace.lua | 3 ++- script/core/diagnostics/no-implicit-any.lua | 9 ++++----- script/core/folding.lua | 4 ++-- script/core/hint.lua | 21 +++++++++++---------- script/core/searcher.lua | 4 +++- script/core/semantic-tokens.lua | 3 ++- script/core/workspace-symbol.lua | 4 ++-- 8 files changed, 28 insertions(+), 23 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 31b3626c..4a3d7d12 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,7 +13,8 @@ "DBGWAIT", "tracy", "LOCALE", - "SHOWSOURCE" + "SHOWSOURCE", + "TRACE" ], "Lua.diagnostics.disable": [ "close-non-object", diff --git a/script/core/command/removeSpace.lua b/script/core/command/removeSpace.lua index ba1ee8eb..2df73a39 100644 --- a/script/core/command/removeSpace.lua +++ b/script/core/command/removeSpace.lua @@ -1,10 +1,11 @@ local files = require 'files' local searcher = require 'core.searcher' +local guide = require 'parser.guide' local proto = require 'proto' local lang = require 'language' local function isInString(ast, offset) - return searcher.eachSourceContain(ast.ast, offset, function (source) + return guide.eachSourceContain(ast.ast, offset, function (source) if source.type == 'string' then return true end diff --git a/script/core/diagnostics/no-implicit-any.lua b/script/core/diagnostics/no-implicit-any.lua index 23af570a..ccbb4917 100644 --- a/script/core/diagnostics/no-implicit-any.lua +++ b/script/core/diagnostics/no-implicit-any.lua @@ -1,8 +1,7 @@ local files = require 'files' -local searcher = require 'core.searcher' +local guide = require 'parser.guide' local lang = require 'language' -local define = require 'proto.define' -local vm = require 'vm' +local infer = require 'core.infer' return function (uri, callback) local ast = files.getAst(uri) @@ -10,7 +9,7 @@ return function (uri, callback) return end - searcher.eachSource(ast.ast, function (source) + guide.eachSource(ast.ast, function (source) if source.type ~= 'local' and source.type ~= 'setlocal' and source.type ~= 'setglobal' @@ -21,7 +20,7 @@ return function (uri, callback) and source.type ~= 'tableindex' then return end - if vm.getInferType(source, 0) == 'any' then + if infer.searchAndViewInfers(source) == 'any' then callback { start = source.start, finish = source.finish, diff --git a/script/core/folding.lua b/script/core/folding.lua index 1bbae944..38008be9 100644 --- a/script/core/folding.lua +++ b/script/core/folding.lua @@ -1,5 +1,5 @@ local files = require "files" -local searcher = require "core.searcher" +local guide = require "parser.guide" local util = require 'utility' local Care = { @@ -153,7 +153,7 @@ return function (uri) local regions = {} local status = {} - searcher.eachSource(ast.ast, function (source) + guide.eachSource(ast.ast, function (source) local tp = source.type if Care[tp] then Care[tp](source, text, regions) diff --git a/script/core/hint.lua b/script/core/hint.lua index 43b8726e..f4ccad44 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -1,7 +1,8 @@ local files = require 'files' -local searcher = require 'core.searcher' +local infer = require 'core.infer' local vm = require 'vm' local config = require 'config' +local guide = require 'parser.guide' local function typeHint(uri, edits, start, finish) local ast = files.getAst(uri) @@ -9,7 +10,7 @@ local function typeHint(uri, edits, start, finish) return end local mark = {} - searcher.eachSourceBetween(ast.ast, start, finish, function (source) + guide.eachSourceBetween(ast.ast, start, finish, function (source) if source.type ~= 'local' and source.type ~= 'setglobal' and source.type ~= 'tablefield' @@ -21,7 +22,7 @@ local function typeHint(uri, edits, start, finish) if source[1] == '_' then return end - if source.value and searcher.isLiteral(source.value) then + if source.value and guide.isLiteral(source.value) then return end if source.parent.type == 'funcargs' then @@ -33,9 +34,9 @@ local function typeHint(uri, edits, start, finish) return end end - local infer = vm.getInferType(source, 0) - if infer == 'any' - or infer == 'nil' then + local view = infer.searchAndViewInfers(source) + if view == 'any' + or view == 'nil' then return end local src = source @@ -52,7 +53,7 @@ local function typeHint(uri, edits, start, finish) end mark[src] = true edits[#edits+1] = { - newText = (':%s'):format(infer), + newText = (':%s'):format(view), start = src.finish, finish = src.finish, } @@ -84,7 +85,7 @@ local function hasLiteralArgInCall(call) return false end for _, arg in ipairs(call.args) do - if searcher.isLiteral(arg) then + if guide.isLiteral(arg) then return true end end @@ -100,7 +101,7 @@ local function paramName(uri, edits, start, finish) return end local mark = {} - searcher.eachSourceBetween(ast.ast, start, finish, function (source) + guide.eachSourceBetween(ast.ast, start, finish, function (source) if source.type ~= 'call' then return end @@ -130,7 +131,7 @@ local function paramName(uri, edits, start, finish) table.remove(args, 1) end for i, arg in ipairs(source.args) do - if not mark[arg] and searcher.isLiteral(arg) then + if not mark[arg] and guide.isLiteral(arg) then mark[arg] = true if args[i] and args[i] ~= '' then edits[#edits+1] = { diff --git a/script/core/searcher.lua b/script/core/searcher.lua index f6c34425..ec4d8b0e 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -246,7 +246,9 @@ function m.searchRefsByID(status, uri, expect, mode) cmark = {} mark[id] = cmark end - log.debug('search:', id, field) + if TRACE then + log.debug('search:', id, field) + end if field then if cmark[field] then return diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 5e9ee9b1..74b3942c 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -4,6 +4,7 @@ local await = require 'await' local define = require 'proto.define' local vm = require 'vm' local util = require 'utility' +local guide = require 'parser.guide' local Care = {} Care['setglobal'] = function (source, results) @@ -221,7 +222,7 @@ return function (uri, start, finish) local results = {} local count = 0 - searcher.eachSourceBetween(ast.ast, start, finish, function (source) + guide.eachSourceBetween(ast.ast, start, finish, function (source) local method = Care[source.type] if not method then return diff --git a/script/core/workspace-symbol.lua b/script/core/workspace-symbol.lua index 2df23a4d..6301cc39 100644 --- a/script/core/workspace-symbol.lua +++ b/script/core/workspace-symbol.lua @@ -1,5 +1,5 @@ local files = require 'files' -local searcher = require 'core.searcher' +local guide = require 'parser.guide' local matchKey = require 'core.matchkey' local define = require 'proto.define' local await = require 'await' @@ -52,7 +52,7 @@ local function searchFile(uri, key, results) return end - searcher.eachSource(ast.ast, function (source) + guide.eachSource(ast.ast, function (source) buildSource(uri, source, key, results) end) end -- cgit v1.2.3