summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-22 10:58:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-22 10:58:43 +0800
commit489fcbaa9da91ac8275a2ba5dadc6bd88b9cd5ec (patch)
treeeabc184d1a8d3df2bed43ddebe429183fd284120 /script/core
parent59b9f2343ef3c7b526a4ea5c4694cdc1ef8c4011 (diff)
downloadlua-language-server-489fcbaa9da91ac8275a2ba5dadc6bd88b9cd5ec.zip
clean up code
Diffstat (limited to 'script/core')
-rw-r--r--script/core/code-action.lua18
-rw-r--r--script/core/command/removeSpace.lua2
-rw-r--r--script/core/command/solve.lua6
3 files changed, 9 insertions, 17 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua
index 2a0d9907..dfd935c5 100644
--- a/script/core/code-action.lua
+++ b/script/core/code-action.lua
@@ -65,9 +65,7 @@ end
local function solveUndefinedGlobal(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)
+ local offset = files.offsetOfWord(uri, diag.range.start)
guide.eachSourceContain(ast.ast, offset, function (source)
if source.type ~= 'getglobal' then
return
@@ -86,9 +84,7 @@ 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)
+ local offset = files.offsetOfWord(uri, diag.range.start)
guide.eachSourceContain(ast.ast, offset, function (source)
if source.type ~= 'setglobal' then
return
@@ -100,12 +96,10 @@ local function solveLowercaseGlobal(uri, diag, results)
end
local function findSyntax(uri, diag)
- local ast = files.getAst(uri)
- local text = files.getText(uri)
- local lines = files.getLines(uri)
+ local ast = files.getAst(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)
+ local range = files.range(uri, err.start, err.finish)
if util.equal(range, diag.range) then
return err
end
@@ -205,9 +199,7 @@ local function solveSyntax(uri, diag, results)
end
local function solveNewlineCall(uri, diag, results)
- local text = files.getText(uri)
- local lines = files.getLines(uri)
- local start = define.unrange(lines, text, diag.range)
+ local start = files.unrange(uri, diag.range)
results[#results+1] = {
title = lang.script.ACTION_ADD_SEMICOLON,
kind = 'quickfix',
diff --git a/script/core/command/removeSpace.lua b/script/core/command/removeSpace.lua
index e8b09932..29513951 100644
--- a/script/core/command/removeSpace.lua
+++ b/script/core/command/removeSpace.lua
@@ -32,7 +32,7 @@ return function (data)
goto NEXT_LINE
end
textEdit[#textEdit+1] = {
- range = define.range(lines, text, start, finish),
+ range = files.range(uri, start, finish),
newText = '',
}
goto NEXT_LINE
diff --git a/script/core/command/solve.lua b/script/core/command/solve.lua
index d3b8f94e..ff14bf40 100644
--- a/script/core/command/solve.lua
+++ b/script/core/command/solve.lua
@@ -35,8 +35,8 @@ return function (data)
return
end
- local start = define.offsetOfWord(lines, text, data.range.start)
- local finish = define.offsetOfWord(lines, text, data.range['end'])
+ local start = files.offsetOfWord(uri, data.range.start)
+ local finish = files.offsetOfWord(uri, data.range['end'])
local result = guide.eachSourceContain(ast.ast, start, function (source)
if source.start ~= start
@@ -86,7 +86,7 @@ return function (data)
changes = {
[uri] = {
{
- range = define.range(lines, text, result.start, result.finish),
+ range = files.range(uri, result.start, result.finish),
newText = ('(%s)'):format(text:sub(result.start, result.finish)),
}
},