Skip to content

Commit 3e20c00

Browse files
authored
fix: correctly format files (#128)
1 parent 9517615 commit 3e20c00

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Diff for: lib/next_ls.ex

+13-9
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,18 @@ defmodule NextLS do
157157

158158
def handle_request(%TextDocumentDocumentSymbol{params: %{text_document: %{uri: uri}}}, lsp) do
159159
symbols =
160-
try do
161-
lsp.assigns.documents[uri]
162-
|> Enum.join("\n")
163-
|> NextLS.DocumentSymbol.fetch()
164-
rescue
165-
e ->
166-
GenLSP.error(lsp, Exception.format_banner(:error, e, __STACKTRACE__))
167-
nil
160+
if Path.extname(uri) in [".ex", ".exs"] do
161+
try do
162+
lsp.assigns.documents[uri]
163+
|> Enum.join("\n")
164+
|> NextLS.DocumentSymbol.fetch()
165+
rescue
166+
e ->
167+
GenLSP.error(lsp, Exception.format_banner(:error, e, __STACKTRACE__))
168+
nil
169+
end
170+
else
171+
nil
168172
end
169173

170174
{:reply, symbols, lsp}
@@ -219,7 +223,7 @@ defmodule NextLS do
219223
dispatch(lsp.assigns.registry, :runtimes, fn entries ->
220224
for {runtime, %{uri: wuri}} <- entries, String.starts_with?(uri, wuri) do
221225
with {:ok, {formatter, _}} <-
222-
Runtime.call(runtime, {Mix.Tasks.Format, :formatter_for_file, [".formatter.exs"]}),
226+
Runtime.call(runtime, {Mix.Tasks.Format, :formatter_for_file, [URI.parse(uri).path]}),
223227
{:ok, response} when is_binary(response) or is_list(response) <-
224228
Runtime.call(runtime, {Kernel, :apply, [formatter, [Enum.join(document, "\n")]]}) do
225229
{:reply,

0 commit comments

Comments
 (0)