I've installed uncrustify in my linux machine and installed it's the extension in Visual Code as well. I've configured the settings.json as follows:
"uncrustify.executablePath": "/usr/bin/uncrustify",
"uncrustify.configPath": "/media/rinaldi/Excess/Dropbox/Projects/uncrusify-cpp.cfg"
and added the line in the keybiddings.json:
{ "key": "ctrl+f6", "command": "uncrustify"}
When I hit "ctrl+f6" it says that the uncrustify command wasn't found even though through a terminal accessing /usr/bin/uncrustify
I get the uncrustify binary.
There are a couple different concepts here that I'll explain.
Formatters:
VS Code has the concept of "formatter" extensions that will format your code. VS Code provides several ways to trigger this formatting, you can use some settings such as
"editor.formatOnSave": true"
or"editor.formatOnType": true
, or use theeditor.action.formatDocument
command directly, it will ask any formatting extensions that are installed for that file to format it.Commands:
In the keybindings above, the "command" part doesn't refer to a shell command/.exe command, it refers to a vscode command. These can be built in commands like the
editor.action.formatDocument
command, or it can be commands contributed by extensions. If you ever want to see what commands an extension contributes, you can look at thepackage.json
. Uncrustify contributes commands here. As you can see, they are all related to configuration and none of the commands are called "uncrustify". That's why VS Code is saying that it can't find the uncrustify command, it simply doesn't exist.So how do you get this to work?
Change the command for ctrl+f6 to
editor.action.formatDocument
. If you do that, as explained above, VS Code will ask your Uncrustify extension to format the document for you.