-
Notifications
You must be signed in to change notification settings - Fork 194
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
Formatting does not work with phoenix and neovim (with vim-lsp) #235
Comments
I think this is some sort of race condition around how the CWD is managed. I think it affects vscode-elixir-ls as well. I think that to resolve this ElixirLS needs to be smarter about choosing the CWD for formatting. You may also want to look to see if your A good debugging step might be to log (at level "info") what the CWD is when the formatting starts. |
I added the log in changes below: diff --git a/apps/language_server/lib/language_server/providers/formatting.ex b/apps/language_server/lib/language_server/providers/formatting.ex
index 4534cf5..e861f37 100644
--- a/apps/language_server/lib/language_server/providers/formatting.ex
+++ b/apps/language_server/lib/language_server/providers/formatting.ex
@@ -1,12 +1,14 @@
defmodule ElixirLS.LanguageServer.Providers.Formatting do
import ElixirLS.LanguageServer.Protocol, only: [range: 4]
- alias ElixirLS.LanguageServer.SourceFile
+ alias ElixirLS.LanguageServer.{JsonRpc, SourceFile}
def supported? do
function_exported?(Code, :format_string!, 2)
end
def format(source_file, uri, project_dir) do
+ JsonRpc.log_message(:info, "formatting file (#{uri}) on project directory (#{project_dir})")
+
if can_format?(uri, project_dir) do
file = SourceFile.path_from_uri(uri) |> Path.relative_to(project_dir)
opts = formatter_opts(file) Got the result when formatting start:
|
I investigate more on elixir side. I patch value from inspect diff --git a/lib/mix/lib/mix/tasks/format.ex b/lib/mix/lib/mix/tasks/format.ex
index b2393e686..12db1faa5 100644
--- a/lib/mix/lib/mix/tasks/format.ex
+++ b/lib/mix/lib/mix/tasks/format.ex
@@ -296,7 +296,7 @@ defp assert_valid_dep_and_fetch_path(dep, deps_paths) when is_atom(dep) do
:error ->
Mix.raise(
- "Unknown dependency #{inspect(dep)} given to :import_deps in the formatter configuration. " <>
+ "Unknown dependency #{inspect(dep)} in the #{inspect(deps_paths)} given to :import_deps in the formatter configuration. " <>
"The dependency is not listed in your mix.exs for environment #{inspect(Mix.env())}"
)
end After call formatting. The result is
|
I think |
I'm more interested in |
Do you have instructions for a neovim setup that I could follow? |
@axelson you needs to install vim-lsp and vim-lsp-settings. And setting NOTE
|
Add diff --git a/lib/mix/lib/mix/tasks/format.ex b/lib/mix/lib/mix/tasks/format.ex
index b2393e686..b82a68334 100644
--- a/lib/mix/lib/mix/tasks/format.ex
+++ b/lib/mix/lib/mix/tasks/format.ex
@@ -297,7 +297,7 @@ defmodule Mix.Tasks.Format do
:error ->
Mix.raise(
"Unknown dependency #{inspect(dep)} given to :import_deps in the formatter configuration. " <>
- "The dependency is not listed in your mix.exs for environment #{inspect(Mix.env())}"
+ "The dependency is not listed in your mix.exs for environment #{inspect(Mix.env())}: #{inspect(Mix.Project.deps_path())}"
)
end
end format raise an exception with deps_path |
I would like to update this issue on neovim + vim-lsp that it's not gonna happens all of time that I called cc @axelson |
@wingyplus are you getting an error similar to #252 ? |
@axelson I found it sometimes while adding a new dependency into |
@axelson I just try to fix by caching formatter opts after build is done. It's seems the formatting issue is getting more stable. The initial branch for discussing is here https://github.com/wingyplus/elixir-ls/tree/experiment-formatter. Good to see your feedback. |
I starting to understand this issue. The @axelson @lukaszsamson What do you think? |
Remove deps cached every build can cause deps cached disappear in :ets. Fixes by move calling Mix.Project.clear_deps_cache/0 only when deps in mix.exs was change. Fixes elixir-lsp#235
I wrote a patch to show what am I thinking. Suggestions are welcome. ^_^ |
Remove deps cached every build can cause deps cached disappear in :ets. Fixes by move calling Mix.Project.clear_deps_cache/0 only when deps in mix.exs was change. Fixes elixir-lsp#235
Environment
Description
The bug happens when I generate phoenix project. After I open file inside project and try formatting with
LspDocumentFormat
.vim-lsp
returns an errors (described in Reproduce Steps below).Reproduce Steps
mix phx.new --no-html --no-webpack --no-gettext lsp_formatter
and fetch and install dependencies.lib/lsp_formatter.ex
withnvim
. Waiting elixir-ls to compile.LspDocumentFormat
, received an error that capture from vim lsp log:subdirectories
in.formatter.exs
:import_deps
in.formatter.exs
:More information
I try it with vscode without any comments in
.formatter.exs
. It's works fine.Run
mix format
. It's works fine.The text was updated successfully, but these errors were encountered: