Selter
(Selter)
April 17, 2019, 10:40am
1
Hi there,
In order to get my code files nicer and cleaner I’m looking for a tool which can format the code (almost) automatically.
To get code like the one below nice, it takes some time when doing it manually
Before:
After:
Maybe someone can point me to such a tool (especially for VSCode).
Thanks,
Selter
2 Likes
Dibbler42
(Thomas Bail)
April 17, 2019, 11:16am
2
1 Like
mhilbush
(Mark)
April 17, 2019, 11:34am
3
Yes, but only if he’s ok with a multiline format…
Dibbler42
(Thomas Bail)
April 17, 2019, 11:52am
4
Thats true, but to be honest for me the multiline format is the better format
1 Like
Selter
(Selter)
April 17, 2019, 12:10pm
5
According to the readme
The ReformatItem command only reformats one line at a time. I haven’t gotten around to making it work on a selection and/or the entire file.
Does that mean that one need to reformat the file line by line?
And how to install the plugin for VSCode on Windows 10?
mhilbush
(Mark)
April 17, 2019, 12:19pm
6
Afraid so. Sorry. But it does go pretty quickly if you use the keyboard shortcut to invoke the reformatter.
Download the latest extension (version 0.0.6). In VS Code, go to the Extensions panel, then select Install from VSIX… from the More Actions… menu.
Selter
(Selter)
April 17, 2019, 12:28pm
7
So I only need this file “openhab-formatter-0.0.6.vsix” from the downloaded ZIP-archive?
Selter
(Selter)
April 17, 2019, 5:12pm
9
Thanks for your support - works fine.
It would be great if there will be the ability to format multiple lines someday
mhilbush
(Mark)
April 17, 2019, 10:50pm
10
I have a version that reformats all lines in the file, but it hasn’t been tested extensively. It doesn’t properly handle items that are already reformatted. But, if you have a file that contains no reformatted items, you’re welcome to give it a try.
Selter
(Selter)
April 18, 2019, 2:37pm
11
mhilbush:
are already reformatted.
Do you mean with “already preformatted” multiple lines per item?
mhilbush
(Mark)
April 18, 2019, 4:30pm
12
Yes, it doesn’t like it if the file already contains item definitions that span multiple lines. I haven’t yet figured out how to skip those.
Selter
(Selter)
April 18, 2019, 6:29pm
13
Could you please provide this version?
It would help me a lot.
mhilbush
(Mark)
April 18, 2019, 6:50pm
14
2 Likes
This may be a total non sequitur, but is there any way to port this to Atom?
mhilbush
(Mark)
April 20, 2019, 10:46am
16
Not easily given that the extension uses the VS Code API.
Syn
(Christoph)
April 20, 2019, 12:29pm
17
Hi @mhilbush ,
thank you very much for your add-on.
One little bug:
When a group definition contains a space, e.g. (note the space after OPEN,
):
Group:Contact:OR(OPEN, CLOSED) gTest
it will be formatted to:
Group:Contact:OR(OPEN, CLOSED
(OPEN, CLOSED)
also the group name is omitted.
mhilbush
(Mark)
April 20, 2019, 1:30pm
19
Syn:
One little bug:
Version 0.0.8 hopefully will fix this.
The Code Alignment extension was my favorite in Visual Studio that would handle this formatting easily. It has been ported to vscode, but not all functionality is there yet. In the current vscode version it takes a few keystrokes, but it does work well.
Here’s the VS Marketplace link:
https://marketplace.visualstudio.com/items?itemName=cpmcgrath.codealignment-vscode&ssr=false#overview