Skip to content

Commit 2d9f942

Browse files
authored
Merge branch 'master' into sp/fix-multibyte-partial-completions
2 parents 75e4668 + 50d7a09 commit 2d9f942

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

src/requests/features.jl

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,36 @@ function textDocument_definition_request(params::TextDocumentPositionParams, ser
9898
return locations
9999
end
100100

101-
function get_file_loc(x::EXPR, offset=0, c=nothing)
102-
if c !== nothing
103-
for a in x
104-
a == c && break
105-
offset += a.fullspan
101+
function descend(x::EXPR, target::EXPR, offset = 0)
102+
for c in x
103+
if c == target
104+
return true, offset
105+
end
106+
107+
found, o = descend(c, target, offset)
108+
if found
109+
return true, o
106110
end
111+
offset += c.fullspan
107112
end
108-
if parentof(x) !== nothing
109-
return get_file_loc(parentof(x), offset, x)
110-
elseif headof(x) === :file && StaticLint.hasmeta(x)
111-
return x.meta.error, offset
112-
else
113+
false, offset
114+
end
115+
function get_file_loc(x::EXPR, offset=0, c=nothing)
116+
parent = x
117+
while parentof(parent) !== nothing
118+
parent = parentof(parent)
119+
end
120+
121+
if parent === nothing
113122
return nothing, offset
114123
end
124+
125+
_, offset = descend(parent, x)
126+
127+
if headof(parent) === :file && StaticLint.hasmeta(parent)
128+
return parent.meta.error, offset
129+
end
130+
return nothing, offset
115131
end
116132

117133
function search_file(filename, dir, topdir)

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,7 @@ end
9595
@testset "paths" begin
9696
include("test_paths.jl")
9797
end
98+
@testset "misc" begin
99+
include("test_misc.jl")
100+
end
98101
end

test/test_misc.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@testset "get_file_loc" begin
2+
str = "(x+y for x in X for y in Y if begin if true end end)"
3+
cst = CSTParser.parse(str)
4+
@test LanguageServer.get_file_loc(cst[2][5][1][1]) == (nothing, 20)
5+
end

0 commit comments

Comments
 (0)