VSCode Dot Syntax Indentation
In VS Code using the InterSystems ObjectScript extensions, I'd like the indentation applied to match that of IRIS Studio. Specifically for comments and dot syntax, I'd like pressing enter (carriage return) to preserve the current dot depth and same comment beginning.
In IRIS Studio after changing the indentation settings to custom using " \t.#/;" without quotes (note the leading space), the behaviour looks like this:
.png)
And after pressing enter the leading comment is preserved:
.png)
For dot indented code:
.png)
After pressing enter the dot depth is preserved:
.png)
If I do the same thing in VS Code the carriage return takes me back to the beginning of the line (after the tab). I could almost live with this for the comments, but if code was indented by 6 dots, I can see mistakes creeping in if developers have to manually apply the dots.
Is there a object script language setting I can alter to reinstate the IRIS Studio behaviour in VS Code?
Comments
Hi @Mathew Rimmington, this exact question was asked in a GitHub discussion a few weeks ago. To summarize my answer there, this isn't easy to add because the text that gets added on enter (besides indentation) is static. It acn't be generated from the regular expression used to match the previous line, so I couldn't dynamically add the correct number of dots. My recommendation is to use modern brace syntax instead of legacy dot syntax.
Hi Brett, thanks for getting back to me with an answer. As we have thousands of routines containing dot syntax I couldn't really leave this without a solution. For now we've built our own simple extension to implement OnTypeFormattingEditProvider. See https://vshaxe.github.io/vscode-extern/vscode/OnTypeFormattingEditProvider.html.
In our case all the method implementation needs to do is look at the previous line, assess how many dots the line begins with and populate the same on the new line. I can appreciate the difficulty you'll have with making this work for all scenarios in Object Script though.
Hi @Mathew Rimmington, thanks for following up with your solution! That is a creative way to solve the problem and I encourage you to submit your code as a Pull Request to the vscode-objectscript extension. It is a community tool so we would happy to include your code if it improves your experience. The contributing guide can be found here.