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…
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”.
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:
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.
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.
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.
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!
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.
thank you for reporting. I changed one thing last minute before the release… Silly idea.
I opened an issue on github for tracking and fixed it already.
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;
}
},
})
);