Skip to content

Commit 0689270

Browse files
committed
remove env handling from parser
1 parent 38bd07d commit 0689270

File tree

1 file changed

+5
-75
lines changed
  • apps/language_server/lib/language_server

1 file changed

+5
-75
lines changed

apps/language_server/lib/language_server/parser.ex

Lines changed: 5 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ defmodule ElixirLS.LanguageServer.Parser do
163163

164164
case {files[uri], Map.has_key?(state.parse_pids, {uri, current_version})} do
165165
{%Context{parsed_version: ^current_version} = file, _} ->
166-
file = maybe_fix_missing_env(file, position)
167-
168166
{:reply, file, state}
169167

170168
{_, true} ->
@@ -269,8 +267,7 @@ defmodule ElixirLS.LanguageServer.Parser do
269267
queue =
270268
Enum.reduce(state.queue, [], fn
271269
{{^uri, ^parsed_file_version, position}, from}, acc ->
272-
file = maybe_fix_missing_env(updated_file, position)
273-
GenServer.reply(from, file)
270+
GenServer.reply(from, updated_file)
274271
acc
275272

276273
{request, from}, acc ->
@@ -311,49 +308,6 @@ defmodule ElixirLS.LanguageServer.Parser do
311308
source_file.language_id in ["elixir", "eex", "html-eex", "phoenix-heex"]
312309
end
313310

314-
defp maybe_fix_missing_env(%Context{} = file, nil), do: file
315-
316-
defp maybe_fix_missing_env(
317-
%Context{metadata: metadata, flag: flag, source_file: source_file = %SourceFile{}} =
318-
file,
319-
{line, _character} = cursor_position
320-
) do
321-
if Map.has_key?(metadata.lines_to_env, line) do
322-
file
323-
else
324-
case flag do
325-
{_, ^cursor_position} ->
326-
# give up - we already tried
327-
file
328-
329-
{:exact, _} ->
330-
# file does not have parse errors, try to parse again with marker
331-
metadata =
332-
case ElixirSense.Core.Parser.try_fix_line_not_found_by_inserting_marker(
333-
source_file.text,
334-
cursor_position
335-
) do
336-
{:ok, acc} ->
337-
ElixirSense.Core.Metadata.fill(source_file.text, acc)
338-
339-
_ ->
340-
metadata
341-
end
342-
343-
%Context{file | metadata: metadata, flag: {:exact, cursor_position}}
344-
345-
:not_parsable ->
346-
# give up - no support in fault tolerant parser
347-
file
348-
349-
{f, _cursor_position} when f in [:not_parsable, :fixed] ->
350-
# reparse with cursor position
351-
{flag, ast, metadata} = fault_tolerant_parse(source_file, cursor_position)
352-
%Context{file | ast: ast, metadata: metadata, flag: flag}
353-
end
354-
end
355-
end
356-
357311
def do_parse(
358312
%Context{source_file: source_file = %SourceFile{}, path: path} = file,
359313
cursor_position \\ nil
@@ -363,9 +317,8 @@ defmodule ElixirLS.LanguageServer.Parser do
363317
{flag, ast, metadata} =
364318
if ast do
365319
# no syntax errors
366-
metadata =
367-
MetadataBuilder.build(ast)
368-
|> fix_missing_env(source_file.text, cursor_position)
320+
acc = MetadataBuilder.build(ast)
321+
metadata = ElixirSense.Core.Metadata.fill(source_file.text, acc)
369322

370323
{{:exact, cursor_position}, ast, metadata}
371324
else
@@ -397,9 +350,8 @@ defmodule ElixirLS.LanguageServer.Parser do
397350

398351
case ElixirSense.Core.Parser.string_to_ast(source_file.text, options) do
399352
{:ok, ast, modified_source, _error} ->
400-
metadata =
401-
MetadataBuilder.build(ast)
402-
|> fix_missing_env(modified_source, cursor_position)
353+
acc = MetadataBuilder.build(ast)
354+
metadata = ElixirSense.Core.Metadata.fill(modified_source, acc)
403355

404356
{{:fixed, cursor_position}, ast, metadata}
405357

@@ -427,28 +379,6 @@ defmodule ElixirLS.LanguageServer.Parser do
427379
{{:not_parsable, cursor_position}, @dummy_ast, @dummy_metadata}
428380
end
429381

430-
defp fix_missing_env(acc, source, nil), do: ElixirSense.Core.Metadata.fill(source, acc)
431-
432-
defp fix_missing_env(acc, source, {line, _} = cursor_position) do
433-
acc =
434-
if Map.has_key?(acc.lines_to_env, line) do
435-
acc
436-
else
437-
case ElixirSense.Core.Parser.try_fix_line_not_found_by_inserting_marker(
438-
source,
439-
cursor_position
440-
) do
441-
{:ok, acc} ->
442-
acc
443-
444-
_ ->
445-
acc
446-
end
447-
end
448-
449-
ElixirSense.Core.Metadata.fill(source, acc)
450-
end
451-
452382
defp get_path(uri) do
453383
case uri do
454384
"file:" <> _ ->

0 commit comments

Comments
 (0)