avh4 / elm-format

elm-format formats Elm source code according to a standard set of rules based on the official Elm Style Guide
BSD 3-Clause "New" or "Revised" License
1.31k stars 145 forks source link

Not working with visual studio code when installed from npm #390

Open Kurren123 opened 7 years ago

Kurren123 commented 7 years ago

On the vs code terminal: npm install elm-format -g Then reset the terminal. elm-format works fine when opened in CMD or powershell from any folder. I can use it to format any elm file. However when I select elm format from the vs code command palette (ctrl+shift+p) I get the following error:

image

Nothing actually happens to the code file. Also format on save doesn't work (despite the option being turned on from the workspace settings).

Thanks!

avh4 commented 7 years ago

Which VSCode Elm/elm-format plugin(s) are you using? If you are able to run elm-format from your terminal, then this seems like an issue with the plugin.

Kurren123 commented 7 years ago
VS Code 1.14.2
elm 0.12.1
elm-format 0.1.0
travisstaloch commented 7 years ago

I'm having the same issue. I have installed elm-format with npm, can use elm-format from the command line, have verified that C:\Users\Travis\AppData\Roaming\npm\elm-format.cmd exists and that C:\Users\Travis\AppData\Roaming\npm is in my PATH. I tried restarting vscode and even logging off but vscode is still saying:

Unable to execute elm-format. Please make sure you have elm-format on your PATH

Any ideas are greatly appreciated. Would be great to be able to use elm formatting while I'm learning elm.

oren-l commented 6 years ago

You can use elm vscode plugin for formatting elm, after you install it use Alt+Shift+F (shortcut for "Format Document") to run elm-format.

The instructions in the README are out of date, elm-format has been unpublished from vscode-marketplace

erikhofer commented 5 years ago

I still have this problem, is there any solution/workaround?

@oren-l this is happening with the elm vscode plugin, not elm-format. It still uses the elm-format package (not vscode plugin).

Swiftaff commented 5 years ago

I have a workaround if this is the same issue as #408

jpierson commented 5 years ago

I'm having this same issue on a new project. Something tells me I've solved this before with some VSCode specific configuration but nothing I've tried so far is working yet.

jpierson commented 5 years ago

Maybe this us also related to this issue reported for the Elm extension for VSCode? https://github.com/Krzysztof-Cieslak/vscode-elm/issues/275

rokit commented 5 years ago

Any workaround for formatting?

razzeee commented 5 years ago

If your running linux, you need to add the full path to your elm-format like /home/razze/.nvm/versions/node/v10.15.3/bin/elm-format

As the path environment that vscode initalizes when you create a child_process with node does not include the nvm (or node?) part of your path variable...

Bernardoow commented 4 years ago

Same problem here =/

I Fixed my problem doing this I upgraded my version of elm-format and its come works now.

PS I changed npm to yarn.

I used yarn to install global follwing this link Yarn

1. yarn config set prefix ~/.yarn  (To created a myglobal yarn directory)
2. sudo yarn global add elm-format
3. ls ~/.yarn
4. elm-format
mwaf commented 3 years ago

I encountered this issue out of nowhere, tried reinstalling via npm, restarting everything, full path in extension setting but it just wouldn't work.

Turns out elm-format only works for me if I start VS Code from my project directory. I normally open it with code . and it works but if I start VS Code some other way it doesn't. YMMV. I'm running OS X.