Skip to content

Commit 8d0d1c3

Browse files
authored
Merge pull request #54 from badsyntax/snippets
Snippets
2 parents 67d4b94 + 3ee8247 commit 8d0d1c3

File tree

11 files changed

+153
-68
lines changed

11 files changed

+153
-68
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ about: Create a report to help us improve
44
title: ''
55
labels: bug
66
assignees: badsyntax
7-
87
---
98

109
**Describe the bug**
@@ -20,7 +19,8 @@ A clear and concise description of what you expected to happen.
2019
If applicable, add screenshots to help explain your problem.
2120

2221
**Environment (please complete the following information):**
23-
- OS: [e.g. iOS]
22+
23+
- OS: [e.g. iOS]
2424

2525
**Output from "Gradle Tasks"**
2626
You can find this by clicking on the "Output" panel, then selecting the "Gradle Tasks" channel from the dropdown.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ about: Suggest an idea for this project
44
title: ''
55
labels: enhancement
66
assignees: badsyntax
7-
87
---
98

109
**Is your feature request related to a problem? Please describe.**

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Run gradle tasks in VS Code.
99

1010
## Features
1111

12-
- Run gradle tasks as [VS Code tasks](https://code.visualstudio.com/docs/editor/tasks)
12+
- Run [Gradle tasks](https://gradle.org/) as [VS Code tasks](https://code.visualstudio.com/docs/editor/tasks)
1313
- List & run gradle tasks in the Explorer
1414
- Multi-root workspace folders supported
1515
- Default Groovy/Kotlin & custom build files supported
@@ -27,6 +27,12 @@ This extension contributes the following settings:
2727
- `gradle.customBuildFile`: Custom gradle build filename
2828
- `gradle.explorerNestedSubProjects`: Show nested subprojects in the explorer
2929

30+
## Snippets
31+
32+
This extensions provides snippets for the groovy and kotlin build files:
33+
34+
- `cgt`: Create a new gradle task
35+
3036
## Slow Task Provider Warning
3137

3238
[Since vscode v1.40](https://code.visualstudio.com/updates/v1_40#_slow-task-provider-warning), you will start seeing warning notifications when the gradle task provider takes too long.

package.json

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"vscode": "^1.39.0"
2424
},
2525
"categories": [
26-
"Other"
26+
"Other",
27+
"Snippets"
2728
],
2829
"keywords": [
2930
"java",
@@ -42,6 +43,16 @@
4243
],
4344
"main": "./out/extension",
4445
"contributes": {
46+
"snippets": [
47+
{
48+
"language": "groovy",
49+
"path": "./snippets/build.gradle.json"
50+
},
51+
{
52+
"language": "kotlinscript",
53+
"path": "./snippets/build.gradle.kts.json"
54+
}
55+
],
4556
"problemMatchers": [
4657
{
4758
"owner": "gradle",
@@ -87,6 +98,14 @@
8798
"command": "gradle.openBuildFile",
8899
"title": "Open Build File"
89100
},
101+
{
102+
"command": "gradle.addTask",
103+
"title": "Add Task",
104+
"icon": {
105+
"light": "resources/light/add.svg",
106+
"dark": "resources/dark/add.svg"
107+
}
108+
},
90109
{
91110
"command": "gradle.refresh",
92111
"title": "Gradle: Refresh Tasks",
@@ -102,6 +121,10 @@
102121
"command": "gradle.runTask",
103122
"when": "false"
104123
},
124+
{
125+
"command": "gradle.addTask",
126+
"when": "false"
127+
},
105128
{
106129
"command": "gradle.stopTask",
107130
"when": "false"
@@ -127,6 +150,15 @@
127150
"command": "gradle.openBuildFile",
128151
"when": "view == gradle-tree-view && viewItem == buildFile"
129152
},
153+
{
154+
"command": "gradle.addTask",
155+
"when": "view == gradle-tree-view && viewItem == buildFile"
156+
},
157+
{
158+
"command": "gradle.addTask",
159+
"when": "view == gradle-tree-view && viewItem == buildFile",
160+
"group": "inline"
161+
},
130162
{
131163
"command": "gradle.runTask",
132164
"when": "view == gradle-tree-view && viewItem == task",
@@ -199,6 +231,10 @@
199231
"fileName": {
200232
"type": "string",
201233
"description": "The filename of the build file that provides the tasks"
234+
},
235+
"description": {
236+
"type": "string",
237+
"description": "Description of the task"
202238
}
203239
}
204240
}
@@ -211,9 +247,9 @@
211247
"test": "node ./out/test/runTest.js",
212248
"pretest": "npm run compile",
213249
"lint": "npm run lint:prettier && npm run lint:tslint",
214-
"lint:prettier": "prettier --check \"**/*.{ts,js,json,svg}\"",
250+
"lint:prettier": "prettier --check \"**/*.{ts,js,json,svg,md,yml}\"",
215251
"lint:tslint": "tslint -c tslint.json 'src/**/*.ts'",
216-
"format": "prettier --write '**/*.{ts,js,json,svg}'"
252+
"format": "prettier --write '**/*.{ts,js,json,svg,md,yml}'"
217253
},
218254
"dependencies": {},
219255
"devDependencies": {

resources/dark/add.svg

Lines changed: 9 additions & 0 deletions
Loading

resources/light/add.svg

Lines changed: 9 additions & 0 deletions
Loading

snippets/build.gradle.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"createGradleTask": {
3+
"prefix": "cgt",
4+
"body": [
5+
"tasks.register(\"$1\") {",
6+
"\tgroup='$2'",
7+
"\tdescription='$3'",
8+
"\tdoLast {",
9+
"\t\tprintln 'Hello, World'",
10+
"\t}",
11+
"}"
12+
],
13+
"description": "Create a new Gradle task"
14+
}
15+
}

snippets/build.gradle.kts.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"createGradleTask": {
3+
"prefix": "cgt",
4+
"body": [
5+
"tasks.register(\"$1\") {",
6+
"\tgroup=\"$2\"",
7+
"\tdescription=\"$3\"",
8+
"\tdoLast {",
9+
"\t\tprintln(\"Hello, World\")",
10+
"\t}",
11+
"}"
12+
],
13+
"description": "Create a new Gradle task"
14+
}
15+
}

src/extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ function registerCommands(
114114
treeDataProvider
115115
)
116116
);
117+
context.subscriptions.push(
118+
vscode.commands.registerCommand(
119+
'gradle.addTask',
120+
treeDataProvider.addTask,
121+
treeDataProvider
122+
)
123+
);
117124
}
118125
}
119126

src/gradleView.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,16 @@ class GradleTaskTreeItem extends vscode.TreeItem {
9696
context: vscode.ExtensionContext,
9797
folderTreeItem: GradleBuildFileTreeItem,
9898
task: vscode.Task,
99-
label: string
99+
label: string,
100+
description?: string
100101
) {
101102
super(label, vscode.TreeItemCollapsibleState.None);
102103
this.command = {
103104
title: 'Run Task',
104105
command: 'gradle.runTask',
105106
arguments: [this]
106107
};
108+
this.tooltip = description || label;
107109
this.folderTreeItem = folderTreeItem;
108110
this.task = task;
109111
this.execution = getTaskExecution(task);
@@ -192,6 +194,22 @@ export class GradleTasksTreeDataProvider
192194
}
193195
}
194196

197+
async addTask(buildFileTreeItem: GradleBuildFileTreeItem) {
198+
const uri = buildFileTreeItem.resourceUri;
199+
if (uri) {
200+
const textEditor = await vscode.window.showTextDocument(
201+
await vscode.workspace.openTextDocument(uri)
202+
);
203+
204+
const position = new vscode.Position(textEditor.document.lineCount, 0);
205+
textEditor.selection = new vscode.Selection(position, position);
206+
207+
vscode.commands.executeCommand('editor.action.insertSnippet', {
208+
name: 'createGradleTask'
209+
});
210+
}
211+
}
212+
195213
refresh(): Thenable<vscode.Task[]> {
196214
invalidateTasksCache();
197215
enableTaskDetection();
@@ -333,15 +351,17 @@ export class GradleTasksTreeDataProvider
333351
this.extensionContext,
334352
subProjectBuildFileTreeItem,
335353
task,
336-
task.name.replace(/[^:]+:/, '')
354+
task.name.replace(/[^:]+:/, ''),
355+
task.definition.description
337356
);
338357
subProjectBuildFileTreeItem.addTask(gradleTask);
339358
} else {
340359
const gradleTask = new GradleTaskTreeItem(
341360
this.extensionContext,
342361
buildFileTreeItem,
343362
task,
344-
task.name
363+
task.name,
364+
task.definition.description
345365
);
346366
buildFileTreeItem.addTask(gradleTask);
347367
}

0 commit comments

Comments
 (0)