summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
Diffstat (limited to 'script/core')
-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
11 files changed, 23 insertions, 29 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]