intersystems-community / vscode-objectscript

InterSystems ObjectScript extension for Visual Studio Code
https://docs.intersystems.com/components/csp/docbook/DocBook.UI.Page.cls?KEY=GVSCO
Other
108 stars 49 forks source link

objectscript.multilineMethodArgs adds tabs #1272

Closed jpa95 closed 12 months ago

jpa95 commented 1 year ago

When setting "objectscript.multilineMethodArgs": true, the code formatting puts function parameters on separate lines which is fine; however it always uses tabs to indent said parameters, regardless of the editor.insertSpaces configuration.

Method AddResultField(
    screenDisplayName As %String, // tabs used
    screenName As %String,
    screenId As %String,
    screenDisplayOrder As %String,
    resultField As %DynamicObject)

I would like the objectscript.multilineMethodArgs to take into account editor.insertSpaces, and when "editor.insertSpaces": true,, it should uses spaces instead of tabs, and also respect editor.tabSize as well.

Thanks for your time!

isc-bsaviano commented 1 year ago

@jpa95 The objectscript.multilineMethodArgs setting is just passed along to the server as a query parameter to a REST request that gets the document's text. The server adds the tabs when it renders the class definition as text. We can't tell the server to add spaces or a different number of tabs. If there's a VS Code command that applies the indentation settings then we could possibly run that command automatically after fetching the document contents, but I think that's the best we could do.

jpa95 commented 12 months ago

@isc-bsaviano Well there is a command named "convert indentation to spaces/tab", but you still would have to check the user's setting configuration. I'm pretty sure it's the formatter extension's responsibility to do so.

I'm gonna go out on a limb and say that for other languages we are using the Prettier extension for code formatting -- i'd love to have an ObjectScript plugin for that. :)

isc-bsaviano commented 12 months ago

@jpa95 Now that I think about it more, I think it's too heavy-handed to call the indentation command just to convert these tabs to spaces. IMO the ideal workflow would be for the user to manually format the entire document whenever they need to (or set up auto-formatting via the VS Code settings). Right now our formatter doesn't touch indentation, but there's a request for us to add that (https://github.com/intersystems/language-server/issues/293). I think I should close this issue and consider it another request for that same feature. As for having an ObjectScript plugin to Prettier, it may be possible but we would need to generate an AST. AFAIK nobody has ever been able to do this for ObjectScript.

jpa95 commented 12 months ago

@isc-bsaviano Sounds good to me. I also agree the user should decide if and when to format, and how.