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

jswny
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
IVR
Hi all, I’ve seen a number of related threads in the past, but I’d still be very curious to hear an up-to-date opinion on this topic. I...
New
jer
I’ve been using umbrellas for a while, and generally started off (on greenfield projects at least) by isolating subapps based on clearly ...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
jesse
Hi everyone, I hesitated to post this here because I don’t want you to think I’m spamming, but I’ve been working on a Platform-as-a-Serv...
New
AstonJ
If so I (and hopefully others!) might have some tips for you :slight_smile: But first, please say which area you’re finding most challen...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
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

We're in Beta

About us Mission Statement