diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-27 01:18:01 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-27 01:18:01 +0800 |
commit | 30e6ffcf59b713b817823f8b0d3c8de282131562 (patch) | |
tree | 5c3f8cc434c54d600db7ee114f2c2fa72c8a7f55 /script-beta/core | |
parent | 21d3b835ea684322a19ec661bb3a7e796d309123 (diff) | |
download | lua-language-server-30e6ffcf59b713b817823f8b0d3c8de282131562.zip |
对5.1的一些支持
Diffstat (limited to 'script-beta/core')
-rw-r--r-- | script-beta/core/code-action.lua | 66 | ||||
-rw-r--r-- | script-beta/core/completion.lua | 9 | ||||
-rw-r--r-- | script-beta/core/diagnostics/redefined-local.lua | 2 | ||||
-rw-r--r-- | script-beta/core/diagnostics/unused-local.lua | 2 |
4 files changed, 72 insertions, 7 deletions
diff --git a/script-beta/core/code-action.lua b/script-beta/core/code-action.lua index de7ef6ac..86bd520e 100644 --- a/script-beta/core/code-action.lua +++ b/script-beta/core/code-action.lua @@ -3,6 +3,7 @@ local lang = require 'language' local define = require 'proto.define' local guide = require 'parser.guide' local library = require 'library' +local util = require 'utility' local function disableDiagnostic(code, results) results[#results+1] = { @@ -79,9 +80,68 @@ local function solveUndefinedGlobal(uri, diag, results) end) end +local function solveLowercaseGlobal(uri, diag, results) + local ast = files.getAst(uri) + local text = files.getText(uri) + local lines = files.getLines(uri) + local offset = define.offsetOfWord(lines, text, diag.range.start) + guide.eachSourceContain(ast.ast, offset, function (source) + if source.type ~= 'setglobal' then + return + end + + local name = guide.getName(source) + markGlobal(name, results) + end) +end + +local function findSyntax(uri, diag) + local ast = files.getAst(uri) + local text = files.getText(uri) + local lines = files.getLines(uri) + for _, err in ipairs(ast.errs) do + if err.type:lower():gsub('_', '-') == diag.code then + local range = define.range(lines, text, err.start, err.finish) + if util.equal(range, diag.range) then + return err + end + end + end + return nil +end + +local function solveSyntaxByChangeVersion(err, results) + if type(err.version) == 'table' then + for _, version in ipairs(err.version) do + changeVersion(version, results) + end + else + changeVersion(err.version, results) + end +end + +local function solveSyntax(uri, diag, results) + local err = findSyntax(uri, diag) + if not err then + return + end + if err.version then + solveSyntaxByChangeVersion(err, results) + end +end + local function solveDiagnostic(uri, diag, results) - if diag.code == 'undefined-global' then + if diag.source == lang.script.DIAG_SYNTAX_CHECK then + solveSyntax(uri, diag, results) + return + end + if not diag.code then + return + end + if diag.code == 'undefined-global' then solveUndefinedGlobal(uri, diag, results) + elseif diag.code == 'lowercase-global' then + solveLowercaseGlobal(uri, diag, results) end disableDiagnostic(diag.code, results) end @@ -94,8 +154,8 @@ return function (uri, range, diagnostics) local results = {} - for _, data in ipairs(diagnostics) do - solveDiagnostic(uri, data, results) + for _, diag in ipairs(diagnostics) do + solveDiagnostic(uri, diag, results) end return results diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 116da8d2..658e3da2 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -303,7 +303,12 @@ local function checkFieldFromFieldToIndex(name, parent, word, start, offset) } end else - textEdit.newText = '_ENV' .. textEdit.newText + if config.runtime.version == 'Lua 5.1' + or config.runtime.version == 'LuaJIT' then + textEdit.newText = '_G' .. textEdit.newText + else + textEdit.newText = '_ENV' .. textEdit.newText + end end return textEdit, additionalTextEdits end @@ -740,7 +745,7 @@ local function tryWord(ast, text, offset, results) else checkLocal(ast, word, start, results) checkTableField(ast, word, start, results) - local env = guide.getLocal(ast.ast, '_ENV', start) + local env = guide.getENV(ast.ast, start) checkField(ast, word, start, offset, env, false, results) end end diff --git a/script-beta/core/diagnostics/redefined-local.lua b/script-beta/core/diagnostics/redefined-local.lua index f6176794..5e53d837 100644 --- a/script-beta/core/diagnostics/redefined-local.lua +++ b/script-beta/core/diagnostics/redefined-local.lua @@ -10,7 +10,7 @@ return function (uri, callback) guide.eachSourceType(ast.ast, 'local', function (source) local name = source[1] if name == '_' - or name == '_ENV' then + or name == ast.ENVMode then return end local exist = guide.getLocal(source, name, source.start-1) diff --git a/script-beta/core/diagnostics/unused-local.lua b/script-beta/core/diagnostics/unused-local.lua index 294a86e5..873a70f2 100644 --- a/script-beta/core/diagnostics/unused-local.lua +++ b/script-beta/core/diagnostics/unused-local.lua @@ -58,7 +58,7 @@ return function (uri, callback) guide.eachSourceType(ast.ast, 'local', function (source) local name = source[1] if name == '_' - or name == '_ENV' then + or name == ast.ENVMode then return end if isClose(source) then |