thiagomajesk

thiagomajesk

Elixir file formatting with vscode (removing whitespaces and documentation)

Hello everyone!

A little while ago I opened this issue in the vscode repository:
Make distinction when removing leading whitespace from trailing whitespace · Issue #113235 · microsoft/vscode · GitHub, which I think would help improve the way we edit Elixir files.

This is a problem that I and my coworkers noticed some time ago, where it’s not possible to use a file formatter that trims whitespace because vscode would remove trailing and leading whitespaces butchering Elixir’s markdown documentation in the process.

I was reluctant to post here at first, but if you use Elixir and vscode, please consider upvoting this request so it can get picked up by the dev team (we have one more day to get at least 20 upvotes).

Cheers!

Most Liked

thiagomajesk

thiagomajesk

Wow, it seems that there’s a lot of confusion going on…
I recorded a gif to better explain, but you could also test it locally by doing the same steps:

  • Install elixir-ls
  • Add the config "files.trimTrailingWhitespace": true and "editor.formatOnSave": true
  • Add documentation to a function with multiple lines
  • Save the file and see the markup getting messed up because vscode removes all spaces around a line and there’s no counterpart option to prevent that (like only removing spaces at the start of the line and not the end)

https://gifyu.com/image/Z5fz

lud

lud

I think there is some confusion about the “leading” word. The only “leading” whitespace on your 3rd image is the one that is still there on the 4th image.

Whitespace is considered “per line”. The editor doesn’t care about what the code means, it just removes whitespace at the end of the line, except for the line break.

On line 1 there is none leading or trailing.
On line 2, there are only spaces, and no content. The editors considers this space to be at the end of the line (trailing), and removes it.
On line 3 there are two leading spaces before @doc, and they are still there after the cleanup.
On line 4, there are two leading spaces too, before “Some”, and they are still there. After the content (after the word “here”) there is trailing whitespace, and it gets removed.
And so on.

So no, the editor does not consider all whistespace as trailing. It does not remove leading whitespace.

thiagomajesk

thiagomajesk

Thanks to everyone that contributed, we reached our goal!

While we are here jousting about semantics, there are at least 27 people (so far) that shared our pain, regardless of the “proposed” solution.

I hope this gets picked up and the team back at Microsoft can propose a nice solution that helps us solve this issue. So, thanks to you all!

Where Next?

Popular in Discussions Top

cvkmohan
The upcoming Phoenix 1.6 release looks very interesting. Became a habit to watch the commits - and - what they are bringing in. phx.gen...
New
pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
mmport80
I have put far too much effort into Dialyzer over the last year or so - and basically - I doubt it’s worth the effort. It’s not as easy ...
New
arcanemachine
https://nitter.net/josevalim/status/1744395345872683471 https://twitter.com/josevalim/status/1744395345872683471
New
ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
ejpcmac
I have discovered Nix last month and I am currently on my way to migrating to it—both on macOS at home and the full NixOS distrubution at...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New
Qqwy
I would like to spark a discussion about the static access operator: .. For whom does not know: it is used in Elixir to access fields of...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement