@@ -198,7 +198,7 @@ defmodule NextLS do
198
198
URI . parse ( uri ) . path ,
199
199
{ position . line + 1 , position . character + 1 }
200
200
) do
201
- { _name , { startl .. endl , startc .. endc } } ->
201
+ { _name , { startl .. endl // _ , startc .. endc // _ } } ->
202
202
% Location {
203
203
uri: "file://#{ URI . parse ( uri ) . path } " ,
204
204
range: % Range {
@@ -316,7 +316,7 @@ defmodule NextLS do
316
316
:unknown ->
317
317
file
318
318
|> NextLS.ASTHelpers.Variables . list_variable_references ( { line , col } )
319
- |> Enum . map ( fn { _name , { startl .. endl , startc .. endc } } ->
319
+ |> Enum . map ( fn { _name , { startl .. endl // _ , startc .. endc // _ } } ->
320
320
[ file , startl , endl , startc , endc ]
321
321
end )
322
322
end
@@ -555,6 +555,20 @@ defmodule NextLS do
555
555
def handle_request ( % TextDocumentCompletion { params: % { text_document: % { uri: uri } , position: position } } , lsp ) do
556
556
document = lsp . assigns . documents [ uri ]
557
557
558
+ env =
559
+ document
560
+ |> List . update_at ( position . line , fn row ->
561
+ { front , back } = String . split_at ( row , position . character )
562
+ String . slice ( front , - 1 .. 1 ) <> "__cursor__()" <> back
563
+ end )
564
+ |> Enum . join ( "\n " )
565
+ |> Spitfire . parse ( literal_encoder: & { :ok , { :__literal__ , & 2 , [ & 1 ] } } )
566
+ |> then ( fn
567
+ { :ok , ast } -> ast
568
+ { :error , ast , _ } -> ast
569
+ end )
570
+ |> NextLS.ASTHelpers.Env . build ( )
571
+
558
572
document_slice =
559
573
document
560
574
|> Enum . take ( position . line + 1 )
@@ -571,7 +585,10 @@ defmodule NextLS do
571
585
|> dispatch ( :runtimes , fn entries ->
572
586
[ result ] =
573
587
for { runtime , % { uri: wuri } } <- entries , String . starts_with? ( uri , wuri ) do
574
- NextLS.Autocomplete . expand ( document_slice |> String . to_charlist ( ) |> Enum . reverse ( ) , runtime )
588
+ document_slice
589
+ |> String . to_charlist ( )
590
+ |> Enum . reverse ( )
591
+ |> NextLS.Autocomplete . expand ( runtime , env )
575
592
end
576
593
577
594
case result do
@@ -607,12 +624,14 @@ defmodule NextLS do
607
624
end )
608
625
|> Enum . reverse ( )
609
626
627
+ dbg ( results )
628
+
610
629
{ :reply , results , lsp }
611
630
rescue
612
631
e ->
613
632
GenLSP . warning (
614
633
lsp ,
615
- "[Next LS] Failed to run completion request: #{ Exception . format_banner ( :error , e , __STACKTRACE__ ) } "
634
+ "[Next LS] Failed to run completion request: #{ Exception . format ( :error , e , __STACKTRACE__ ) } "
616
635
)
617
636
618
637
{ :reply , [ ] , lsp }
0 commit comments