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

Jayshua
I recently came across the javascript library htmx. It reminded me a lot of liveview so I thought the community here might be interested....
New
Donovan
Hello everyone, I’m so glad to have discovered this awesome community. Thanks for creating it! This is my second post, and apologies for...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
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
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
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
Owens
Hello all, I am developing a new mobile app with Flutter frontend and Phoenix backend. The mobile app has real-time task management and c...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement