mint-lang / mint-vscode

VS Code Extension for Mint programming language
https://marketplace.visualstudio.com/items?itemName=mint-lang.mint
31 stars 10 forks source link

Option+Shift+F formatting support #2

Closed lukepighetti closed 4 years ago

lukepighetti commented 4 years ago

What do we need to enable Option+Shift+F file formatting support?

It looks like mint format doesn't have any arguments for a specific file which is not ideal for this feature, but triggering a global format would be better than nothing. Also format on save.

s0kil commented 4 years ago

mint format does support formatting individual files such as mint format file.mint, this should not be difficult to implement.

s0kil commented 4 years ago

Related for development: https://code.visualstudio.com/blogs/2016/11/15/formatters-best-practices

lukepighetti commented 4 years ago

@s0kil I have never touched VSCode extensions before, I'd be happy to take a stab at it, is there a quick start guide somewhere?

EDIT: just saw your link, let me take a stab at it tonight

s0kil commented 4 years ago

Also, format on save is controlled by VS Code, if the option is enabled in user settings, it calls the configured formatter.

lukepighetti commented 4 years ago

It looks like VSCode wants the formatted text returned instead of having the command line tool edit the file in place. Do we have any way to output the mint format src/foo.mint result to the terminal instead of editing the file in place?

Related: https://stackoverflow.com/questions/61568246/how-do-i-add-a-language-formatter-which-is-a-terminal-command

Edit: It looks like the mint CLI only outputs to file. https://github.com/mint-lang/mint/blob/master/src/commands/format.cr

s0kil commented 4 years ago

We could have a hack similar to https://github.com/pragmagic/vscode-nim/blob/master/src/nimFormatting.ts, they save the current file as a temporary file /tmp/vscodenimdirty.nim format that file with nimpretty command, and then return the contents of that temporarily file to replace the file being formatted in the editor.

lukepighetti commented 4 years ago

Resolved by https://github.com/s0kil/mint-vscode/pull/7

s0kil commented 4 years ago

@lukepighetti Thank You!