Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code formatting #61

Closed
soywod opened this issue Nov 26, 2019 · 7 comments · Fixed by #83
Closed

Code formatting #61

soywod opened this issue Nov 26, 2019 · 7 comments · Fixed by #83

Comments

@soywod
Copy link

soywod commented Nov 26, 2019

haskell-ide-engine proposes to format the code via brittany. It would be possible to do the same for eg. with purty?

@nwolverson
Copy link
Owner

I'm as yet unconvinced whether this should be in the language server or something external with editor integration; I guess the fact that there only seems to be 1 option does lean towards simply including it.

Welcome opinions

@soywod
Copy link
Author

soywod commented Nov 27, 2019

Well, the text formatting is part of the LSP spec, so I guess it makes sense to add one. For eg. the client Coc.vim has implemented the formatting. No matter the language I use, it will call the format function (if exists) from the language server.

@milesfrain
Copy link
Contributor

A few related links that are mostly related to purty with vscode IDE:

There's a vscode extension for purty formatting:
https://github.com/mvakula/vscode-purty

Discussion on consolidating vscode extensions:
nwolverson/vscode-language-purescript#10

purty issue on integration with vscode:
https://gitlab.com/joneshf/purty/-/issues/124

Discourse thread on purty integration with IDE:
https://discourse.purescript.org/t/purty-ide-integration-to-format-on-save/1272

@andys8
Copy link
Contributor

andys8 commented Aug 11, 2020

In my opinion it would be nice to provide a format handler and delegate the work to purty. Fail if not installed. The advantage is that there is no need to configure formatting or have a plugin for putty per editor.

@thomashoneyman
Copy link

I'm as yet unconvinced whether this should be in the language server or something external with editor integration; I guess the fact that there only seems to be 1 option does lean towards simply including it.

If we do end up with multiple code formatters that's also not a problem; afaik the language server API is designed to accommodate this. In VSCode, for example, if you have multiple code formatters on your system that can be used for the same language then the editor will ask you to choose which one you want to use (or it can be configured in your settings).

@andys8
Copy link
Contributor

andys8 commented Aug 12, 2020

haskell-ide-engine (and haskell-language-server) give the user configuration options to select the formatting provider. elm-language-server does not because there is only elm-format.

One could try to detect if purty is on the PATH and conditionally set the the formatting provider capability but I haven't seen that before. I think it's easier to fail silently (log) or with an user facing error once the user executes code formatting with the language server.

@nwolverson
Copy link
Owner

I've definitely come around to the idea that we should "just do it" (before the PR :) ), can always make the option enabled in config if required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants