Skip to content

Commit f9b3b65

Browse files
committed
#1240 use faster isInString
1 parent d60ff46 commit f9b3b65

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

script/core/command/removeSpace.lua

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ local proto = require 'proto'
44
local lang = require 'language'
55
local converter = require 'proto.converter'
66

7-
local function isInString(ast, offset)
8-
return guide.eachSourceContain(ast.ast, offset, function (source)
9-
if source.type == 'string' then
10-
return true
11-
end
12-
end) or false
13-
end
14-
157
---@async
168
return function (data)
179
local uri = data.uri
@@ -32,7 +24,8 @@ return function (data)
3224
goto NEXT_LINE
3325
end
3426
local lastPos = guide.offsetToPosition(state, lastOffset)
35-
if isInString(state.ast, lastPos) then
27+
if guide.isInString(state.ast, lastPos)
28+
or guide.isInComment(state.ast, lastPos) then
3629
goto NEXT_LINE
3730
end
3831
local firstOffset = startOffset

script/core/diagnostics/trailing-space.lua

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,6 @@ local files = require 'files'
22
local lang = require 'language'
33
local guide = require 'parser.guide'
44

5-
local function isInString(ast, offset)
6-
return guide.eachSourceType(ast, 'string', function (source)
7-
if offset >= source.start and offset <= source.finish then
8-
return true
9-
end
10-
end)
11-
end
12-
13-
local function isInComment(ast, offset)
14-
for _, com in ipairs(ast.state.comms) do
15-
if offset >= com.start and offset <= com.finish then
16-
return true
17-
end
18-
end
19-
return false
20-
end
21-
225
return function (uri, callback)
236
local state = files.getState(uri)
247
local text = files.getText(uri)
@@ -35,8 +18,8 @@ return function (uri, callback)
3518
goto NEXT_LINE
3619
end
3720
local lastPos = guide.offsetToPosition(state, lastOffset)
38-
if isInString(state.ast, lastPos)
39-
or isInComment(state.ast, lastPos) then
21+
if guide.isInString(state.ast, lastPos)
22+
or guide.isInComment(state.ast, lastPos) then
4023
goto NEXT_LINE
4124
end
4225
local firstOffset = startOffset

script/parser/guide.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,15 @@ function m.isInString(ast, position)
12311231
end)
12321232
end
12331233

1234+
function m.isInComment(ast, offset)
1235+
for _, com in ipairs(ast.state.comms) do
1236+
if offset >= com.start and offset <= com.finish then
1237+
return true
1238+
end
1239+
end
1240+
return false
1241+
end
1242+
12341243
function m.isOOP(source)
12351244
if source.type == 'setmethod'
12361245
or source.type == 'getmethod' then

0 commit comments

Comments
 (0)