Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Dec 7, 2023
1 parent 72d2b81 commit 3c8ae4e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
37 changes: 29 additions & 8 deletions lib/elixir_sense.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ defmodule ElixirSense do
nil

%{begin: begin_pos, end: end_pos} = context ->
metadata = Keyword.get_lazy(options, :metadata, fn -> Parser.parse_string(code, true, true, {line, column}) end)
metadata =
Keyword.get_lazy(options, :metadata, fn ->
Parser.parse_string(code, true, true, {line, column})
end)

env = Metadata.get_env(metadata, {line, column})

Expand Down Expand Up @@ -106,7 +109,10 @@ defmodule ElixirSense do
nil

context ->
metadata = Keyword.get_lazy(options, :metadata, fn -> Parser.parse_string(code, true, true, {line, column}) end)
metadata =
Keyword.get_lazy(options, :metadata, fn ->
Parser.parse_string(code, true, true, {line, column})
end)

env =
Metadata.get_env(metadata, {line, column})
Expand Down Expand Up @@ -139,7 +145,10 @@ defmodule ElixirSense do
[]

context ->
metadata = Keyword.get_lazy(options, :metadata, fn -> Parser.parse_string(code, true, true, {line, column}) end)
metadata =
Keyword.get_lazy(options, :metadata, fn ->
Parser.parse_string(code, true, true, {line, column})
end)

env = Metadata.get_env(metadata, {line, column})

Expand Down Expand Up @@ -205,8 +214,12 @@ defmodule ElixirSense do
@spec suggestions(String.t(), pos_integer, pos_integer, keyword()) :: [Suggestion.suggestion()]
def suggestions(code, line, column, options \\ []) do
hint = Source.prefix(code, line, column)

metadata = Keyword.get_lazy(options, :metadata, fn -> Parser.parse_string(code, true, true, {line, column}) end)

metadata =
Keyword.get_lazy(options, :metadata, fn ->
Parser.parse_string(code, true, true, {line, column})
end)

{text_before, text_after} = Source.split_at(code, line, column)

metadata =
Expand Down Expand Up @@ -281,10 +294,15 @@ defmodule ElixirSense do
]
}
"""
@spec signature(String.t(), pos_integer, pos_integer, keyword) :: Signature.signature_info() | :none
@spec signature(String.t(), pos_integer, pos_integer, keyword) ::
Signature.signature_info() | :none
def signature(code, line, column, options \\ []) do
prefix = Source.text_before(code, line, column)
metadata = Keyword.get_lazy(options, :metadata, fn -> Parser.parse_string(code, true, true, {line, column}) end)

metadata =
Keyword.get_lazy(options, :metadata, fn ->
Parser.parse_string(code, true, true, {line, column})
end)

env = Metadata.get_env(metadata, {line, column})

Expand Down Expand Up @@ -445,7 +463,10 @@ defmodule ElixirSense do
%{
begin: {begin_line, begin_col}
} = context ->
metadata = Keyword.get_lazy(options, :metadata, fn -> Parser.parse_string(code, true, true, {line, column}) end)
metadata =
Keyword.get_lazy(options, :metadata, fn ->
Parser.parse_string(code, true, true, {line, column})
end)

env =
%State.Env{
Expand Down
17 changes: 11 additions & 6 deletions lib/elixir_sense/core/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ defmodule ElixirSense.Core.Parser do
original_source,
original_error,
parser_options
) when is_binary(source) do
)
when is_binary(source) do
case Code.string_to_quoted(source, parser_options) do
{:ok, ast} ->
{:ok, ast, source, original_error}
Expand All @@ -108,7 +109,11 @@ defmodule ElixirSense.Core.Parser do
error_to_report = original_error || {:error, :parse_error}
# dbg(error)

modified_source = if(errors_threshold > 0, do: fix_parse_error(source, cursor_position, error), else: error)
modified_source =
if(errors_threshold > 0,
do: fix_parse_error(source, cursor_position, error),
else: error
)

if is_binary(modified_source) do
do_string_to_ast(
Expand Down Expand Up @@ -141,10 +146,10 @@ defmodule ElixirSense.Core.Parser do
end

def try_fix_line_not_found_by_inserting_marker(
modified_source,
{cursor_line_number, _} = cursor_position
)
when is_integer(cursor_line_number) do
modified_source,
{cursor_line_number, _} = cursor_position
)
when is_integer(cursor_line_number) do
with {:ok, ast, _modified_source, _error} <-
modified_source
|> fix_line_not_found(cursor_line_number)
Expand Down

0 comments on commit 3c8ae4e

Please sign in to comment.