diff options
61 files changed, 107 insertions, 93 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua index 9ed000e9..3fd58c81 100644 --- a/script/core/code-action.lua +++ b/script/core/code-action.lua @@ -7,7 +7,7 @@ local guide = require "parser.guide" local function checkDisableByLuaDocExits(uri, row, mode, code) local lines = files.getLines(uri) - local ast = files.getAst(uri) + local ast = files.getState(uri) local text = files.getOriginText(uri) local line = lines[row] if ast.ast.docs and line then @@ -43,7 +43,7 @@ end local function checkDisableByLuaDocInsert(uri, row, mode, code) local lines = files.getLines(uri) - local ast = files.getAst(uri) + local ast = files.getState(uri) local text = files.getOriginText(uri) -- 先看看上一行是不是已经有了 -- 没有的话就插入一行 @@ -134,7 +134,7 @@ local function changeVersion(uri, version, results) end local function solveUndefinedGlobal(uri, diag, results) - local ast = files.getAst(uri) + local ast = files.getState(uri) local offset = files.offsetOfWord(uri, diag.range.start) guide.eachSourceContain(ast.ast, offset, function (source) if source.type ~= 'getglobal' then @@ -153,7 +153,7 @@ local function solveUndefinedGlobal(uri, diag, results) end local function solveLowercaseGlobal(uri, diag, results) - local ast = files.getAst(uri) + local ast = files.getState(uri) local offset = files.offsetOfWord(uri, diag.range.start) guide.eachSourceContain(ast.ast, offset, function (source) if source.type ~= 'setglobal' then @@ -166,7 +166,7 @@ local function solveLowercaseGlobal(uri, diag, results) end local function findSyntax(uri, diag) - local ast = files.getAst(uri) + local ast = files.getState(uri) for _, err in ipairs(ast.errs) do if err.type:lower():gsub('_', '-') == diag.code then local range = files.range(uri, err.start, err.finish) @@ -350,7 +350,7 @@ local function checkQuickFix(results, uri, start, diagnostics) end local function checkSwapParams(results, uri, start, finish) - local ast = files.getAst(uri) + local ast = files.getState(uri) local text = files.getText(uri) if not ast then return @@ -539,7 +539,7 @@ local function checkJsonToLua(results, uri, start, finish) end return function (uri, start, finish, diagnostics) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return nil end diff --git a/script/core/command/removeSpace.lua b/script/core/command/removeSpace.lua index 2df73a39..6fb9669f 100644 --- a/script/core/command/removeSpace.lua +++ b/script/core/command/removeSpace.lua @@ -16,7 +16,7 @@ return function (data) local uri = data.uri local lines = files.getLines(uri) local text = files.getText(uri) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not lines then return end diff --git a/script/core/command/solve.lua b/script/core/command/solve.lua index dc23e7af..348c2646 100644 --- a/script/core/command/solve.lua +++ b/script/core/command/solve.lua @@ -28,7 +28,7 @@ local literalMap = { return function (data) local uri = data.uri local text = files.getText(uri) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/completion.lua b/script/core/completion.lua index acaaa276..9f35c4ac 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -322,7 +322,7 @@ local function checkModule(ast, word, offset, results) and not config.config.diagnostics.globals[stemName] and stemName:match '^[%a_][%w_]*$' and matchKey(word, stemName) then - local targetAst = files.getAst(uri) + local targetAst = files.getState(uri) if not targetAst then goto CONTINUE end @@ -1925,7 +1925,7 @@ local function completion(uri, offset, triggerCharacter) return results end tracy.ZoneBeginN 'completion #1' - local ast = files.getAst(uri) + local ast = files.getState(uri) local text = files.getText(uri) results = {} clearStack() diff --git a/script/core/definition.lua b/script/core/definition.lua index 3ced05a2..27a9e553 100644 --- a/script/core/definition.lua +++ b/script/core/definition.lua @@ -102,7 +102,7 @@ local function convertIndex(source) end return function (uri, offset) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return nil end diff --git a/script/core/diagnostics/ambiguity-1.lua b/script/core/diagnostics/ambiguity-1.lua index 37815fb5..bae39a03 100644 --- a/script/core/diagnostics/ambiguity-1.lua +++ b/script/core/diagnostics/ambiguity-1.lua @@ -25,7 +25,7 @@ local literalMap = { } return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/circle-doc-class.lua b/script/core/diagnostics/circle-doc-class.lua index d2e26378..ae6d4d3b 100644 --- a/script/core/diagnostics/circle-doc-class.lua +++ b/script/core/diagnostics/circle-doc-class.lua @@ -5,7 +5,7 @@ local vm = require 'vm' local guide = require 'parser.guide' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/close-non-object.lua b/script/core/diagnostics/close-non-object.lua index 7828efe9..afd259d0 100644 --- a/script/core/diagnostics/close-non-object.lua +++ b/script/core/diagnostics/close-non-object.lua @@ -3,7 +3,7 @@ local guide = require 'parser.guide' local lang = require 'language' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/code-after-break.lua b/script/core/diagnostics/code-after-break.lua index f300a61a..21f7e83a 100644 --- a/script/core/diagnostics/code-after-break.lua +++ b/script/core/diagnostics/code-after-break.lua @@ -4,7 +4,7 @@ local lang = require 'language' local define = require 'proto.define' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/count-down-loop.lua b/script/core/diagnostics/count-down-loop.lua index ee245781..a16811ab 100644 --- a/script/core/diagnostics/count-down-loop.lua +++ b/script/core/diagnostics/count-down-loop.lua @@ -3,7 +3,7 @@ local guide = require "parser.guide" local lang = require 'language' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) local text = files.getText(uri) if not state or not text then return diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua index a6f8a47e..c60084fb 100644 --- a/script/core/diagnostics/deprecated.lua +++ b/script/core/diagnostics/deprecated.lua @@ -7,7 +7,7 @@ local define = require 'proto.define' local await = require 'await' return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/doc-field-no-class.lua b/script/core/diagnostics/doc-field-no-class.lua index f27bbb32..97603c0b 100644 --- a/script/core/diagnostics/doc-field-no-class.lua +++ b/script/core/diagnostics/doc-field-no-class.lua @@ -2,7 +2,7 @@ local files = require 'files' local lang = require 'language' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/duplicate-doc-class.lua b/script/core/diagnostics/duplicate-doc-class.lua index daecb836..20eedb5e 100644 --- a/script/core/diagnostics/duplicate-doc-class.lua +++ b/script/core/diagnostics/duplicate-doc-class.lua @@ -5,7 +5,7 @@ local vm = require 'vm' local guide = require 'parser.guide' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/duplicate-doc-field.lua b/script/core/diagnostics/duplicate-doc-field.lua index b621fd9e..1ee27ff2 100644 --- a/script/core/diagnostics/duplicate-doc-field.lua +++ b/script/core/diagnostics/duplicate-doc-field.lua @@ -2,7 +2,7 @@ local files = require 'files' local lang = require 'language' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/duplicate-doc-param.lua b/script/core/diagnostics/duplicate-doc-param.lua index 676a6fb4..b54c1978 100644 --- a/script/core/diagnostics/duplicate-doc-param.lua +++ b/script/core/diagnostics/duplicate-doc-param.lua @@ -2,7 +2,7 @@ local files = require 'files' local lang = require 'language' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/duplicate-index.lua b/script/core/diagnostics/duplicate-index.lua index d1ba9261..91a35212 100644 --- a/script/core/diagnostics/duplicate-index.lua +++ b/script/core/diagnostics/duplicate-index.lua @@ -5,7 +5,7 @@ local define = require 'proto.define' local vm = require 'vm' return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/duplicate-set-field.lua b/script/core/diagnostics/duplicate-set-field.lua index e1883fe5..492793b1 100644 --- a/script/core/diagnostics/duplicate-set-field.lua +++ b/script/core/diagnostics/duplicate-set-field.lua @@ -5,7 +5,7 @@ local define = require 'proto.define' local guide = require "parser.guide" return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/empty-block.lua b/script/core/diagnostics/empty-block.lua index 2024f4e3..fc205d7e 100644 --- a/script/core/diagnostics/empty-block.lua +++ b/script/core/diagnostics/empty-block.lua @@ -6,7 +6,7 @@ local define = require 'proto.define' -- 检查空代码块 -- 但是排除忙等待(repeat/while) return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/global-in-nil-env.lua b/script/core/diagnostics/global-in-nil-env.lua index 9a0d4f35..d95963e4 100644 --- a/script/core/diagnostics/global-in-nil-env.lua +++ b/script/core/diagnostics/global-in-nil-env.lua @@ -8,7 +8,7 @@ local function mayRun(path) end return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index 1d1ab9af..e068238e 100644 --- a/script/core/diagnostics/init.lua +++ b/script/core/diagnostics/init.lua @@ -62,7 +62,7 @@ local function check(uri, name, results) end return function (uri, response) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return nil end diff --git a/script/core/diagnostics/lowercase-global.lua b/script/core/diagnostics/lowercase-global.lua index 8c7ae793..cba33459 100644 --- a/script/core/diagnostics/lowercase-global.lua +++ b/script/core/diagnostics/lowercase-global.lua @@ -18,7 +18,7 @@ end -- 不允许定义首字母小写的全局变量(很可能是拼错或者漏删) return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/newfield-call.lua b/script/core/diagnostics/newfield-call.lua index 75681cbc..2cbc13ee 100644 --- a/script/core/diagnostics/newfield-call.lua +++ b/script/core/diagnostics/newfield-call.lua @@ -3,7 +3,7 @@ local guide = require 'parser.guide' local lang = require 'language' return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua index 159a60c9..71dc33e2 100644 --- a/script/core/diagnostics/newline-call.lua +++ b/script/core/diagnostics/newline-call.lua @@ -3,7 +3,7 @@ local guide = require 'parser.guide' local lang = require 'language' return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) local lines = files.getLines(uri) local text = files.getText(uri) if not ast or not lines then diff --git a/script/core/diagnostics/no-implicit-any.lua b/script/core/diagnostics/no-implicit-any.lua index ccbb4917..6ff17c81 100644 --- a/script/core/diagnostics/no-implicit-any.lua +++ b/script/core/diagnostics/no-implicit-any.lua @@ -4,7 +4,7 @@ local lang = require 'language' local infer = require 'core.infer' return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/redefined-local.lua b/script/core/diagnostics/redefined-local.lua index 48093417..503347d0 100644 --- a/script/core/diagnostics/redefined-local.lua +++ b/script/core/diagnostics/redefined-local.lua @@ -3,7 +3,7 @@ local guide = require 'parser.guide' local lang = require 'language' return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/redundant-parameter.lua b/script/core/diagnostics/redundant-parameter.lua index eca7fc91..a2e60b71 100644 --- a/script/core/diagnostics/redundant-parameter.lua +++ b/script/core/diagnostics/redundant-parameter.lua @@ -67,7 +67,7 @@ local function getFuncArgs(func) end return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/redundant-value.lua b/script/core/diagnostics/redundant-value.lua index be483448..d6cd97a7 100644 --- a/script/core/diagnostics/redundant-value.lua +++ b/script/core/diagnostics/redundant-value.lua @@ -3,7 +3,7 @@ local define = require 'proto.define' local lang = require 'language' return function (uri, callback, code) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/trailing-space.lua b/script/core/diagnostics/trailing-space.lua index e54a6e60..824eb83f 100644 --- a/script/core/diagnostics/trailing-space.lua +++ b/script/core/diagnostics/trailing-space.lua @@ -13,7 +13,7 @@ local function isInString(ast, offset) end return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/unbalanced-assignments.lua b/script/core/diagnostics/unbalanced-assignments.lua index 35aebb45..df71f0c9 100644 --- a/script/core/diagnostics/unbalanced-assignments.lua +++ b/script/core/diagnostics/unbalanced-assignments.lua @@ -4,7 +4,7 @@ local lang = require 'language' local guide = require 'parser.guide' return function (uri, callback, code) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/undefined-doc-class.lua b/script/core/diagnostics/undefined-doc-class.lua index d79f7ea4..e7133ab9 100644 --- a/script/core/diagnostics/undefined-doc-class.lua +++ b/script/core/diagnostics/undefined-doc-class.lua @@ -5,7 +5,7 @@ local define = require 'proto.define' local vm = require 'vm' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/undefined-doc-name.lua b/script/core/diagnostics/undefined-doc-name.lua index 871f16e1..c7318fcf 100644 --- a/script/core/diagnostics/undefined-doc-name.lua +++ b/script/core/diagnostics/undefined-doc-name.lua @@ -5,7 +5,7 @@ local define = require 'proto.define' local vm = require 'vm' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/undefined-doc-param.lua b/script/core/diagnostics/undefined-doc-param.lua index 4a97947d..6140b4f0 100644 --- a/script/core/diagnostics/undefined-doc-param.lua +++ b/script/core/diagnostics/undefined-doc-param.lua @@ -17,7 +17,7 @@ local function hasParamName(func, name) end return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/undefined-env-child.lua b/script/core/diagnostics/undefined-env-child.lua index ea9d1c4c..39c8de27 100644 --- a/script/core/diagnostics/undefined-env-child.lua +++ b/script/core/diagnostics/undefined-env-child.lua @@ -5,7 +5,7 @@ local lang = require 'language' local vm = require "vm.vm" return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua index 2d357d5b..9d1f696c 100644 --- a/script/core/diagnostics/undefined-field.lua +++ b/script/core/diagnostics/undefined-field.lua @@ -13,7 +13,7 @@ local SkipCheckClass = { } return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua index 825b14f1..549a1922 100644 --- a/script/core/diagnostics/undefined-global.lua +++ b/script/core/diagnostics/undefined-global.lua @@ -12,7 +12,7 @@ local requireLike = { } return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/unknown-diag-code.lua b/script/core/diagnostics/unknown-diag-code.lua index 45d3b6db..013a702b 100644 --- a/script/core/diagnostics/unknown-diag-code.lua +++ b/script/core/diagnostics/unknown-diag-code.lua @@ -3,7 +3,7 @@ local lang = require 'language' local define = require 'proto.define' return function (uri, callback) - local state = files.getAst(uri) + local state = files.getState(uri) if not state then return end diff --git a/script/core/diagnostics/unused-function.lua b/script/core/diagnostics/unused-function.lua index 41c239f9..59f27e59 100644 --- a/script/core/diagnostics/unused-function.lua +++ b/script/core/diagnostics/unused-function.lua @@ -19,7 +19,7 @@ local function isToBeClosed(source) end return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/unused-label.lua b/script/core/diagnostics/unused-label.lua index e6d998ba..8ee0bba3 100644 --- a/script/core/diagnostics/unused-label.lua +++ b/script/core/diagnostics/unused-label.lua @@ -4,7 +4,7 @@ local define = require 'proto.define' local lang = require 'language' return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/unused-local.lua b/script/core/diagnostics/unused-local.lua index 1a77a45f..072cbd31 100644 --- a/script/core/diagnostics/unused-local.lua +++ b/script/core/diagnostics/unused-local.lua @@ -77,7 +77,7 @@ local function isDocParam(source) end return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/diagnostics/unused-vararg.lua b/script/core/diagnostics/unused-vararg.lua index 74cc08e7..2e07e1ee 100644 --- a/script/core/diagnostics/unused-vararg.lua +++ b/script/core/diagnostics/unused-vararg.lua @@ -4,7 +4,7 @@ local define = require 'proto.define' local lang = require 'language' return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/document-symbol.lua b/script/core/document-symbol.lua index e36ba29b..03169cfd 100644 --- a/script/core/document-symbol.lua +++ b/script/core/document-symbol.lua @@ -228,7 +228,7 @@ local function buildSource(source, text, used, symbols) end local function makeSymbol(uri) - local ast = files.getAst(uri) + local ast = files.getState(uri) local text = files.getText(uri) if not ast or not text then return nil diff --git a/script/core/folding.lua b/script/core/folding.lua index 38008be9..dad98422 100644 --- a/script/core/folding.lua +++ b/script/core/folding.lua @@ -145,7 +145,7 @@ local Care = { } return function (uri) - local ast = files.getAst(uri) + local ast = files.getState(uri) local text = files.getText(uri) if not ast or not text then return nil diff --git a/script/core/highlight.lua b/script/core/highlight.lua index d75c12c4..3ae4dcb2 100644 --- a/script/core/highlight.lua +++ b/script/core/highlight.lua @@ -236,7 +236,7 @@ local function isLiteralValue(source) end return function (uri, offset) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return nil end diff --git a/script/core/hint.lua b/script/core/hint.lua index f4ccad44..2c449ae6 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -5,7 +5,7 @@ local config = require 'config' local guide = require 'parser.guide' local function typeHint(uri, edits, start, finish) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end @@ -96,7 +96,7 @@ local function paramName(uri, edits, start, finish) if not config.config.hint.paramName then return end - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua index 5dd00c43..41616bc9 100644 --- a/script/core/hover/init.lua +++ b/script/core/hover/init.lua @@ -147,7 +147,7 @@ local accept = { } local function getHoverByUri(uri, offset) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return nil end diff --git a/script/core/reference.lua b/script/core/reference.lua index c3f3b349..6ea79f5f 100644 --- a/script/core/reference.lua +++ b/script/core/reference.lua @@ -53,7 +53,7 @@ local accept = { } return function (uri, offset) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return nil end diff --git a/script/core/rename.lua b/script/core/rename.lua index 6b67d4be..bc85ac14 100644 --- a/script/core/rename.lua +++ b/script/core/rename.lua @@ -443,7 +443,7 @@ function m.rename(uri, pos, newname) if not newname then return nil end - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return nil end @@ -492,7 +492,7 @@ function m.rename(uri, pos, newname) end function m.prepareRename(uri, pos) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return nil end diff --git a/script/core/searcher.lua b/script/core/searcher.lua index f13c511f..fc19fc80 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -210,7 +210,7 @@ local function checkCache(status, uri, expect, mode) end function m.searchRefsByID(status, uri, expect, mode) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end @@ -585,7 +585,7 @@ local function getField(status, source, mode) end local function searchAllGlobalByUri(status, mode, uri, fullID) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end @@ -640,24 +640,6 @@ function m.searchRefs(status, source, mode) m.searchRefsByID(status, uri, id, mode) end ----查找全局变量 ----@param uri uri ----@param mode guide.searchmode ----@param name string ----@return parser.guide.object[] -function m.findGlobals(uri, mode, name) - local status = m.status(mode) - - if name then - local fullID = ('g:%q'):format(name) - searchAllGlobalByUri(status, mode, uri, fullID) - else - searchAllGlobalByUri(status, mode, uri) - end - - return status.results -end - ---搜索对象的field ---@param status guide.status ---@param source parser.guide.object diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 74b3942c..f310e3f1 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -213,7 +213,7 @@ local function buildTokens(uri, results) end return function (uri, start, finish) - local ast = files.getAst(uri) + local ast = files.getState(uri) local lines = files.getLines(uri) local text = files.getText(uri) if not ast then diff --git a/script/core/signature.lua b/script/core/signature.lua index 915310c0..8de1c374 100644 --- a/script/core/signature.lua +++ b/script/core/signature.lua @@ -133,7 +133,7 @@ local function skipSpace(text, offset) end return function (uri, pos) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return nil end diff --git a/script/core/type-formatting.lua b/script/core/type-formatting.lua index 49a721e5..b01a1999 100644 --- a/script/core/type-formatting.lua +++ b/script/core/type-formatting.lua @@ -69,7 +69,7 @@ local function checkSplitOneLine(results, uri, offset, ch) end return function (uri, offset, ch) - local ast = files.getAst(uri) + local ast = files.getState(uri) local text = files.getOriginText(uri) if not ast or not text then return nil diff --git a/script/core/workspace-symbol.lua b/script/core/workspace-symbol.lua index 6301cc39..18ab1eeb 100644 --- a/script/core/workspace-symbol.lua +++ b/script/core/workspace-symbol.lua @@ -47,7 +47,7 @@ local function buildSource(uri, source, key, results) end local function searchFile(uri, key, results) - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return end diff --git a/script/files.lua b/script/files.lua index bb143250..3ee64229 100644 --- a/script/files.lua +++ b/script/files.lua @@ -378,7 +378,7 @@ function m.eachDll() return pairs(map) end -function m.compileAst(uri, text) +function m.compileState(uri, text) local ws = require 'workspace' if not m.isOpen(uri) and #text >= config.config.workspace.preloadFileSize * 1000 then if not m.notifyCache['preloadFileSize'] then @@ -446,8 +446,8 @@ end --- 获取文件语法树 ---@param uri uri ----@return table ast -function m.getAst(uri) +---@return table state +function m.getState(uri) uri = getUriKey(uri) if uri ~= '' and not m.isLua(uri) then return nil @@ -458,7 +458,7 @@ function m.getAst(uri) end local ast = m.astMap[uri] if not ast then - ast = m.compileAst(uri, file.text) + ast = m.compileState(uri, file.text) m.astMap[uri] = ast --await.delay() end diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 883ae68c..4a207115 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -190,7 +190,7 @@ function m.doDiagnostic(uri) await.delay() - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then m.clear(uri) return diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index e712c6f7..bc7df626 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -25,7 +25,7 @@ end function vm.getDocDefines(name) local results = {} for uri in files.eachFile() do - local ast = files.getAst(uri) + local ast = files.getState(uri) getDocDefinesInAst(results, ast.ast, name) end return results @@ -49,7 +49,7 @@ function vm.getDocEnums(doc) end function vm.isMetaFile(uri) - local status = files.getAst(uri) + local status = files.getState(uri) if not status then return false end @@ -203,7 +203,7 @@ local function makeDiagRange(uri, doc, results) end function vm.isDiagDisabledAt(uri, offset, name) - local status = files.getAst(uri) + local status = files.getState(uri) if not status then return false end diff --git a/script/vm/getGlobals.lua b/script/vm/getGlobals.lua.txt index e5bcafc0..e5bcafc0 100644 --- a/script/vm/getGlobals.lua +++ b/script/vm/getGlobals.lua.txt diff --git a/script/vm/getLinks.lua b/script/vm/getLinks.lua index 51a18d58..14b34987 100644 --- a/script/vm/getLinks.lua +++ b/script/vm/getLinks.lua @@ -5,7 +5,7 @@ local files = require 'files' local function getFileLinks(uri) local ws = require 'workspace' local links = {} - local ast = files.getAst(uri) + local ast = files.getState(uri) if not ast then return links end @@ -52,6 +52,7 @@ local function getLinksTo(uri) return links end +-- 获取所有 require(uri) 的文件 function vm.getLinksTo(uri) local cache = vm.getCache('getLinksTo')[uri] if cache ~= nil then diff --git a/script/vm/globals.lua b/script/vm/globals.lua new file mode 100644 index 00000000..cf18aa19 --- /dev/null +++ b/script/vm/globals.lua @@ -0,0 +1,31 @@ +local files = require 'files' +local await = require 'await' +local noder = require 'core.noder' + +local globalsMap = {} +local subscribe = {} + +local function popGlobals(uri) + +end + +local function pushGlobals(uri) + local state = files.getState(uri) + if not state then + return + end + noder.compileNodes(state.ast) + +end + +local m = {} + +files.watch(function (ev, uri) + if ev == 'update' then + popGlobals(uri) + await.delay() + pushGlobals(uri) + end +end) + +return m diff --git a/script/vm/guideInterface.lua b/script/vm/guideInterface.lua index e59fc6e3..a07b6644 100644 --- a/script/vm/guideInterface.lua +++ b/script/vm/guideInterface.lua @@ -31,7 +31,7 @@ function m.require(args, index) local uris = ws.findUrisByRequirePath(reqName) for _, uri in ipairs(uris) do if not files.eq(myUri, uri) then - local ast = files.getAst(uri) + local ast = files.getState(uri) if ast then m.searchFileReturn(results, ast.ast, index) end @@ -51,7 +51,7 @@ function m.dofile(args, index) local uris = ws.findUrisByFilePath(reqName) for _, uri in ipairs(uris) do if not files.eq(myUri, uri) then - local ast = files.getAst(uri) + local ast = files.getState(uri) if ast then m.searchFileReturn(results, ast.ast, index) end diff --git a/test/basic/noder.lua b/test/basic/noder.lua index 3e5e9f25..99c28964 100644 --- a/test/basic/noder.lua +++ b/test/basic/noder.lua @@ -4,7 +4,7 @@ local util = require 'utility' local guide = require 'parser.guide' local function getSource(pos) - local ast = files.getAst('') + local ast = files.getState('') return guide.eachSourceContain(ast.ast, pos, function (source) if source.type == 'local' or source.type == 'getlocal' diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 4c8817f2..7a968972 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -6,7 +6,7 @@ local infer = require 'core.infer' rawset(_G, 'TEST', true) local function getSource(pos) - local ast = files.getAst('') + local ast = files.getState('') return guide.eachSourceContain(ast.ast, pos, function (source) if source.type == 'local' or source.type == 'getlocal' |