ElixisLS in VS Code does not format *.ex, *.exs files

Hi,

I cannot get VS Code with the elixir-ls extension to format my code.
Only thru “mix format” command.

Environment:
Erlang/OTP 23 [erts-11.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.11.3 (compiled with Erlang/OTP 23)
elixir-lsp.elixir-ls-0.6.2

I even tried after recompiling elixirls with my current elixir installation.
I have configured VS Code settings.json, to specify ‘elixir-lsp.elixir-ls’ as the default formatter.

Any ideas what other things I need to tweak in order for it to work?

Best regards,
Gusti.

Hi :wave:! Are you running the “Format Command” in VSCode (defaults to alt+shift+f)?

If that isn’t working then try running through the debugging steps: https://github.com/elixir-lsp/vscode-elixir-ls/#debugging

1 Like

I tried with keyboard secuences alt+shift+f.
I also tried with Ctrl+shift+p, then “Format document”

Nothing happens.

View output:

Started ElixirLS v0.6.2

Elixir version: “1.11.3 (compiled with Erlang/OTP 23)”

Erlang version: “23”

ElixirLS compiled with Elixir 1.8.2 and erlang 21

MIX_ENV: test

MIX_TARGET:

[Info - 12:40:35 PM] Compile took 550 milliseconds

[Info - 12:40:35 PM] [ElixirLS WorkspaceSymbols] Indexing…

The toggle developer tools output is:

electron/js2c/renderer_init.js:15 (electron) Security Warning: webFrame.executeJavaScript was called without worldSafeExecuteJavaScript enabled. This is considered unsafe. worldSafeExecuteJavaScript will be enabled by default in Electron 12.
log @ electron/js2c/renderer_init.js:15
electron/js2c/renderer_init.js:135 Electron Security Warning (Insecure Content-Security-Policy) This renderer process has either no Content Security
Policy set or a policy with “unsafe-eval” enabled. This exposes users of
this app to unnecessary security risks.

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged.
(anonymous) @ electron/js2c/renderer_init.js:135
workbench.html:1 A cookie associated with a cross-site resource at https://open-vsx.org/ was set without the SameSite attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
webviewElement.ts:90 [Embedded Page] %cElectron Security Warning (enableBlinkFeatures) font-weight: bold; This renderer process has additional “enableBlinkFeatures”
enabled. This exposes users of this app to some security risk. If you do not
need this feature, you should disable it.

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged.
webviewElement.ts:90 [Embedded Page] (electron) Security Warning: webFrame.executeJavaScript was called without worldSafeExecuteJavaScript enabled. This is considered unsafe. worldSafeExecuteJavaScript will be enabled by default in Electron 12.
webviewElement.ts:90 [Embedded Page] %cElectron Security Warning (Insecure Content-Security-Policy) font-weight: bold; This renderer process has either no Content Security
Policy set or a policy with “unsafe-eval” enabled. This exposes users of
this app to unnecessary security risks.

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged.
webviewElement.ts:90 [Embedded Page] %cElectron Security Warning (enableBlinkFeatures) font-weight: bold; This renderer process has additional “enableBlinkFeatures”
enabled. This exposes users of this app to some security risk. If you do not
need this feature, you should disable it.

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged.
webviewElement.ts:90 [Embedded Page] (electron) Security Warning: webFrame.executeJavaScript was called without worldSafeExecuteJavaScript enabled. This is considered unsafe. worldSafeExecuteJavaScript will be enabled by default in Electron 12.
webviewElement.ts:90 [Embedded Page] %cElectron Security Warning (Insecure Content-Security-Policy) font-weight: bold; This renderer process has either no Content Security
Policy set or a policy with “unsafe-eval” enabled. This exposes users of
this app to unnecessary security risks.

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged.
log.ts:191 WARN Settings pattern “workbench.fontAliasing” doesn’t match any settings
log.ts:191 WARN Settings pattern “settingsSync." doesn’t match any settings
log.ts:191 WARN Settings pattern "sync.
” doesn’t match any settings

But these electron warnings were there at the start of VS Code, before I tried to format.

As I could not get it work, I created a VSCode Task, to execute “mix format”, and assigned it a keyboard sequence.
So, instead of pressing just Ctrl+S to save my file and format it, I need to press another key sequence after the save. It is not terribly bad. It’s a workaround, until somebody enlightens me.

Best regards,
Gusti.

Hi, I experience the same problem, the format command from VSCode does not trigger mix format. When running mix format from the CLI this goes well.

My Elixir-ls output log looks fine:

Started ElixirLS v0.8.1
Elixir version: "1.12.2 (compiled with Erlang/OTP 24)"
Erlang version: "24"
ElixirLS compiled with Elixir 1.10.4 and erlang 22
MIX_ENV: test
MIX_TARGET: 
Compiling 5 files (.ex)
Generated islands_engine app
[Info  - 8:14:41 AM] Compile took 1197 milliseconds
[Info  - 8:14:41 AM] [ElixirLS WorkspaceSymbols] Indexing...
MIX_ENV: test
MIX_TARGET: 
[Info  - 8:14:41 AM] [ElixirLS WorkspaceSymbols] Module discovery complete
[Info  - 8:14:41 AM] [ElixirLS WorkspaceSymbols] 22 callbacks added to index
[Info  - 8:14:41 AM] [ElixirLS WorkspaceSymbols] 171 modules added to index
[Info  - 8:14:42 AM] Compile took 716 milliseconds
[Info  - 8:14:42 AM] [ElixirLS Dialyzer] Checking for stale beam files
[Info  - 8:14:42 AM] [ElixirLS Dialyzer] Found 11 changed files in 17 milliseconds
[Info  - 8:14:42 AM] [ElixirLS WorkspaceSymbols] 281 types added to index
[Info  - 8:14:42 AM] [ElixirLS Dialyzer] Analyzing 11 modules: [Collectable, Enumerable, IEx.Info, Inspect, IslandsEngine, IslandsEngine.Application, IslandsEngine.Coordinate, IslandsEngine.Guesses, IslandsEngine.Island, List.Chars, String.Chars]
[Info  - 8:14:42 AM] [ElixirLS Dialyzer] Analysis finished in 422 milliseconds
[Info  - 8:14:42 AM] Dialyzer analysis is up to date
[Info  - 8:14:42 AM] [ElixirLS Dialyzer] Writing manifest...
[Info  - 8:14:43 AM] [ElixirLS Dialyzer] Done writing manifest in 597 milliseconds.
[Info  - 8:14:44 AM] [ElixirLS WorkspaceSymbols] 3964 functions added to index

What else should I check into?

I’d bounce over to Issues · elixir-lsp/elixir-ls · GitHub to see if there are any similar issues logged (and create one if not).

Beware, that the code is not formatted if there are syntax errors.

1 Like

FWIW I’ve been having trouble too (formatter.exs seems to not be respected) and rolled back to the previous version, I just haven’t been able to gather enough details to post a helpful issue yet :slight_smile: It doesn’t seem related to the existing issue about formatter.exs during compilation, but I need to double check first.

1 Like

Try ctrl + shift + I. Check File, Preferences, Keyboard shortcuts.