VSC openHAB Alignment Tool

Hey guys,

i just released the second major version of my openHAB Alignment Tool extension for Visual Studio Code. V2
You can find it in the Visual Studio Code Marketplace or directly in VSC. Here is the link:

https://marketplace.visualstudio.com/items?itemName=max-beckenbauer.oh-alignment-tool

The tool can only format .item-files and .sitemap files at the moment. But the other file-types will follow. You can choose between three formatting styles for items. Column, ChannelColumn or Multiline formatting. The formatter is implemented as a standard VSC Formatter. So for formatting just right-click the file and click “Format Document…”.

I am thrilled to hear some feedback from you. If you find any bugs please report them on github.

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 for your support and all the best,
Max


openHAB Alignment Tool

Build Status Visual Studio Marketplace Installs Visual Studio Marketplace Version Visual Studio Marketplace Version

This extension adds support for formatting and indenting openHAB files like *.items, *.sitemap, etc. At the moment only *.items and *.sitemap files are supported. They can be formatted in a column channel-column or multiline style. In the future the other file types
and other format-types will be added. Feel free to add feature-requests on the github repository.

Features

The tool is available as a standard Visual-Studio-Code formatter as it uses the original vsc formatter API. You can force to formatting with right-clicking the document and clicking Format Document... or Format Selection.... If you have enabled the function in the vsc settings it even can
Format-On-Save.

Item-Formatting:

Column-Style:

Column-Channel-Style:

Multiline-Style:

Limitations

The formatting is available for the following openhab file types:

  • .items (Fully functional)
  • .sitemap (Under development)
  • .things (Under development)

Extension Settings

New Line After Item

With this option you can choose if you want to have a new line inserted after each item. If there is already a single empty line after an item this settings is ignored.

"oh-alignment-tool.newLineAfterItem": true

Preserve Whitespace

Whitespaces (tabs or spaces) in front of items get preserved and won’t be deleted.

"oh-alignment-tool.preserveWhitespace": true

Multiline Indent Amount

With this option you can control the amount of indent when using the Multiline format.

"oh-alignment-tool.multilineIndentAmount": 28

Format Style

The format style option gives you two styles between you can choose.

  • Column
  • ChannelColumn
  • Multiline

The Column style formats the files in a column-way. Each item will be on one line and the item parts are separated in columns. With the ChannelColumn style only the channel part of an item gets formatted into multiple lines. The Multiline format prints every part of an item in a new line and indents
the different parts.

Known Issues

See Github Issues file for the details.

Release Notes

See CHANGELOG.md file for the details.


For More Information

Enjoy!

17 Likes

So we have two formatters for visual Studio Code. One for column lovers an one for row lovers.

Great.

1 Like

Just gave it a test. I actually was looking for a tool last night and came across the other one that formats as multi-line. So quite happy there is this column based one.

Unfortunately, I did run into some issues with your tool.

Firstly, it’s named exactly the same as the one from MarkHilbush. This caused the Command-Palette to not offer your one up for use. After disabling Mark’s one, it appeared in the Command-Palette, but the results weren’t what was expected.

Here is one of my item files before:

String                      JiPhone_BatteryStatus
                            "Battery Status [%s]"
                            <battery>
                            (iCloud_GroupJ)
                            {channel="icloud:device:myaccount:JiPhone7:batteryStatus"}

And here is what it looks like after using your tool:

StringJiPhone_BatteryStatus
                            "Battery Status [%s]"
                            <battery>
                            (iCloud_GroupJ)
                            {channel="icloud:device:myaccount:JiPhone7:batteryStatus"}
1 Like

Hey Juan,

thank you for the feedback. I will have a look for the double-naming issue and the multi-line conversion.
My tool was expecting to have the item already in a line. But of course, there can be multi-line users which want wo convert to columns. I will implement that.

Can you maybe open an issue on github? Thank you!

Before:


After:

What am I doing wrong?

2 Likes

Thank you for the feedback.

Can you please send me the before-img as a text? So i can try it on my machine? Thanks!

Switch FibWPlug1_SW <poweroutlet> (gRestore) { channel="zwave:device:uzb:node41:switch_binary" }

Number FibWPlug1_LED_Color_ON { channel="zwave:device:uzb:node41:config_decimal_param61" } //LED Color if device is ON

Number FibWPlug1_LED_Color_OFF { channel="zwave:device:uzb:node41:config_decimal_param62" } //LED Color if device is OFF

Switch EVER_Smoke_2_Smoke <fire> (gRestore) { channel="zwave:device:uzb:node26:alarm_smoke" }

Switch POPP_Smoke_1_A <fire> { channel="zwave:device:uzb:node10:sensor_binary" }

Switch POPP_Smoke_1_Sw <siren> (gRestore) { channel="zwave:device:uzb:node10:switch_binary" }

Switch POPP_Smoke_1_AG <siren> (gRestore) { channel="zwave:device:uzb:node10:alarm_general" }

Switch Neo_Water_1_Sw <siren> (gRestore) { channel="zwave:device:uzb:node42:alarm_flood" }

Switch Neo_Water_2_Sw <siren> (gRestore) { channel="zwave:device:uzb:node43:alarm_flood" }

Contact Neo_DW_1_C <door> (gRestore,gLastUpdateSwCt) { channel="zwave:device:uzb:node46:sensor_door" }

String Neo_DW_1_C_Update <motion> (gRestore)

Btw, this is the output of notepad++

Found the problem. You are indenting with spaces. I will implement that.
Please open an issue on github. Thank you! :slight_smile:

Done:

Thanks for your work :+1:

1 Like

BTW, it does not work with tabs either:

Added the support for space indentation. New Version 1.0.4 should be online in a couple of seconds.

1 Like

Great job, thanks, works now:

1 Like

hello, unfortunately a few problems …

1 Like

Thank you for the info. Can you pls open an issue on github? Thank you! :slight_smile:

1 Like

The tool is now available under the name “openHAB Alignment Tool”. There was a confusion with the tool of Mark Hilbush. Sorry for that.

Here is the new link:
https://marketplace.visualstudio.com/items?itemName=maximilian-beckenbauer.oh-alignment-tool

The bug with the MAX funciton is fixed in version 1.0.5.

1 Like

Hey @Max_Bec,

This looks really promising. Kudos. :slight_smile:
Any chance that we may join forces and add this to the openHAB VsCode extension in the future?

3 Likes

Hey Jerome,

thank you very much and i am glad to hear that. I am always open to solutions for making things easier for the other users. I’ll just write you an pm.

1 Like

Hey Juan,

the new version (1.0.6) now even supports multiline files. :slight_smile:
Thank you for reporting.