vscode-cfml icon indicating copy to clipboard operation
vscode-cfml copied to clipboard

script code formatting

Open lmajano opened this issue 6 years ago • 3 comments

What would it take to have some code formatting commands like the sublime plugin:

Code Formatting

This package includes several CFScript code formatting commands. You can view the default settings for these commands via the menu: Package Settings -> CFML -> Format Settings - Default, or from the command palette via CFML: Format Settings - Default. Please view these settings to see the various formatting options available. These settings can be overridden in your user format settings file, which can be found in the same locations.

There are two key bindings included that work with these commands: SHIFT+ALT+F and CTRL+ALT+SHIFT+F (CMD+ALT+SHIFT+F on a Mac) The first executes a default set of commands (specified in the settings file (cfml_format.sublime-settings), while the second calls up a menu from which formatting commands can be selected. The SHIFT+ALT+F command formats only the current method when in a component - though if any text is selected it formats that text, and in .cfm files it formats all CFScript in the file. To format an entire component the Format Full Component menu command can be used. All of the individual command options in the menu format the whole file unless text is selected.

PLEASE NOTE: The reason formatting is limited by default to the current method in components is that the formatting is CPU intensive and is currently run on the main thread, meaning Sublime Text will "freeze" while formatting is ongoing. On small blocks of code, this should be very quick, but on a large file it can take some time.

lmajano avatar Feb 08 '18 22:02 lmajano

This would involve implementing a DocumentFormattingEditProvider. I'm not sure how the Sublime plugin does this, but it seems to me that you would need a parser to do this properly. Sublime at least has access to the syntax scopes from the grammar, which might be how it's doing it, but the VS Code API does not provide access to that information.

EDIT: Found where it's done. It looks like there are many references to the scopes as I expected.

KamasamaK avatar Feb 09 '18 01:02 KamasamaK

I would like to piggyback on this old enhancement request. It would be great to be able to format .cfc and .cfm files. For the .cfm files, I think using a standard HTML format would work great for most people. For CFC files, maybe there's a way to leverage cfformat

homestar9 avatar Aug 23 '23 17:08 homestar9

I know that Scott steinbeck has created a module to put CommandBox in deamon mode inside of VSCode. This would allow the cfformating to work fast due to this. Maybe Bradd Wood can assist in connecting you guys.

lmajano avatar Aug 24 '23 06:08 lmajano