popo63301

popo63301

Hello !

I would like to prevent automatic parentheses while coding in Elixir in VSCode.

I can’t see where to configure that.

Any suggestions ?

Showing Posts 1 to 10

cmo

cmo

The elixir formatter doesn’t have much in the way of options. The idea is that you accept how it is and move on with your life, free from worrying about formatting.

There are libraries, ecto, phoenix etc, that tell it not to add them to some macros, which you need to add to formatter.exs.

If you’re just talking about it creating the second bracket, look in the VS Code settings.

adamu

adamu

The good news is, that’s one of the few customisable options.
The bad news is, you have to specify every function name and arity where you don’t want it to automatically add the parenthesis.

Check out the mix format and Code.format_format_string/2 docs. You’re looking for :locals_without_parens.

See Plug for an example.

opsb

opsb

I’ve also had this issue. The config is in formatter.exs and running mix format works as expected. In vscode though it only works intermittently, the rest of the time it will start adding brackets in again.

BartOtten

BartOtten

Is this about them being added ‘on format’ or during typing? The latter seems like an option which is editor specific….

popo63301

popo63301 OP

I have to precise. It’s annoying for 2 particular situations:

Macros like add and field (in Ecto Migrations and Schemas)

cmo

cmo

Have you got the inpit_deps set in .formatter.exs? The ecto setting should stop that. However, as someone pointed out, it will randomly screw it up every now and then. You have git to save you in those instances.

[
  import_deps: [:ecto, :phoenix, :surface, :nimble_parsec],
  inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs,sface}"],
  subdirectories: ["priv/*/migrations"],
...
Ivor

Ivor

I just ran into this issue and found this thread. Then I added and removed a dep and rearranged the order and then the parentheses went away when I saved. In my case this was for the prop declaration in surface.

Not sure if this was just luck or whether it helped. Can’t reproduce it now because problem is fixed and the parentheses are being removed. Hopefully this helps someone else test it in the future.

fteschke

fteschke

I experienced the same issue.
Similar to @Ivor, resetting the dependencies helped me.

rm mix.lock; rm -rf _build; rm -rf deps; mix deps.get

Before: Parantheses added by mix format, e.g. to ecto field macro.
After: Parantheses no longer added.

I did not test if all the steps were necessary, or if a single one of them might have helped.

greven

greven

This is a bug with ElixirLS and it’s a trick one, it has to do with race conditions.
It’s being tracked here: Formatter doesn't respect formatter.exs while your code is still compiling · Issue #526 · elixir-lsp/elixir-ls · GitHub

rorscharg

rorscharg

Runing MIX_ENV=test mix compile --force and restarting VSCode seems to fix it for me.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
subsaharancoder
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews