Skip to content

Commit 83a4b5f

Browse files
committed
improve type stability
1 parent baf6e37 commit 83a4b5f

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/completions.jl

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -177,29 +177,32 @@ function global_completions!(items::Dict{String, CompletionItem}, state::ServerS
177177
completion_module = mod
178178

179179
prev_token = token_before_offset(fi, pos)
180-
prev_kind = isnothing(prev_token) ? nothing : JS.kind(this(prev_token))
181-
182-
# Case: `@│`
183-
if prev_kind === JS.K"@"
184-
edit_start_pos = offset_to_xy(fi, first_byte(prev_token))
185-
is_macro_invoke = true
186-
# Case: `@macr│`
187-
elseif prev_kind === JS.K"MacroName"
188-
edit_start_pos = offset_to_xy(fi, first_byte(prev_tok(prev_token)))
189-
is_macro_invoke = true
190-
# Case `│` (empty program)
191-
elseif isnothing(prev_token)
180+
if isnothing(prev_token)
181+
# Case `│` (empty program)
192182
edit_start_pos = Position(; line=0, character=0)
193183
is_macro_invoke = false
194-
elseif JS.is_identifier(prev_kind)
195-
edit_start_pos = offset_to_xy(fi, first_byte(prev_token))
196-
is_macro_invoke = false
197184
else
198-
# When completion is triggered within unknown scope (e.g., comment),
199-
# it's difficult to properly specify `edit_start_pos`.
200-
# Simply specify only the `label` and let the client handle it appropriately.
201-
edit_start_pos = nothing
202-
is_macro_invoke = false
185+
prev_kind = JS.kind(this(prev_token))
186+
# Case: `@│`
187+
if prev_kind === JS.K"@"
188+
edit_start_pos = offset_to_xy(fi, first_byte(prev_token))
189+
is_macro_invoke = true
190+
# Case: `@macr│`
191+
elseif prev_kind === JS.K"MacroName"
192+
at_token = @something prev_tok(prev_token) @goto elseblk
193+
edit_start_pos = offset_to_xy(fi, first_byte(at_token))
194+
is_macro_invoke = true
195+
elseif JS.is_identifier(prev_kind)
196+
edit_start_pos = offset_to_xy(fi, first_byte(prev_token))
197+
is_macro_invoke = false
198+
else
199+
# When completion is triggered within unknown scope (e.g., comment),
200+
# it's difficult to properly specify `edit_start_pos`.
201+
# Simply specify only the `label` and let the client handle it appropriately.
202+
@label elseblk
203+
edit_start_pos = nothing
204+
is_macro_invoke = false
205+
end
203206
end
204207

205208
# if we are in macro name context, then we don't need the local completions

0 commit comments

Comments
 (0)