Skip to content

Commit c6cb2a7

Browse files
committed
codenlens fixes
1 parent 98871c3 commit c6cb2a7

File tree

3 files changed

+171
-4
lines changed

3 files changed

+171
-4
lines changed

extensions/gitpod-remote/package.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@
168168
"title": "%runGitpodYml%",
169169
"icon": "$(play)"
170170
},
171+
{
172+
"command": "gitpod.gitpodyml.dockerfile.editorContext.build",
173+
"title": "%buildGitpodYml%",
174+
"icon": "$(tools)"
175+
},
176+
{
177+
"command": "gitpod.gitpodyml.dockerfile.editorContext.run",
178+
"title": "%runGitpodYml%",
179+
"icon": "$(play)"
180+
},
171181
{
172182
"command": "gitpod.gitpodyml.editorTitle.build",
173183
"title": "%buildGitpodYml%",
@@ -177,6 +187,16 @@
177187
"command": "gitpod.gitpodyml.editorTitle.run",
178188
"title": "%runGitpodYml%",
179189
"icon": "$(play)"
190+
},
191+
{
192+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.build",
193+
"title": "%buildGitpodYml%",
194+
"icon": "$(tools)"
195+
},
196+
{
197+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.run",
198+
"title": "%runGitpodYml%",
199+
"icon": "$(play)"
180200
}
181201
],
182202
"menus": {
@@ -267,6 +287,16 @@
267287
"command": "gitpod.gitpodyml.editorContext.run",
268288
"when": "gitpod.run-gp.enabled && resourceFilename == '.gitpod.yml' && resourceScheme == file",
269289
"group": "0_navigation@0"
290+
},
291+
{
292+
"command": "gitpod.gitpodyml.dockerfile.editorContext.build",
293+
"when": "gitpod.run-gp.enabled && gitpod.run-gp.dockerfile && resourceFilename =~ /^Dockerfile$|\\.Dockerfile$/ && resourceScheme == file",
294+
"group": "0_navigation@0"
295+
},
296+
{
297+
"command": "gitpod.gitpodyml.dockerfile.editorContext.run",
298+
"when": "gitpod.run-gp.enabled && gitpod.run-gp.dockerfile && resourceFilename =~ /^Dockerfile$|\\.Dockerfile$/ && resourceScheme == file",
299+
"group": "0_navigation@0"
270300
}
271301
],
272302
"editor/title":[
@@ -279,6 +309,16 @@
279309
"command": "gitpod.gitpodyml.editorTitle.run",
280310
"when": "gitpod.run-gp.enabled && resourceFilename == '.gitpod.yml' && resourceScheme == file",
281311
"group": "navigation"
312+
},
313+
{
314+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.build",
315+
"when": "gitpod.run-gp.enabled && gitpod.run-gp.dockerfile && resourceFilename =~ /^Dockerfile$|\\.Dockerfile$/ && resourceScheme == file",
316+
"group": "navigation"
317+
},
318+
{
319+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.run",
320+
"when": "gitpod.run-gp.enabled && gitpod.run-gp.dockerfile && resourceFilename =~ /^Dockerfile$|\\.Dockerfile$/ && resourceScheme == file",
321+
"group": "navigation"
282322
}
283323
],
284324
"commandPalette": [
@@ -326,13 +366,29 @@
326366
"command": "gitpod.gitpodyml.editorContext.run",
327367
"when": "false"
328368
},
369+
{
370+
"command": "gitpod.gitpodyml.dockerfile.editorContext.build",
371+
"when": "false"
372+
},
373+
{
374+
"command": "gitpod.gitpodyml.dockerfile.editorContext.run",
375+
"when": "false"
376+
},
329377
{
330378
"command": "gitpod.gitpodyml.editorTitle.build",
331379
"when": "false"
332380
},
333381
{
334382
"command": "gitpod.gitpodyml.editorTitle.run",
335383
"when": "false"
384+
},
385+
{
386+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.build",
387+
"when": "false"
388+
},
389+
{
390+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.run",
391+
"when": "false"
336392
}
337393
]
338394
},

extensions/gitpod-shared/src/gitpodCodelens.ts

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const BuildAction = {
1414
shellCommand: 'gp-run --all-commands=false',
1515

1616
dockerfileCommand: 'gitpod.gitpodyml.dockerfile.build',
17+
dockerfileEditorContextCommand: 'gitpod.gitpodyml.dockerfile.editorContext.build',
18+
dockerfileEditorTitleCommand: 'gitpod.gitpodyml.dockerfile.editorTitle.build',
1719
editorContextCommand: 'gitpod.gitpodyml.editorContext.build',
1820
editorTitleCommand: 'gitpod.gitpodyml.editorTitle.build',
1921
};
@@ -24,6 +26,8 @@ const RunAction = {
2426
shellCommand: 'gp-run',
2527

2628
dockerfileCommand: 'gitpod.gitpodyml.dockerfile.run',
29+
dockerfileEditorContextCommand: 'gitpod.gitpodyml.dockerfile.editorContext.run',
30+
dockerfileEditorTitleCommand: 'gitpod.gitpodyml.dockerfile.editorTitle.run',
2731
editorContextCommand: 'gitpod.gitpodyml.editorContext.run',
2832
editorTitleCommand: 'gitpod.gitpodyml.editorTitle.run',
2933
};
@@ -51,13 +55,13 @@ export class GitpodYamlCodelensProvider implements vscode.CodeLensProvider {
5155
constructor() {
5256
}
5357

54-
public setValidDockerFile(uri: vscode.Uri | undefined) {
58+
public setDockerFile(uri: vscode.Uri | undefined) {
5559
this.dockerFileUri = uri;
5660
}
5761

5862
public provideCodeLenses(document: vscode.TextDocument, _tkn: vscode.CancellationToken): vscode.CodeLens[] {
5963
const isDockerFile = document.fileName.endsWith('Dockerfile');
60-
if (!this.dockerFileUri || isDockerFile && document.uri.fsPath !== this.dockerFileUri.fsPath) {
64+
if (isDockerFile && (!this.dockerFileUri || document.uri.fsPath !== this.dockerFileUri.fsPath)) {
6165
return [];
6266
}
6367

@@ -101,6 +105,8 @@ export class GitpodCodelens extends vscode.Disposable {
101105

102106
private codelensProvider = new GitpodYamlCodelensProvider();
103107

108+
private dockerFileUri: vscode.Uri | undefined;
109+
104110
private async initiateUserTask(taskAction: typeof BuildAction) {
105111
const allTasksExecutions = vscode.tasks.taskExecutions;
106112
const isTaskRunning = allTasksExecutions.find(task => task.task.source === taskAction.command);
@@ -135,6 +141,10 @@ export class GitpodCodelens extends vscode.Disposable {
135141
this.disposables.push(this.context.gitpodYml.onDidChangeGitpodYml(() => {
136142
this.updateDockerFile();
137143
}));
144+
this.disposables.push(vscode.window.onDidChangeActiveTextEditor((editor) => {
145+
const isGitpodDockerfile = !!editor && !!this.dockerFileUri && editor.document.uri.fsPath === this.dockerFileUri.fsPath;
146+
vscode.commands.executeCommand('setContext', 'gitpod.run-gp.dockerfile', isGitpodDockerfile);
147+
}));
138148
}
139149

140150
async initialize(): Promise<void> {
@@ -261,6 +271,28 @@ export class GitpodCodelens extends vscode.Disposable {
261271
});
262272
await this.initiateUserTask(RunAction);
263273
}));
274+
this.disposables.push(vscode.commands.registerCommand(BuildAction.dockerfileEditorContextCommand, async () => {
275+
this.context.fireAnalyticsEvent({
276+
eventName: 'vscode_execute_command_inner_loop',
277+
properties: {
278+
action: 'build',
279+
location: 'editorContext',
280+
source: 'dockerfile'
281+
}
282+
});
283+
await this.initiateUserTask(BuildAction);
284+
}));
285+
this.disposables.push(vscode.commands.registerCommand(RunAction.dockerfileEditorContextCommand, async () => {
286+
this.context.fireAnalyticsEvent({
287+
eventName: 'vscode_execute_command_inner_loop',
288+
properties: {
289+
action: 'run',
290+
location: 'editorContext',
291+
source: 'dockerfile'
292+
}
293+
});
294+
await this.initiateUserTask(RunAction);
295+
}));
264296
this.disposables.push(vscode.commands.registerCommand(BuildAction.editorTitleCommand, async () => {
265297
this.context.fireAnalyticsEvent({
266298
eventName: 'vscode_execute_command_inner_loop',
@@ -283,17 +315,40 @@ export class GitpodCodelens extends vscode.Disposable {
283315
});
284316
await this.initiateUserTask(RunAction);
285317
}));
318+
this.disposables.push(vscode.commands.registerCommand(BuildAction.dockerfileEditorTitleCommand, async () => {
319+
this.context.fireAnalyticsEvent({
320+
eventName: 'vscode_execute_command_inner_loop',
321+
properties: {
322+
action: 'build',
323+
location: 'editorTitle',
324+
source: 'dockerfile'
325+
}
326+
});
327+
await this.initiateUserTask(BuildAction);
328+
}));
329+
this.disposables.push(vscode.commands.registerCommand(RunAction.dockerfileEditorTitleCommand, async () => {
330+
this.context.fireAnalyticsEvent({
331+
eventName: 'vscode_execute_command_inner_loop',
332+
properties: {
333+
action: 'run',
334+
location: 'editorTitle',
335+
source: 'dockerfile'
336+
}
337+
});
338+
await this.initiateUserTask(RunAction);
339+
}));
286340
}
287341

288342
private async updateDockerFile() {
289343
const yaml = await this.context.gitpodYml.getYaml();
290344
const dockerfile = yaml.document.getIn(['image', 'file']);
291345
if (dockerfile) {
292346
const dir = path.posix.dirname(this.context.gitpodYml.uri.path);
293-
this.codelensProvider.setValidDockerFile(this.context.gitpodYml.uri.with({ path: path.join(dir, dockerfile) }));
347+
this.dockerFileUri = this.context.gitpodYml.uri.with({ path: path.join(dir, dockerfile) });
294348
} else {
295-
this.codelensProvider.setValidDockerFile(undefined);
349+
this.dockerFileUri = undefined;
296350
}
351+
this.codelensProvider.setDockerFile(this.dockerFileUri);
297352
}
298353

299354
override dispose() {

extensions/gitpod-web/package.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@
189189
"title": "%runGitpodYml%",
190190
"icon": "$(play)"
191191
},
192+
{
193+
"command": "gitpod.gitpodyml.dockerfile.editorContext.build",
194+
"title": "%buildGitpodYml%",
195+
"icon": "$(tools)"
196+
},
197+
{
198+
"command": "gitpod.gitpodyml.dockerfile.editorContext.run",
199+
"title": "%runGitpodYml%",
200+
"icon": "$(play)"
201+
},
192202
{
193203
"command": "gitpod.gitpodyml.editorTitle.build",
194204
"title": "%buildGitpodYml%",
@@ -198,6 +208,16 @@
198208
"command": "gitpod.gitpodyml.editorTitle.run",
199209
"title": "%runGitpodYml%",
200210
"icon": "$(play)"
211+
},
212+
{
213+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.build",
214+
"title": "%buildGitpodYml%",
215+
"icon": "$(tools)"
216+
},
217+
{
218+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.run",
219+
"title": "%runGitpodYml%",
220+
"icon": "$(play)"
201221
}
202222
],
203223
"menus": {
@@ -373,13 +393,29 @@
373393
"command": "gitpod.gitpodyml.editorContext.run",
374394
"when": "false"
375395
},
396+
{
397+
"command": "gitpod.gitpodyml.dockerfile.editorContext.build",
398+
"when": "false"
399+
},
400+
{
401+
"command": "gitpod.gitpodyml.dockerfile.editorContext.run",
402+
"when": "false"
403+
},
376404
{
377405
"command": "gitpod.gitpodyml.editorTitle.build",
378406
"when": "false"
379407
},
380408
{
381409
"command": "gitpod.gitpodyml.editorTitle.run",
382410
"when": "false"
411+
},
412+
{
413+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.build",
414+
"when": "false"
415+
},
416+
{
417+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.run",
418+
"when": "false"
383419
}
384420
],
385421
"statusBar/remoteIndicator": [
@@ -479,6 +515,16 @@
479515
"command": "gitpod.gitpodyml.editorContext.run",
480516
"when": "gitpod.run-gp.enabled && resourceFilename == '.gitpod.yml' && resourceScheme == file",
481517
"group": "0_navigation@0"
518+
},
519+
{
520+
"command": "gitpod.gitpodyml.dockerfile.editorContext.build",
521+
"when": "gitpod.run-gp.enabled && gitpod.run-gp.dockerfile && resourceFilename =~ /^Dockerfile$|\\.Dockerfile$/ && resourceScheme == file",
522+
"group": "0_navigation@0"
523+
},
524+
{
525+
"command": "gitpod.gitpodyml.dockerfile.editorContext.run",
526+
"when": "gitpod.run-gp.enabled && gitpod.run-gp.dockerfile && resourceFilename =~ /^Dockerfile$|\\.Dockerfile$/ && resourceScheme == file",
527+
"group": "0_navigation@0"
482528
}
483529
],
484530
"editor/title":[
@@ -491,6 +537,16 @@
491537
"command": "gitpod.gitpodyml.editorTitle.run",
492538
"when": "gitpod.run-gp.enabled && resourceFilename == '.gitpod.yml' && resourceScheme == file",
493539
"group": "navigation"
540+
},
541+
{
542+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.build",
543+
"when": "gitpod.run-gp.enabled && gitpod.run-gp.dockerfile && resourceFilename =~ /^Dockerfile$|\\.Dockerfile$/ && resourceScheme == file",
544+
"group": "navigation"
545+
},
546+
{
547+
"command": "gitpod.gitpodyml.dockerfile.editorTitle.run",
548+
"when": "gitpod.run-gp.enabled && gitpod.run-gp.dockerfile && resourceFilename =~ /^Dockerfile$|\\.Dockerfile$/ && resourceScheme == file",
549+
"group": "navigation"
494550
}
495551
]
496552
},

0 commit comments

Comments
 (0)