VSC openHAB Alignment Tool

I found an issue with your aligment tool:
Maybe it’s aready known, but I just want to share it just in case:
This is my original line:

Switch Abus_Mode            "Alarmanlage [%s]"          <siren>         (G_jdbc,Group_HabPanel_Dashboard)    {http=">[ON:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Set{Authorization=Basic xxx}] >[OFF:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Unset{Authorization=Basic xxx}]"}

and this is the result after alignment:

Switch  Abus_Mode   "Alarmanlage [%s]"  <siren> (G_jdbc,Group_HabPanel_Dashboard)       {http=">[ON:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Set{Authorization=Basic xxx} //192.168.68.36:8060/setMode.cgi?Mode=Set{Authorization=Basic xxx}] >[OFF:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Unset{Authorization=Basic xxx}]"}
1 Like

Hey NCO,

thank you for the report.
Can you please open an issue on github? I will have a look at it asap.

Kind Regards,
Max

I also have a little problem:
I usually add 1-2 empty line after a “section” in an items file to seperate different group of items (also I have empty line after each Item). However when I apply the formatter, it will always add a new empty line in a bigger empty section. So if somewhere I have 2 empty lines, it will become 3. If I rerun the formatter again, there will be 4…

1 Like

Sure.
That will be my first issue, but I’ll give it a try. :wink:

1 Like

Hey, guys,

due to the COVID-19 crisis I didn’t have much time to take care of the extension for VSC in the last months. But in the last weeks I finally got around to doing a major code-side change.

The openHAB Alignment Tool is now a “real” formatting extension and uses the VSC Formatter API. This enables functions such as “Format-On-Save”.

You can download the new Version here:
https://github.com/MaxBec/openHAB-Alignment-Tool/releases/tag/v2.0.0-beta.2.

:warning: Important:

The tool is currently still in Beta stage. If I don’t get any serious bug reports within the next days I will compile a version for the VSC Marketplace and upload it there. You can download the beta version as .VSIX file and install it in VSC. How to do this is described here:

Thanks already now for your support!!!

6 Likes

I get an error when I’m trying to use this version:

Command 'openHAB Alignment: Reformat File' resulted in an error (command 'extension.reformat-file' not found)
1 Like

With the new implementation of the Visual Studio Code Formatter API formatting is done via:

  • Saving the file (If “Format-On-Save” is enabled)
  • Right-Click Format Document
  • Right-Click Format Selection
1 Like

Thanks it works like that!

However the new line insert is worse than before. Now it inserts a new line after every empty line. Before it inserted a new line after every 2nd empty line I think.

1 Like

Can you please send me a copy of the lines you are trying to format?

And just to make sure… Did you use 2.0.0.-Beta.2?

Sent. Yes I’m using Beta2

1 Like

This seems to work for me great (updated Beta2 version).

Only the ‘New Line After Item’ is not working as it should. Right now it inserts a new line after each Item, even if you already have a new line after an Item. @Max_Bec will fix this soon.

1 Like

I just released Beta.3.
It should be fixed there. This will be the last beta before the final release of v2.

1 Like

Hey guys,

after a long time, a lot of coding and debugging and a lot of support in issue reporting from @christoph_wempe i finally released the new openHAB Alignment Tool V2.

The extension is now implemented as a “real” formatter with the help of the VSC Formatter API. So it is integrated into the VSC environment now and enables functions like Format-On-Save, etc.

Furthermore there are two new special comments you can use in *.items files:

  • // #OHNG#: starts a new formatting group. So the column width will belong to the widest item in the following group and not the whole file.
  • // #OHFS#Multiline#OHFS#: can change the formatting style for the following code. The default style for all documents will get overridden for the part after the special comment.

I hope you guys like it and if you’ll find a bug feel free to report an issue on my github site:

Thank you very very much for the support and thank you for nearly 9000 installs. This is incredible. :star_struck:

If you’ve found the extension helpful or useful, then please consider throwing a coffee my way to help support my work. As i am a student and would like to invest more time and effort in this project this would really help me. Thank you already!

ko-fi

3 Likes

Hi Max,

thanks a lot for the continued work and update to the openHAB Alignment Tool. I’m not seeing any effect with the new comments tags though

with the currently installed version 2.0.2. // #OHNG# still formats to the widest item of the whole file for me and not just the commented group.

Any idea what I might be missing?

Thanks

1 Like

I just cloned my openhab-config to test the new V2.0.2.

But right at the start I experienced something new.

image

Does the official openHAB-Extension have its own formatting feature?
I just think this is confusing for new users.
If the official extiension does not format the code I will report in issue with the official extension.

1 Like

I’m not seeing any effect with the new comments tags though

Me neither. :confused:

EDIT:

Actuially #OHFS# seems to work as expected.

2 Likes

I think Max is registering the file type endings for using the formatter api.

I am not sure if this can be done only for particular parts of the vscode api.

1 Like

I should have used the singular, as I’ve only tried #OHNG# :wink: which I am interested in.

Hey @Hans_Lree,

thank you for reporting. I changed one thing last minute before the release… Silly idea. :wink:
I opened an issue on github for tracking and fixed it already.

Hey @christoph_wempe,

yes the official openHAB extension has an implementation for the lsp of openHAB and so for formatting as well (not sure if this is correct). But it does only some pretty basic formatting tasks. The problem is that *.items, *.things, *.sitemp, etc. are no single language files but are all recognized as just “openhab” files.

So in my extension i do this in the beginning to see which file-type the user wants to format:

context.subscriptions.push(
		vscode.languages.registerDocumentFormattingEditProvider("openhab", {
			provideDocumentFormattingEdits: (document, options, token) => {
				// Check the file type, clean the file and format it
				if (document.fileName.includes(".sitemap")) {
					return formatSitemapFile();
				} else if (document.fileName.includes(".items")) {
					return formatItemFile();
				} else if (document.fileName.includes(".things")) {
					return formatThingFile();
				} else {
					return undefined;
				}
			},
		})
	);