summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-22 17:24:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-22 17:24:44 +0800
commit32aa2dac835a0c74b82b19d83d9fd06be7a947ce (patch)
treed3e162b147ebc030de703439a7dcf94bce013fe9
parenta45e980f0d51c47229d18d0f859e718d203b472f (diff)
downloadlua-language-server-32aa2dac835a0c74b82b19d83d9fd06be7a947ce.zip
cleanup
-rw-r--r--script/core/code-action.lua3
-rw-r--r--script/core/command/autoRequire.lua1
-rw-r--r--script/core/command/removeSpace.lua1
-rw-r--r--script/core/completion.lua1
-rw-r--r--script/core/diagnostics/different-requires.lua2
-rw-r--r--script/core/diagnostics/init.lua2
-rw-r--r--script/core/diagnostics/newfield-call.lua1
-rw-r--r--script/core/diagnostics/newline-call.lua3
-rw-r--r--script/core/diagnostics/trailing-space.lua36
-rw-r--r--script/core/semantic-tokens.lua1
-rw-r--r--script/core/type-formatting.lua1
-rw-r--r--script/files.lua29
-rw-r--r--script/parser/guide.lua12
-rw-r--r--script/vm/getDocs.lua1
-rw-r--r--test/diagnostics/init.lua63
15 files changed, 39 insertions, 118 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua
index 922ebff3..ce71f4af 100644
--- a/script/core/code-action.lua
+++ b/script/core/code-action.lua
@@ -5,7 +5,6 @@ local sp = require 'bee.subprocess'
local guide = require "parser.guide"
local function checkDisableByLuaDocExits(uri, row, mode, code)
- local lines = files.getLines(uri)
local ast = files.getState(uri)
local text = files.getOriginText(uri)
local line = lines[row]
@@ -41,7 +40,6 @@ local function checkDisableByLuaDocExits(uri, row, mode, code)
end
local function checkDisableByLuaDocInsert(uri, row, mode, code)
- local lines = files.getLines(uri)
local ast = files.getState(uri)
local text = files.getOriginText(uri)
-- 先看看上一行是不是已经有了
@@ -56,7 +54,6 @@ local function checkDisableByLuaDocInsert(uri, row, mode, code)
end
local function disableDiagnostic(uri, code, start, results)
- local lines = files.getLines(uri)
local row = guide.rowColOf(start)
results[#results+1] = {
title = lang.script('ACTION_DISABLE_DIAG', code),
diff --git a/script/core/command/autoRequire.lua b/script/core/command/autoRequire.lua
index 2cb6a8f8..e784a827 100644
--- a/script/core/command/autoRequire.lua
+++ b/script/core/command/autoRequire.lua
@@ -6,7 +6,6 @@ local client = require 'client'
local lang = require 'language'
local function findInsertOffset(uri)
- local lines = files.getLines(uri)
local text = files.getText(uri)
local fmt = {
pair = false,
diff --git a/script/core/command/removeSpace.lua b/script/core/command/removeSpace.lua
index b94f9788..34c74ce0 100644
--- a/script/core/command/removeSpace.lua
+++ b/script/core/command/removeSpace.lua
@@ -13,7 +13,6 @@ end
return function (data)
local uri = data.uri
- local lines = files.getLines(uri)
local text = files.getText(uri)
local ast = files.getState(uri)
if not lines then
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 6f9605e2..e56ed3f8 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -227,7 +227,6 @@ end
local function buildInsertRequire(state, targetUri, stemName)
local uri = guide.getUri(state.ast)
- local lines = files.getLines(uri)
local text = files.getText(uri)
local start = 1
for i = 1, #lines do
diff --git a/script/core/diagnostics/different-requires.lua b/script/core/diagnostics/different-requires.lua
index 909342f4..fd7415b6 100644
--- a/script/core/diagnostics/different-requires.lua
+++ b/script/core/diagnostics/different-requires.lua
@@ -12,7 +12,7 @@ return function (uri, callback)
end
local cache = vm.getCache 'different-requires'
guide.eachSpecialOf(state.ast, 'require', function (source)
- local call = source.next
+ local call = source.parent
if not call or call.type ~= 'call' then
return
end
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index 09688f6e..63a1bcf0 100644
--- a/script/core/diagnostics/init.lua
+++ b/script/core/diagnostics/init.lua
@@ -44,7 +44,7 @@ local function check(uri, name, results)
if vm.isDiagDisabledAt(uri, result.start, name) then
return
end
- if result.start == 0 then
+ if result.start < 0 then
return
end
if mark[result.start] then
diff --git a/script/core/diagnostics/newfield-call.lua b/script/core/diagnostics/newfield-call.lua
index 83d205ca..669ed2bb 100644
--- a/script/core/diagnostics/newfield-call.lua
+++ b/script/core/diagnostics/newfield-call.lua
@@ -8,7 +8,6 @@ return function (uri, callback)
return
end
- local lines = files.getLines(uri)
local text = files.getText(uri)
guide.eachSourceType(ast.ast, 'table', function (source)
diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua
index 1c31fa8d..b28310e3 100644
--- a/script/core/diagnostics/newline-call.lua
+++ b/script/core/diagnostics/newline-call.lua
@@ -4,9 +4,8 @@ local lang = require 'language'
return function (uri, callback)
local ast = files.getState(uri)
- local lines = files.getLines(uri)
local text = files.getText(uri)
- if not ast or not lines then
+ if not ast then
return
end
diff --git a/script/core/diagnostics/trailing-space.lua b/script/core/diagnostics/trailing-space.lua
index 824eb83f..5c66b118 100644
--- a/script/core/diagnostics/trailing-space.lua
+++ b/script/core/diagnostics/trailing-space.lua
@@ -13,40 +13,44 @@ local function isInString(ast, offset)
end
return function (uri, callback)
- local ast = files.getState(uri)
- if not ast then
+ local state = files.getState(uri)
+ if not state then
return
end
local text = files.getText(uri)
- local lines = files.getLines(uri)
- for i = 1, #lines do
- local start = lines[i].start
- local range = lines[i].range
- local lastChar = text:sub(range, range)
+ local lines = state.lines
+ for i = 0, #lines do
+ local startPos = lines[i]
+ local startOffset = guide.positionToOffset(state, startPos)
+ local finishOffset = text:find('[\r\n]', startOffset) or (#text + 1)
+ local lastOffset = finishOffset - 1
+ local lastChar = text:sub(lastOffset, lastOffset)
if lastChar ~= ' ' and lastChar ~= '\t' then
goto NEXT_LINE
end
- if isInString(ast.ast, range) then
+ local lastPos = guide.offsetToPosition(state, lastOffset)
+ if isInString(state.ast, lastPos) then
goto NEXT_LINE
end
- local first = start
- for n = range - 1, start, -1 do
+ local firstOffset = startOffset
+ for n = lastOffset - 1, startOffset, -1 do
local char = text:sub(n, n)
if char ~= ' ' and char ~= '\t' then
- first = n + 1
+ firstOffset = n + 1
break
end
end
- if first == start then
+ local firstPos = guide.offsetToPosition(state, firstOffset) - 1
+ if firstOffset == startOffset then
callback {
- start = first,
- finish = range,
+ start = firstPos,
+ finish = lastPos,
message = lang.script.DIAG_LINE_ONLY_SPACE,
}
else
callback {
- start = first,
- finish = range,
+ start = firstPos,
+ finish = lastPos,
message = lang.script.DIAG_LINE_POST_SPACE,
}
end
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua
index 96cbc5e1..238df862 100644
--- a/script/core/semantic-tokens.lua
+++ b/script/core/semantic-tokens.lua
@@ -214,7 +214,6 @@ end
return function (uri, start, finish)
local ast = files.getState(uri)
- local lines = files.getLines(uri)
local text = files.getText(uri)
if not ast then
return nil
diff --git a/script/core/type-formatting.lua b/script/core/type-formatting.lua
index d7bacbf8..cd2044bc 100644
--- a/script/core/type-formatting.lua
+++ b/script/core/type-formatting.lua
@@ -3,7 +3,6 @@ local lookBackward = require 'core.look-backward'
local guide = require "parser.guide"
local function insertIndentation(uri, offset, edits)
- local lines = files.getLines(uri)
local text = files.getOriginText(uri)
local row = guide.rowColOf(offset)
local line = lines[row]
diff --git a/script/files.lua b/script/files.lua
index 98d9b83c..a3595a4f 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -537,35 +537,6 @@ function m.getVisibles(uri)
return visibles
end
---- 获取文件行信息
----@param uri uri
----@return table lines
-function m.getLines(uri)
- local file = m.fileMap[uri]
- if not file then
- return nil
- end
- local lines = m.linesMap[uri]
- if not lines then
- lines = parser.lines(file.text)
- m.linesMap[uri] = lines
- end
- return lines
-end
-
-function m.getOriginLines(uri)
- local file = m.fileMap[uri]
- if not file then
- return nil
- end
- local lines = m.originLinesMap[uri]
- if not lines then
- lines = parser.lines(file.originText)
- m.originLinesMap[uri] = lines
- end
- return lines
-end
-
function m.getFile(uri)
return m.fileMap[uri]
or m.dllMap[uri]
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index fb5f3db4..cea56be8 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -805,18 +805,6 @@ function m.lineContent(lines, text, row, ignoreNL)
end
end
-function m.lineRange(lines, row, ignoreNL)
- local line = lines[row]
- if not line then
- return 0, 0
- end
- if ignoreNL then
- return line.start, line.range
- else
- return line.start, line.finish
- end
-end
-
local isSetMap = {
['setglobal'] = true,
['local'] = true,
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua
index 218dc048..7cac0935 100644
--- a/script/vm/getDocs.lua
+++ b/script/vm/getDocs.lua
@@ -177,7 +177,6 @@ function vm.isDeprecated(value, deep)
end
local function makeDiagRange(uri, doc, results)
- local lines = files.getLines(uri)
local names
if doc.names then
names = {}
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index 54ac73ef..840be836 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -2,36 +2,12 @@ local core = require 'core.diagnostics'
local files = require 'files'
local config = require 'config'
local util = require 'utility'
+local catch = require 'catch'
config.get 'Lua.diagnostics.neededFileStatus'['deprecated'] = 'Any'
rawset(_G, 'TEST', true)
-local function catch_target(script, ...)
- local list = {}
- local function catch(buf)
- local cur = 1
- local cut = 0
- while true do
- local start, finish = buf:find('<!.-!>', cur)
- if not start then
- break
- end
- list[#list+1] = { start - cut, finish - 4 - cut }
- cur = finish + 1
- cut = cut + 4
- end
- end
- catch(script)
- if ... then
- for _, buf in ipairs {...} do
- catch(buf)
- end
- end
- local new_script = script:gsub('<!(.-)!>', '%1')
- return new_script, list
-end
-
local function founded(targets, results)
if #targets ~= #results then
return false
@@ -50,8 +26,8 @@ end
function TEST(script, ...)
files.removeAll()
- local new_script, target = catch_target(script, ...)
- files.setText('', new_script)
+ local newScript, catched = catch(script, '!')
+ files.setText('', newScript)
files.open('')
local datas = {}
core('', function (results)
@@ -65,11 +41,11 @@ function TEST(script, ...)
end
if results[1] then
- if not founded(target, results) then
- error(('%s\n%s'):format(util.dump(target), util.dump(results)))
+ if not founded(catched['!'], results) then
+ error(('%s\n%s'):format(util.dump(catched['!']), util.dump(results)))
end
else
- assert(#target == 0)
+ assert(catched['!'] == nil)
end
end
@@ -99,15 +75,11 @@ local <!t!> = {}
<!t!>.a = 1
]]
-TEST([[
-local <!function x()
+TEST [[
+local <!function <!x!>()
end!>
-]],
-[[
-local function <!x!>()
-end
]]
-)
+
TEST [[
local <!x!> = <!function () end!>
@@ -118,21 +90,13 @@ local <!x!>
<!x!> = <!function () end!>
]]
-TEST([[
+TEST [[
local <!function x()
end!>
-local <!function y()
+local <!function <!y!>()
x()
end!>
-]],
-[[
-local function x()
-end
-local function <!y!>()
- x()
-end
]]
-)
TEST [[
local print, _G
@@ -155,6 +119,11 @@ TEST [[
]]
TEST [[
+
+<! !>
+]]
+
+TEST [[
X = 1<! !>
]]