README
google-java-format is a tool to format Java code. It can be configured with a config file within the working folder or a parent folder. Configuration see: https://github.com/google/google-java-format
Usage
This extension allows google-java-format (version 3.8 or higher) to be used to format C/C++, Javascript etc.
source files directly from within Visual Studio Code.
Files can be formatted on-demand by right clicking in the document and
selecting "Format Document", or by using the associated keyboard shortcut
(usually Ctrl+⇧+F on Windows, Ctrl+⇧+I on Linux, and ⇧+⌥+F on macOS).
To automatically format a file on save, add the following to your
vscode settings.json file:
{
"editor.formatOnSave": true
}
This extension will attempt to find google-java-format on your PATH
.
Alternatively, the google-java-format executable can be specified in your vscode
settings.json file:
{
"google-java-format.executable": "/absolute/path/to/google-java-format"
}
Placeholders can also be used in the google-java-format.executable
value.
The following placeholders are supported:
${workspaceRoot}
- replaced by the absolute path of the current vscode
workspace root.
${cwd}
- replaced by the current working directory of vscode.
${env.VAR}
- replaced by the environment variable $VAR, e.g. ${env.HOME}
will be replaced by $HOME
, your home directory.
Some examples:
${workspaceRoot}/node_modules/.bin/google-java-format
- specifies the version of
clang that has been added to your workspace by npm install google-java-format
.
${env.HOME}/tools/clang38/google-java-format
- use a specific clang format version
under your home directory.
Placeholders are also supported in google-java-format.assumeFilename
. The supported
placeholders are ${file}
, ${fileNoExtension}
, ${fileBasename}
,
${fileBasenameNoExtension}
, and ${fileExtname}
, with the same meaning as the
predefined variables in other configuration files.
For example:
${fileNoExtension}.cpp
- /home/src/foo.h
will be formatted with
-assume-filename /home/src/foo.cpp
.
Source code
Available on github: https://github.com/wx-chevalier/vscode-google-java-format-provider