Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant whitespace from symbol name #1052

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do

type_name =
type_name
|> String.replace("\n", "")
|> String.replace(~r/,*\n\s*/u, fn
"," <> _ -> ", "
_ -> ""
end)

type = if type_kind in [:type, :typep, :opaque], do: :class, else: :event

Expand Down Expand Up @@ -220,7 +223,12 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
{defname, location, [{:when, _, [{_, head_location, _} = fn_head, _]} | _]}
)
when defname in @defs do
name = Macro.to_string(fn_head) |> String.replace("\n", "")
name =
Macro.to_string(fn_head)
|> String.replace(~r/,*\n\s*/u, fn
"," <> _ -> ", "
_ -> ""
end)

%Info{
type: if(defname in @macro_defs, do: :constant, else: :function),
Expand All @@ -235,7 +243,12 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
# Function, macro, delegate
defp extract_symbol(_current_module, {defname, location, [{_, head_location, _} = fn_head | _]})
when defname in @defs do
name = Macro.to_string(fn_head) |> String.replace("\n", "")
name =
Macro.to_string(fn_head)
|> String.replace(~r/,*\n\s*/u, fn
"," <> _ -> ", "
_ -> ""
end)

%Info{
type: if(defname in @macro_defs, do: :constant, else: :function),
Expand Down
67 changes: 63 additions & 4 deletions apps/language_server/test/providers/document_symbols_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
def fun_multiple_when(_other) do
:something_else
end
def fun_multiline_args(
foo,
bar
)
when is_atom(foo),
do: foo
def fun_multiline_args(
foo,
bar
),
do: bar
end
]

Expand Down Expand Up @@ -196,12 +207,22 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
"end" => %{"character" => 37, "line" => 31},
"start" => %{"character" => 12, "line" => 31}
}
},
%Protocol.DocumentSymbol{
children: [],
kind: 12,
name: "def fun_multiline_args(foo, bar)"
},
%Protocol.DocumentSymbol{
children: [],
kind: 12,
name: "def fun_multiline_args(foo, bar)"
}
],
kind: 2,
name: "MyModule",
range: %{
"end" => %{"character" => 9, "line" => 34},
"end" => %{"character" => 9, "line" => 45},
"start" => %{"character" => 6, "line" => 1}
},
selectionRange: %{
Expand Down Expand Up @@ -238,6 +259,17 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
after
:ok
end
def fun_multiline_args(
foo,
bar
)
when is_atom(foo),
do: foo
def fun_multiline_args(
foo,
bar
),
do: bar
end
]

Expand All @@ -250,7 +282,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
kind: 2,
location: %{
range: %{
"end" => %{"character" => 9, "line" => 24},
"end" => %{"character" => 9, "line" => 35},
"start" => %{"character" => 6, "line" => 1}
}
}
Expand Down Expand Up @@ -344,6 +376,16 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
}
},
containerName: "MyModule"
},
%Protocol.SymbolInformation{
kind: 12,
name: "def fun_multiline_args(foo, bar)",
containerName: "MyModule"
},
%Protocol.SymbolInformation{
kind: 12,
name: "def fun_multiline_args(foo, bar)",
containerName: "MyModule"
}
]} = DocumentSymbols.symbols(uri, parser_context, false)
end
Expand Down Expand Up @@ -1215,6 +1257,10 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
@type my_with_args_when(key, value) :: [{key, value}] when value: integer
@type abc
@type
@type my_with_multiline_args(
key,
value
) :: [{key, value}]
end
"""

Expand Down Expand Up @@ -1271,6 +1317,11 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
children: [],
kind: 22,
name: "@type"
},
%Protocol.DocumentSymbol{
children: [],
kind: 5,
name: "@type my_with_multiline_args(key, value)"
}
],
kind: 2,
Expand All @@ -1292,6 +1343,10 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
@type my_with_args_when(key, value) :: [{key, value}] when value: integer
@type abc
@type
@type my_with_multiline_args(
key,
value
) :: [{key, value}]
end
"""

Expand Down Expand Up @@ -1348,6 +1403,11 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
kind: 22,
name: "@type",
containerName: "MyModule"
},
%Protocol.SymbolInformation{
kind: 5,
name: "@type my_with_multiline_args(key, value)",
containerName: "MyModule"
}
]} = DocumentSymbols.symbols(uri, parser_context, false)
end
Expand Down Expand Up @@ -2556,8 +2616,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do

parser_context = ParserContextBuilder.from_string(text)

assert {:ok, []} =
DocumentSymbols.symbols(uri, parser_context, true)
assert {:ok, []} = DocumentSymbols.symbols(uri, parser_context, true)
end

test "returns def and defp as a prefix" do
Expand Down
Loading