An extension to provide Gradle language support for Visual Studio Code, including advanced functionalities like Syntax Highlighting, Keyword Auto-completion Proposals and Duplication Validation.
Homepage: Visual Studio Code Marketplace
The extension observes all .gradle
documents and uses the server to provide validation and auto-completion proposals (IntelliSense).
The code for the extension is in the client
folder, which uses the vscode-languageclient
node module to launch the language server.
The language server is located in the server
folder.
The tests are located in the test
folder.
- The extension converts the sublime-gradle's TextMate grammar configuration for Gradle language.
The extension automatically detects the Java and Android plugin used in the Gradle scripts, then propose keywords smartly in different situations depending on the position of the cursor:
-
Inside a line with existing code:
-
At the start of a word:
- Particularly, after the
apply
method, propose the parameters for plugin application.
-
In a Task Container's constructor:
- At the start of a parameter, propose Task Container's constructor parameters.
- Particularly, after the
type
parameter, propose Task's default types.
- Particularly, after the
dependsOn
parameter, propose other Tasks names.
- Particularly, after the
TaskDependency
methods (i.e.dependsOn
,finalizedBy
,mustRunAfter
andshouldRunAfter
), propose other Tasks names.
-
Elsewhere, propose the Delegate Object together with its properties and methods.
- Particularly, after the
-
After an entity's dot inside a line with existing code, propose the properties and methods of this entity.
-
-
At the start of a new line:
- On the root level of the build script, propose the properties and methods of the current script's Delegate Object.
- Particularly, in a
TaskContainer
, analyze the task's type and propose the properties and methods according to this type.
- In a script block of
NamedDomainObjectContainer
, such asBuildTypes
,ProductFlavors
,SigningConfigs
andAndroidSourceSets
, DO NOT override default keywords and let the user decide the name for each item.
- In a configure closure of an item within a
NamedDomainObjectContainer
, propose the properties and methods of this container's element type.
- In a script block of a general property or method, propose the properties and methods of this script block.
- The extension automatically validates the script under editing and warns the user about duplicated script blocks.
- Download and install Visual Studio Code.
- Download and install Node.js.
- Pull the repo and
cd
to the root directory. - Run
npm install
to initialize the extension and the server. - Run
npm run compile
in the terminal to compile the extension and the server. - Open the root folder in Visual Studio Code, then set the
Preferences -> Color Theme
toDark+ (default dark)
. - In the Debug viewlet, run
Launch Client
from drop-down menu (or pressF5
) to launch the extension and attach to the extension. - Create and open a file
build.gradle
and type'app'
into it. You should see keywords proposed including'apply'
.
- In the Debug viewlet, run
Attach to Server
launch config and set breakpoints in the client or the server.
- In the Debug viewlet, run
Launch Unit Tests
from drop-down menu to run the unit tests.
- Syntax highlighting doesn't always work consistently with task constructor with parameters in parentheses, i.e.
task foo(type: Bar) {...}
andtask foo {...}