@@ -319,8 +319,8 @@ defmodule ElixirLS.LanguageServer.Parser do
319
319
end
320
320
321
321
defp should_parse? ( uri , source_file ) do
322
- String . ends_with? ( uri , [ ".ex" , ".exs" , ".eex" ] ) or
323
- source_file . language_id in [ "elixir" , "eex" , "html-eex" ]
322
+ String . ends_with? ( uri , [ ".ex" , ".exs" , ".eex" , ".heex" ] ) or
323
+ source_file . language_id in [ "elixir" , "eex" , "html-eex" , "phoenix-heex" ]
324
324
end
325
325
326
326
defp maybe_fix_missing_env ( % Context { } = file , nil ) , do: file
@@ -506,6 +506,16 @@ defmodule ElixirLS.LanguageServer.Parser do
506
506
( is_binary ( file ) and String . ends_with? ( file , ".eex" ) ) or language_id in [ "eex" , "html-eex" ]
507
507
end
508
508
509
+ defp html_eex? ( file , language_id ) do
510
+ ( is_binary ( file ) and
511
+ ( String . ends_with? ( file , ".html.eex" ) or String . ends_with? ( file , ".htm.eex" ) ) ) or
512
+ language_id in [ "html-eex" ]
513
+ end
514
+
515
+ defp heex? ( file , language_id ) do
516
+ ( is_binary ( file ) and String . ends_with? ( file , ".heex" ) ) or language_id in [ "phoenix-heex" ]
517
+ end
518
+
509
519
defp parse_file ( text , file , language_id ) do
510
520
{ result , raw_diagnostics } =
511
521
Build . with_diagnostics ( [ log: false ] , fn ->
@@ -517,18 +527,70 @@ defmodule ElixirLS.LanguageServer.Parser do
517
527
]
518
528
519
529
ast =
520
- if eex? ( file , language_id ) do
521
- EEx . compile_string ( text ,
522
- file: file ,
523
- parser_options: parser_options
524
- )
525
- else
526
- Code . string_to_quoted! ( text , parser_options )
530
+ cond do
531
+ eex? ( file , language_id ) ->
532
+ EEx . compile_string ( text ,
533
+ file: file ,
534
+ parser_options: parser_options
535
+ )
536
+
537
+ html_eex? ( file , language_id ) ->
538
+ if Code . ensure_loaded? ( Phoenix.HTML.Engine ) do
539
+ EEx . compile_string ( text ,
540
+ file: file ,
541
+ parser_options: parser_options ,
542
+ engine: Phoenix.HTML.Engine
543
+ )
544
+ else
545
+ EEx . compile_string ( text ,
546
+ file: file ,
547
+ parser_options: parser_options
548
+ )
549
+ end
550
+
551
+ heex? ( file , language_id ) ->
552
+ cond do
553
+ Code . ensure_loaded? ( Phoenix.LiveView.TagEngine ) ->
554
+ # LV 0.18+
555
+ EEx . compile_string ( text ,
556
+ file: file ,
557
+ parser_options: parser_options ,
558
+ source: text ,
559
+ caller: __ENV__ ,
560
+ engine: Phoenix.LiveView.TagEngine ,
561
+ tag_handler: Phoenix.LiveView.HTMLEngine
562
+ )
563
+
564
+ Code . ensure_loaded? ( Phoenix.LiveView.HTMLEngine ) ->
565
+ # LV <= 0.18.17
566
+ EEx . compile_string ( text ,
567
+ file: file ,
568
+ parser_options: parser_options ,
569
+ source: text ,
570
+ caller: __ENV__ ,
571
+ engine: Phoenix.LiveView.HTMLEngine
572
+ )
573
+
574
+ true ->
575
+ EEx . compile_string ( text ,
576
+ file: file ,
577
+ parser_options: parser_options
578
+ )
579
+ end
580
+
581
+ true ->
582
+ Code . string_to_quoted! ( text , parser_options )
527
583
end
528
584
529
585
{ :ok , ast }
530
586
rescue
531
- e in [ EEx.SyntaxError , SyntaxError , TokenMissingError , MismatchedDelimiterError ] ->
587
+ e in [
588
+ EEx.SyntaxError ,
589
+ SyntaxError ,
590
+ TokenMissingError ,
591
+ MismatchedDelimiterError ,
592
+ Phoenix.LiveView.Tokenizer.ParseError
593
+ ] ->
532
594
diagnostic = Diagnostics . from_error ( :error , e , __STACKTRACE__ , file , :no_stacktrace )
533
595
534
596
{ :error , diagnostic }
0 commit comments