@@ -46,6 +46,8 @@ defmodule ElixirLS.LanguageServer.Parser do
46
46
{ :ok , % { files: % { } , debounce_refs: % { } } }
47
47
end
48
48
49
+ # TODO terminate
50
+
49
51
@ impl true
50
52
def handle_cast ( { :closed , uri } , state = % { files: files , debounce_refs: debounce_refs } ) do
51
53
{ maybe_ref , updated_debounce_refs } = Map . pop ( debounce_refs , uri )
@@ -58,8 +60,7 @@ defmodule ElixirLS.LanguageServer.Parser do
58
60
end
59
61
60
62
def handle_cast ( { :parse_with_debounce , uri , source_file } , state ) do
61
- # TODO check source_file.language_id
62
- state = if String . ends_with? ( uri , [ ".ex" , ".exs" , ".eex" ] ) do
63
+ state = if should_parse? ( uri , source_file ) do
63
64
state = update_in ( state . debounce_refs [ uri ] , fn old_ref ->
64
65
if old_ref do
65
66
Process . cancel_timer ( old_ref , info: false )
@@ -80,7 +81,7 @@ defmodule ElixirLS.LanguageServer.Parser do
80
81
}
81
82
end )
82
83
else
83
- Logger . debug ( "Not parsing #{ uri } with debounce" )
84
+ Logger . debug ( "Not parsing #{ uri } with debounce: languageId #{ source_file . language_id } " )
84
85
state
85
86
end
86
87
@@ -89,7 +90,7 @@ defmodule ElixirLS.LanguageServer.Parser do
89
90
90
91
@ impl true
91
92
def handle_call ( { :parse_immediate , uri , source_file } , _from , % { files: files , debounce_refs: debounce_refs } = state ) do
92
- { reply , state } = if String . ends_with ?( uri , [ ".ex" , ".exs" , ".eex" ] ) do
93
+ { reply , state } = if should_parse ?( uri , source_file ) do
93
94
{ maybe_ref , updated_debounce_refs } = Map . pop ( debounce_refs , uri )
94
95
if maybe_ref do
95
96
Process . cancel_timer ( maybe_ref , info: false )
@@ -103,7 +104,7 @@ defmodule ElixirLS.LanguageServer.Parser do
103
104
# current version already parsed
104
105
{ file , state }
105
106
_other ->
106
- Logger . debug ( "Parsing #{ uri } immediately" )
107
+ Logger . debug ( "Parsing #{ uri } immediately: languageId #{ source_file . language_id } " )
107
108
# overwrite everything
108
109
file = % Context {
109
110
source_file: source_file ,
@@ -119,7 +120,7 @@ defmodule ElixirLS.LanguageServer.Parser do
119
120
{ file , state }
120
121
end
121
122
else
122
- Logger . debug ( "Not parsing #{ uri } immediately" )
123
+ Logger . debug ( "Not parsing #{ uri } immediately: languageId #{ source_file . language_id } " )
123
124
# not parsing - respond with empty struct
124
125
reply = % Context {
125
126
source_file: source_file ,
@@ -136,9 +137,10 @@ defmodule ElixirLS.LanguageServer.Parser do
136
137
{ :parse_file , uri } ,
137
138
% { files: files , debounce_refs: debounce_refs } = state
138
139
) do
139
- Logger . debug ( "Parsing #{ uri } after debounce" )
140
+ file = Map . fetch! ( files , uri )
141
+ Logger . debug ( "Parsing #{ uri } after debounce: languageId #{ file . source_file . language_id } " )
140
142
141
- updated_file = Map . fetch! ( files , uri )
143
+ updated_file = file
142
144
|> do_parse ( )
143
145
144
146
updated_files = Map . put ( files , uri , updated_file )
@@ -150,8 +152,12 @@ defmodule ElixirLS.LanguageServer.Parser do
150
152
{ :noreply , state }
151
153
end
152
154
155
+ defp should_parse? ( uri , source_file ) do
156
+ String . ends_with? ( uri , [ ".ex" , ".exs" , ".eex" ] ) or source_file . language_id in [ "elixir" , "eex" , "html-eex" ]
157
+ end
158
+
153
159
defp do_parse ( % Context { source_file: source_file , path: path } = file ) do
154
- { ast , diagnostics } = parse_file ( source_file . text , path )
160
+ { ast , diagnostics } = parse_file ( source_file . text , path , source_file . language_id )
155
161
156
162
metadata = if ast do
157
163
acc = MetadataBuilder . build ( ast )
@@ -170,11 +176,7 @@ defmodule ElixirLS.LanguageServer.Parser do
170
176
case uri do
171
177
"file:" <> _ -> SourceFile.Path . from_uri ( uri )
172
178
_ ->
173
- # TODO think if this is sane
174
- extension = uri
175
- |> String . split ( "." )
176
- |> List . last
177
- "nofile." <> extension
179
+ "nofile"
178
180
end
179
181
end
180
182
@@ -184,10 +186,7 @@ defmodule ElixirLS.LanguageServer.Parser do
184
186
|> Server . parser_finished ( )
185
187
end
186
188
187
-
188
- # TODO uri instead of file?
189
- # defp parse_file(_text, nil), do: {nil, []}
190
- defp parse_file ( text , file ) do
189
+ defp parse_file ( text , file , language_id ) do
191
190
{ result , raw_diagnostics } =
192
191
Build . with_diagnostics ( [ log: false ] , fn ->
193
192
try do
@@ -196,7 +195,7 @@ defmodule ElixirLS.LanguageServer.Parser do
196
195
columns: true
197
196
]
198
197
199
- ast = if String . ends_with? ( file , ".eex" ) do
198
+ ast = if is_binary ( file ) and String . ends_with? ( file , ".eex" ) or language_id in [ "eex" , "html-eex" ] do
200
199
EEx . compile_string ( text ,
201
200
file: file ,
202
201
parser_options: parser_options
0 commit comments