@@ -14,6 +14,8 @@ const BuildAction = {
14
14
shellCommand : 'gp-run --all-commands=false' ,
15
15
16
16
dockerfileCommand : 'gitpod.gitpodyml.dockerfile.build' ,
17
+ dockerfileEditorContextCommand : 'gitpod.gitpodyml.dockerfile.editorContext.build' ,
18
+ dockerfileEditorTitleCommand : 'gitpod.gitpodyml.dockerfile.editorTitle.build' ,
17
19
editorContextCommand : 'gitpod.gitpodyml.editorContext.build' ,
18
20
editorTitleCommand : 'gitpod.gitpodyml.editorTitle.build' ,
19
21
} ;
@@ -24,6 +26,8 @@ const RunAction = {
24
26
shellCommand : 'gp-run' ,
25
27
26
28
dockerfileCommand : 'gitpod.gitpodyml.dockerfile.run' ,
29
+ dockerfileEditorContextCommand : 'gitpod.gitpodyml.dockerfile.editorContext.run' ,
30
+ dockerfileEditorTitleCommand : 'gitpod.gitpodyml.dockerfile.editorTitle.run' ,
27
31
editorContextCommand : 'gitpod.gitpodyml.editorContext.run' ,
28
32
editorTitleCommand : 'gitpod.gitpodyml.editorTitle.run' ,
29
33
} ;
@@ -51,13 +55,13 @@ export class GitpodYamlCodelensProvider implements vscode.CodeLensProvider {
51
55
constructor ( ) {
52
56
}
53
57
54
- public setValidDockerFile ( uri : vscode . Uri | undefined ) {
58
+ public setDockerFile ( uri : vscode . Uri | undefined ) {
55
59
this . dockerFileUri = uri ;
56
60
}
57
61
58
62
public provideCodeLenses ( document : vscode . TextDocument , _tkn : vscode . CancellationToken ) : vscode . CodeLens [ ] {
59
63
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 ) ) {
61
65
return [ ] ;
62
66
}
63
67
@@ -101,6 +105,8 @@ export class GitpodCodelens extends vscode.Disposable {
101
105
102
106
private codelensProvider = new GitpodYamlCodelensProvider ( ) ;
103
107
108
+ private dockerFileUri : vscode . Uri | undefined ;
109
+
104
110
private async initiateUserTask ( taskAction : typeof BuildAction ) {
105
111
const allTasksExecutions = vscode . tasks . taskExecutions ;
106
112
const isTaskRunning = allTasksExecutions . find ( task => task . task . source === taskAction . command ) ;
@@ -135,6 +141,10 @@ export class GitpodCodelens extends vscode.Disposable {
135
141
this . disposables . push ( this . context . gitpodYml . onDidChangeGitpodYml ( ( ) => {
136
142
this . updateDockerFile ( ) ;
137
143
} ) ) ;
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
+ } ) ) ;
138
148
}
139
149
140
150
async initialize ( ) : Promise < void > {
@@ -261,6 +271,28 @@ export class GitpodCodelens extends vscode.Disposable {
261
271
} ) ;
262
272
await this . initiateUserTask ( RunAction ) ;
263
273
} ) ) ;
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
+ } ) ) ;
264
296
this . disposables . push ( vscode . commands . registerCommand ( BuildAction . editorTitleCommand , async ( ) => {
265
297
this . context . fireAnalyticsEvent ( {
266
298
eventName : 'vscode_execute_command_inner_loop' ,
@@ -283,17 +315,40 @@ export class GitpodCodelens extends vscode.Disposable {
283
315
} ) ;
284
316
await this . initiateUserTask ( RunAction ) ;
285
317
} ) ) ;
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
+ } ) ) ;
286
340
}
287
341
288
342
private async updateDockerFile ( ) {
289
343
const yaml = await this . context . gitpodYml . getYaml ( ) ;
290
344
const dockerfile = yaml . document . getIn ( [ 'image' , 'file' ] ) ;
291
345
if ( dockerfile ) {
292
346
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 ) } ) ;
294
348
} else {
295
- this . codelensProvider . setValidDockerFile ( undefined ) ;
349
+ this . dockerFileUri = undefined ;
296
350
}
351
+ this . codelensProvider . setDockerFile ( this . dockerFileUri ) ;
297
352
}
298
353
299
354
override dispose ( ) {
0 commit comments