diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-27 20:46:58 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-27 20:46:58 +0800 |
commit | f9b3b65445e86ae0e9c1026ea1fac44bf5d884da (patch) | |
tree | 7ab3d3c5c78bd35631c89ff067376675b7d736e6 /script | |
parent | d60ff4632d81d4357118f724b61ff5d0c6943ac5 (diff) | |
download | lua-language-server-f9b3b65445e86ae0e9c1026ea1fac44bf5d884da.zip |
#1240 use faster `isInString`
Diffstat (limited to 'script')
-rw-r--r-- | script/core/command/removeSpace.lua | 11 | ||||
-rw-r--r-- | script/core/diagnostics/trailing-space.lua | 21 | ||||
-rw-r--r-- | script/parser/guide.lua | 9 |
3 files changed, 13 insertions, 28 deletions
diff --git a/script/core/command/removeSpace.lua b/script/core/command/removeSpace.lua index 69a01b53..992a0705 100644 --- a/script/core/command/removeSpace.lua +++ b/script/core/command/removeSpace.lua @@ -4,14 +4,6 @@ local proto = require 'proto' local lang = require 'language' local converter = require 'proto.converter' -local function isInString(ast, offset) - return guide.eachSourceContain(ast.ast, offset, function (source) - if source.type == 'string' then - return true - end - end) or false -end - ---@async return function (data) local uri = data.uri @@ -32,7 +24,8 @@ return function (data) goto NEXT_LINE end local lastPos = guide.offsetToPosition(state, lastOffset) - if isInString(state.ast, lastPos) then + if guide.isInString(state.ast, lastPos) + or guide.isInComment(state.ast, lastPos) then goto NEXT_LINE end local firstOffset = startOffset diff --git a/script/core/diagnostics/trailing-space.lua b/script/core/diagnostics/trailing-space.lua index b9e4d32d..aad0b53d 100644 --- a/script/core/diagnostics/trailing-space.lua +++ b/script/core/diagnostics/trailing-space.lua @@ -2,23 +2,6 @@ local files = require 'files' local lang = require 'language' local guide = require 'parser.guide' -local function isInString(ast, offset) - return guide.eachSourceType(ast, 'string', function (source) - if offset >= source.start and offset <= source.finish then - return true - end - end) -end - -local function isInComment(ast, offset) - for _, com in ipairs(ast.state.comms) do - if offset >= com.start and offset <= com.finish then - return true - end - end - return false -end - return function (uri, callback) local state = files.getState(uri) local text = files.getText(uri) @@ -35,8 +18,8 @@ return function (uri, callback) goto NEXT_LINE end local lastPos = guide.offsetToPosition(state, lastOffset) - if isInString(state.ast, lastPos) - or isInComment(state.ast, lastPos) then + if guide.isInString(state.ast, lastPos) + or guide.isInComment(state.ast, lastPos) then goto NEXT_LINE end local firstOffset = startOffset diff --git a/script/parser/guide.lua b/script/parser/guide.lua index a91a6f68..05827398 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1231,6 +1231,15 @@ function m.isInString(ast, position) end) end +function m.isInComment(ast, offset) + for _, com in ipairs(ast.state.comms) do + if offset >= com.start and offset <= com.finish then + return true + end + end + return false +end + function m.isOOP(source) if source.type == 'setmethod' or source.type == 'getmethod' then |