thiagomajesk

thiagomajesk

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!

Showing Posts 1 to 10

NobbZ

NobbZ

I don’t understand the issue.

Can you provide an example where whitespace is removed where it shouldn’t?

axelson

axelson

Scenic Core Team

Can you specify exactly what you mean by leading white space?

thiagomajesk

thiagomajesk OP

@NobbZ, @axelson it’s very simple actually. Take the issue example itself:

@doc """
My function documentation markdown.
This will be part of the first line because the "line break" was removed when saved
"""
def hello(), do: :world

If you mark the option to trim whitespace in vscode today, it will remove whitespace from the line start and line ends (leading and trailing). This would result in the documentation of the hello function to be on the same line like this:

My function documentation markdown. This will be part of the first line because the "line break" was removed when saved

This happens because whitespace works as line breaks and vscode only has one option that removes all whitespace (around). Usually, you want to disable this option to work with markdown files so your markup doesn’t get butchered.

You can test this by enabling format on save/ trim on save in vscode, add documentation to a function, and then visualize it with elixir-ls (for example). The markdown won’t be properly formatted because of the lack of whitespaces (line breaks).

LostKobrakai

LostKobrakai

How is this related to leading vs. trailing whitespace though? Only trailing whitespace (two spaces) is converted to a line break in markdown.

NobbZ

NobbZ

I do not see any leading or trailing whitespace.

Also I do not see how existing leading whitespace would change anything.

defmodule M do
  @doc """
  My function documentation markdown.
  This will be part of the first line because the "line break" was removed when saved
  """
  def hello(), do: :world
end

If you have this construct, neither VScode, nor the elixir formatter will remove any leading whitespace, but still the documentation will be rendered on a single line.

So I still do not see a problem, and I never have observed leading whitespace getting removed by VScode. Though language specific formatters might of course reformat into something that has more or less whitespace leading, but that is nothing VScode can do about, and neither should change any semantics by that.

A thing I would indeed give you support for, if that was an issue, is that within a “string” whitespace should always be preserved by VScode and/or formatters, as removing whitespace there changes semantics.

thiagomajesk

thiagomajesk OP

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

NobbZ

NobbZ

This animation confirmed, that your problem is not removal of leading whitespace, but trailing whitespace within a string literal.

As I’ve said already, open a report that describes the correct problem and you’ll get the votes.

Your video did not show any modification of leading whitespace.

lud

lud

Well in markdown a single line break is converted to a simple space in HTML. There were “flavours” of markdown that changed this behaviour. Github did that one. And it was really bad as most of the time your HTML is not displayed with monospaced fonts.

If you want the line break in the docs, just make two paragraphs:

@doc """
My function documentation markdown.

This will be part of the first line because the "line break" was removed when saved
"""

Edit: oh no, I understand now, you want to keep two spaces at the end of the line. Sorry. I’ve never liked this markdown feature as it is not visible when writing. I would like markdown to have a symbol for linebreaks, like -/-, but I guess you can always try with <br/> ; i don’t know if ex_doc will escape it though.

thiagomajesk

thiagomajesk OP

@NobbZ When exactly did you get the impression I was talking about leading whitespaces only?
If you read the Github issue you’ll see that I talk about how in vs code we have an option to remove trailing whitespace, that actually removes trailing and leading whitespace.

If we have control over what kind of whitespace we can remove for each file extension (in this case, .ex), this wouldn’t be a problem with embedded markdown. Actually, this is useful not just for Elixir files.

As I’ve said already, open a report that describes the correct problem and you’ll get the votes.

I’m not a native English speaker, though. So, please… How could I be more clear than this?
The very first paragraph of the issue says:

Hi, I’ve noticed that there’s only the files.trimTrailingWhitespace without a files.trimLeadingWhitespace counterpart. This has been a problem for editing files that mix markdown documentation with another syntax for a while.

And the very last also says:

If possible, I’d like to be able to remove only leading or trailing whitespace

Perhaps you don’t agree with the solution or were expecting a more elaborate description, but to say that this does not describe the “correct” problem, honestly, I don’t even know how to respond to that.

@lud Exactly! And this is not currently possible because vs code treats both leading and trailing whitespace under the same option.

lud

lud

There is no “leading” whitespace involved in this problem. The problem is just that vscode removes two trailing spaces. It does not remove any leading space otherwise your code would not be indented.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
_mfierro
Hello, I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
nseaSeb
AcmeScript — Writing JS hooks as if I were still using Elixir I’ve been having fun building a little something over the last few days: Ac...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews