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

Formatting GLSL not supported, even though it should be able to format GLSL

Open FrostKiwi opened this issue 1 year ago • 6 comments

Environment

  • OS and version: Windows_NT x64 10.0.19044
  • VS Code: 1.71.2 (user setup)
  • C/C++ extension: v1.12.4
  • OS and version of remote machine (if applicable):

Bug Summary and Steps to Reproduce

Posting issue here, as suggested by: https://github.com/microsoft/vscode/issues/161209#issuecomment-1251914962

Issuing the format document command on a GLSL file with .frag as the extension in case of the this fragment shader file, results in the There is no formatter for 'glsl' files installed. error message. Which is correct, I do not have one installed specifically for GLSL shaders.

image

I would like to use the default formatter for C files, as GLSL is formatted identically to C. So I set the following in my settings .json

    "[glsl]": {
        "editor.defaultFormatter": "ms-vscode.cpptools"
    },

This does not change the error message, which persists.

I presume this is because ms-vscode.cpptools is not specifically registered to work with glsl files, although the formatter should be more than capable of formatting GLSL files. It would be excellent, if I could chose the C formatter for GLSL files.

Does this issue occur when all extensions are disabled?: Yes

Detailed version Info
Version: 1.71.2 (user setup)
Commit: 74b1f979648cc44d385a2286793c226e611f59e7
Date: 2022-09-14T21:03:37.738Z
Electron: 19.0.12
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: No

Steps to Reproduce:

  1. Set "editor.defaultFormatter": "ms-vscode.cpptools"
  2. Format a glsl file

Other Extensions

No response

Additional Information

No response

FrostKiwi avatar Sep 21 '22 02:09 FrostKiwi

Do you intend to format with vcFormat or clangFormat? If you set files.associations: { "*.frag": "c" } that should be a workaround, but it would treat the file as C for all language service features. I'm not sure formatting would work without issues. We'd also have to disable non-formatting features like IntelliSense.

sean-mcmanus avatar Sep 21 '22 05:09 sean-mcmanus

set files.associations: { "*.frag": "c" } that should be a workaround

Indeed, that works and formats the file correctly, but as you already guessed, IntelliSense flips out with errors: image I see no formatting issues with multiple files across GLSL vertex and fragment shaders. I presume the same to be true for DirectX HLSL shaders.

I wonder if I can setup a function,, that temporarily switches to files.associations: c, format file, and switch back to the original association as an extra dirty workaround. Bind it to the default Shift+Alt+F with .frag files as the conditional.

intend to format with vcFormat or clangFormat?

I never set it to clangFormat, so I presume the default(?) vcFormat is being used.

We'd also have to disable non-formatting features like IntelliSense.

I kinda presumed this "formatter" thingy is an extra component divorced from linting and stuff, but clearly this is a bit more complicated than I would have guessed...

FrostKiwi avatar Sep 21 '22 05:09 FrostKiwi

You could try setting the C_Cpp.errorSquiggles to "Disabled". You may need to disable other language service features too. However, that would only work if you also don't want those in actual C/C++ files, unless possibly if you used a multi-root workspace with one workspace folder configured for GLSL formatting and another for C/C++.

The default is clangFormat.

I'm not sure if switching file associations back and forth would work.

The reason the formatting is embedded with the other language service features is due to our shared internal document object which is used by formatting and IntelliSense (and other configuration details).

sean-mcmanus avatar Sep 21 '22 06:09 sean-mcmanus

The default is clangFormat.

Ohh, good to know.

You could try setting the C_Cpp.errorSquiggles to "Disabled"

I must remain in glsl mode to get the glsl linting via https://marketplace.visualstudio.com/items?itemName=dtoplak.vscode-glsllint .

I'm not sure if switching file associations back and forth would work.

It does! Hahaha, this is so ugly, but man is it ever better than installing an extra formatter:

{
    "key": "ctrl+alt+f",
    "command": "extension.multiCommand.execute",
    "args": {
        "sequence": [
            { "command": "commands.setEditorLanguage", "args": "c"},
            { "command": "editor.action.formatDocument"},
            { "command": "commands.setEditorLanguage", "args": "glsl"}
        ]
}
 

Using https://marketplace.visualstudio.com/items?itemName=usernamehw.commands to change the language mode and https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command to execute multiple commands with one keybind. It works and formats correctly in roughly half a second, so this is perfect.

FrostKiwi avatar Sep 21 '22 07:09 FrostKiwi

This feature request is being closed due to insufficient upvotes. Please leave a 👍-upvote or 👎-downvote reaction on the issue to help us prioritize it. When enough upvotes are received, this issue will be eligible for our backlog.

github-actions[bot] avatar Dec 18 '22 11:12 github-actions[bot]

This feature request has received enough votes to be added to our backlog.

github-actions[bot] avatar Jan 26 '24 12:01 github-actions[bot]