Skip to content

Commit 5e131d9

Browse files
authored
Add dvc.yaml into files used to show editor/title icons (#4228)
1 parent c6d70ec commit 5e131d9

File tree

8 files changed

+77
-56
lines changed

8 files changed

+77
-56
lines changed

extension/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@
10721072
{
10731073
"command": "dvc.stopAllRunningExperiments",
10741074
"group": "navigation@0",
1075-
"when": "dvc.params.file.active && dvc.experiment.running && dvc.commands.available"
1075+
"when": "dvc.experiments.file.active && dvc.experiment.running && dvc.commands.available"
10761076
},
10771077
{
10781078
"command": "dvc.stopAllRunningExperiments",
@@ -1082,7 +1082,7 @@
10821082
{
10831083
"command": "dvc.runExperiment",
10841084
"group": "navigation@1",
1085-
"when": "dvc.params.file.active && !dvc.experiment.running.workspace && dvc.commands.available && !dvc.experiment.checkpoints"
1085+
"when": "dvc.experiments.file.active && !dvc.experiment.running.workspace && dvc.commands.available && !dvc.experiment.checkpoints"
10861086
},
10871087
{
10881088
"command": "dvc.runExperiment",
@@ -1097,7 +1097,7 @@
10971097
{
10981098
"command": "dvc.resetAndRunCheckpointExperiment",
10991099
"group": "navigation@2",
1100-
"when": "dvc.params.file.active && !dvc.experiment.running.workspace && dvc.commands.available && dvc.experiment.checkpoints"
1100+
"when": "dvc.experiments.file.active && !dvc.experiment.running.workspace && dvc.commands.available && dvc.experiment.checkpoints"
11011101
},
11021102
{
11031103
"command": "dvc.resumeCheckpointExperiment",
@@ -1107,7 +1107,7 @@
11071107
{
11081108
"command": "dvc.resumeCheckpointExperiment",
11091109
"group": "navigation@3",
1110-
"when": "dvc.params.file.active && !dvc.experiment.running.workspace && dvc.commands.available && dvc.experiment.checkpoints"
1110+
"when": "dvc.experiments.file.active && !dvc.experiment.running.workspace && dvc.commands.available && dvc.experiment.checkpoints"
11111111
},
11121112
{
11131113
"command": "dvc.startExperimentsQueue",
@@ -1117,7 +1117,7 @@
11171117
{
11181118
"command": "dvc.startExperimentsQueue",
11191119
"group": "navigation@4",
1120-
"when": "dvc.params.file.active && dvc.commands.available"
1120+
"when": "dvc.experiments.file.active && dvc.commands.available"
11211121
},
11221122
{
11231123
"command": "dvc.queueExperiment",
@@ -1127,7 +1127,7 @@
11271127
{
11281128
"command": "dvc.queueExperiment",
11291129
"group": "navigation@5",
1130-
"when": "dvc.params.file.active && !dvc.experiment.running.workspace && dvc.commands.available"
1130+
"when": "dvc.experiments.file.active && !dvc.experiment.running.workspace && dvc.commands.available"
11311131
}
11321132
],
11331133
"view/item/context": [

extension/src/experiments/context.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const setContextOnDidChangeParamsFiles = (
1616
return
1717
}
1818

19-
if (!getParamsFiles().has(path)) {
19+
if (!getParamsFiles().has(path) && !path.endsWith('dvc.yaml')) {
2020
return
2121
}
2222
setActiveEditorContext(true)
@@ -39,21 +39,25 @@ const setContextOnDidChangeActiveEditor = (
3939
}
4040

4141
const isParamsFile = getParamsFiles().has(path)
42+
const isDvcYaml = path.endsWith('dvc.yaml')
4243

43-
setActiveEditorContext(isParamsFile)
44+
setActiveEditorContext(isParamsFile || isDvcYaml)
4445
})
4546

4647
export const setContextForEditorTitleIcons = (
4748
dvcRoot: string,
4849
disposer: (() => void) & Disposer,
4950
getParamsFiles: () => Set<string>,
50-
paramsFileFocused: EventEmitter<string | undefined>,
51+
experimentsFileFocused: EventEmitter<string | undefined>,
5152
onDidChangeColumns: Event<void>
5253
): void => {
53-
const setActiveEditorContext = (paramsFileActive: boolean) => {
54-
void setContextValue(ContextKey.PARAMS_FILE_ACTIVE, paramsFileActive)
55-
const activeDvcRoot = paramsFileActive ? dvcRoot : undefined
56-
paramsFileFocused.fire(activeDvcRoot)
54+
const setActiveEditorContext = (experimentsFileActive: boolean) => {
55+
void setContextValue(
56+
ContextKey.EXPERIMENTS_FILE_ACTIVE,
57+
experimentsFileActive
58+
)
59+
const activeDvcRoot = experimentsFileActive ? dvcRoot : undefined
60+
experimentsFileFocused.fire(activeDvcRoot)
5761
}
5862

5963
disposer.track(

extension/src/experiments/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type ModifiedExperimentAndRunCommandId =
5656
| typeof AvailableCommands.EXPERIMENT_RESET_AND_RUN
5757

5858
export class Experiments extends BaseRepository<TableData> {
59-
public readonly onDidChangeIsParamsFileFocused: Event<string | undefined>
59+
public readonly onDidChangeIsExperimentsFileFocused: Event<string | undefined>
6060
public readonly onDidChangeExperiments: Event<void>
6161
public readonly onDidChangeColumns: Event<void>
6262
public readonly onDidChangeColumnOrderOrStatus: Event<void>
@@ -69,7 +69,7 @@ export class Experiments extends BaseRepository<TableData> {
6969
private readonly experiments: ExperimentsModel
7070
private readonly columns: ColumnsModel
7171

72-
private readonly paramsFileFocused = this.dispose.track(
72+
private readonly experimentsFileFocused = this.dispose.track(
7373
new EventEmitter<string | undefined>()
7474
)
7575

@@ -123,7 +123,7 @@ export class Experiments extends BaseRepository<TableData> {
123123
this.addStage = addStage
124124
this.selectBranches = selectBranches
125125

126-
this.onDidChangeIsParamsFileFocused = this.paramsFileFocused.event
126+
this.onDidChangeIsExperimentsFileFocused = this.experimentsFileFocused.event
127127
this.onDidChangeExperiments = this.experimentsChanged.event
128128
this.onDidChangeColumns = this.columnsChanged.event
129129
this.onDidChangeColumnOrderOrStatus = this.columnsOrderOrStatusChanged.event
@@ -594,7 +594,7 @@ export class Experiments extends BaseRepository<TableData> {
594594
this.dvcRoot,
595595
this.dispose,
596596
() => this.columns.getParamsFiles(),
597-
this.paramsFileFocused,
597+
this.experimentsFileFocused,
598598
this.onDidChangeColumns
599599
)
600600
}

extension/src/experiments/workspace.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
6565

6666
private readonly checkpointsChanged: EventEmitter<void>
6767

68-
private focusedParamsDvcRoot: string | undefined
68+
private focusedFileDvcRoot: string | undefined
6969

7070
constructor(
7171
internalCommands: InternalCommands,
@@ -327,8 +327,8 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
327327
)
328328

329329
experiments.dispose.track(
330-
experiments.onDidChangeIsParamsFileFocused(
331-
dvcRoot => (this.focusedParamsDvcRoot = dvcRoot)
330+
experiments.onDidChangeIsExperimentsFileFocused(
331+
dvcRoot => (this.focusedFileDvcRoot = dvcRoot)
332332
)
333333
)
334334

@@ -362,7 +362,7 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
362362
public getFocusedOrOnlyOrPickProject() {
363363
return (
364364
this.focusedWebviewDvcRoot ||
365-
this.focusedParamsDvcRoot ||
365+
this.focusedFileDvcRoot ||
366366
this.getOnlyOrPickProject()
367367
)
368368
}

extension/src/test/suite/experiments/index.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ suite('Experiments Test Suite', () => {
19621962
await window.showTextDocument(paramsFile)
19631963

19641964
const mockContext: { [key: string]: unknown } = {
1965-
'dvc.params.file.active': false
1965+
'dvc.experiments.file.active': false
19661966
}
19671967

19681968
const mockSetContextValue = stub(VscodeContext, 'setContextValue')
@@ -1975,8 +1975,8 @@ suite('Experiments Test Suite', () => {
19751975
await experiments.isReady()
19761976

19771977
expect(
1978-
mockContext['dvc.params.file.active'],
1979-
'should set dvc.params.file.active to true when a params file is open and the extension starts'
1978+
mockContext['dvc.experiments.file.active'],
1979+
'should set dvc.experiments.file.active to true when a params file is open and the extension starts'
19801980
).to.be.true
19811981

19821982
mockSetContextValue.resetHistory()
@@ -1987,8 +1987,8 @@ suite('Experiments Test Suite', () => {
19871987
await startupEditorClosed
19881988

19891989
expect(
1990-
mockContext['dvc.params.file.active'],
1991-
'should set dvc.params.file.active to false when the params file in the active editor is closed'
1990+
mockContext['dvc.experiments.file.active'],
1991+
'should set dvc.experiments.file.active to false when the params file in the active editor is closed'
19921992
).to.be.false
19931993

19941994
mockSetContextValue.resetHistory()
@@ -2001,16 +2001,16 @@ suite('Experiments Test Suite', () => {
20012001
const activeEditorClosed = getActiveEditorUpdatedEvent()
20022002

20032003
expect(
2004-
mockContext['dvc.params.file.active'],
2005-
'should set dvc.params.file.active to true when a params file is in the active editor'
2004+
mockContext['dvc.experiments.file.active'],
2005+
'should set dvc.experiments.file.active to true when a params file is in the active editor'
20062006
).to.be.true
20072007

20082008
await closeAllEditors()
20092009
await activeEditorClosed
20102010

20112011
expect(
2012-
mockContext['dvc.params.file.active'],
2013-
'should set dvc.params.file.active to false when the params file in the active editor is closed again'
2012+
mockContext['dvc.experiments.file.active'],
2013+
'should set dvc.experiments.file.active to false when the params file in the active editor is closed again'
20142014
).to.be.false
20152015
})
20162016

extension/src/test/suite/experiments/workspace.test.ts

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,15 @@ suite('Workspace Experiments Test Suite', () => {
103103
expect(mockQuickPickOne).to.not.be.called
104104
})
105105

106-
it('should not prompt to pick a project if a params file is focused', async () => {
106+
it('should not prompt to pick a project if a params file or dvc.yaml is focused', async () => {
107107
const mockQuickPickOne = stub(QuickPick, 'quickPickOne').resolves(
108108
dvcDemoPath
109109
)
110+
const mockRunExperiment = stub(
111+
DvcRunner.prototype,
112+
'runExperiment'
113+
).resolves(undefined)
114+
stub(DvcReader.prototype, 'listStages').resolves('train')
110115

111116
const { workspaceExperiments, experiments } =
112117
buildMultiRepoExperiments(disposable)
@@ -119,32 +124,37 @@ suite('Workspace Experiments Test Suite', () => {
119124

120125
expect(await focusedWebview).to.equal(dvcDemoPath)
121126

122-
const focusedParamsFile = new Promise(resolve => {
123-
const listener: Disposable = experiments.onDidChangeIsParamsFileFocused(
124-
(event: string | undefined) => {
125-
listener.dispose()
126-
return resolve(event)
127-
}
128-
)
129-
})
127+
const getDvcRootFocusedEvent = () =>
128+
new Promise(resolve => {
129+
const listener: Disposable =
130+
experiments.onDidChangeIsExperimentsFileFocused(
131+
(event: string | undefined) => {
132+
listener.dispose()
133+
return resolve(event)
134+
}
135+
)
136+
})
130137

131-
const paramsFile = Uri.file(join(dvcDemoPath, 'params.yaml'))
132-
await window.showTextDocument(paramsFile)
138+
const testFile = async (path: string) => {
139+
const focusedDvcRoot = getDvcRootFocusedEvent()
140+
const uri = Uri.file(join(dvcDemoPath, path))
141+
await window.showTextDocument(uri)
133142

134-
expect(await focusedParamsFile).to.equal(dvcDemoPath)
143+
expect(await focusedDvcRoot).to.equal(dvcDemoPath)
135144

136-
mockQuickPickOne.resetHistory()
145+
mockQuickPickOne.resetHistory()
137146

138-
const mockRunExperiment = stub(
139-
DvcRunner.prototype,
140-
'runExperiment'
141-
).resolves(undefined)
147+
await workspaceExperiments.getCwdThenRun(
148+
AvailableCommands.EXPERIMENT_RUN
149+
)
142150

143-
stub(DvcReader.prototype, 'listStages').resolves('train')
144-
await workspaceExperiments.getCwdThenRun(AvailableCommands.EXPERIMENT_RUN)
151+
expect(mockQuickPickOne).not.to.be.called
152+
expect(mockRunExperiment).to.be.calledWith(dvcDemoPath)
153+
return closeAllEditors()
154+
}
145155

146-
expect(mockQuickPickOne).not.to.be.calledOnce
147-
expect(mockRunExperiment).to.be.calledWith(dvcDemoPath)
156+
await testFile('params.yaml')
157+
await testFile('dvc.yaml')
148158
})
149159
}).timeout(WEBVIEW_TEST_TIMEOUT)
150160

extension/src/test/suite/vscode/recommend.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import { join } from 'path'
2-
import { afterEach, beforeEach, describe, it, suite } from 'mocha'
2+
import { afterEach, before, beforeEach, describe, it, suite } from 'mocha'
33
import { expect } from 'chai'
44
import { MessageItem, Uri, window } from 'vscode'
55
import { restore, stub } from 'sinon'
66
import { closeAllEditors } from '../util'
77
import { dvcDemoPath } from '../../util'
88
import * as Extensions from '../../../vscode/extensions'
9+
import { recommendRedHatExtensionOnce } from '../../../vscode/recommend'
910

1011
suite('Recommend Test Suite', () => {
12+
const openFileInEditor = (fileName: string) =>
13+
window.showTextDocument(Uri.file(join(dvcDemoPath, fileName)))
14+
15+
before(async () => {
16+
await openFileInEditor('dvc.lock') // clear any existing recommendation
17+
return closeAllEditors()
18+
})
19+
1120
beforeEach(() => {
1221
restore()
1322
})
@@ -16,11 +25,9 @@ suite('Recommend Test Suite', () => {
1625
return closeAllEditors()
1726
})
1827

19-
const openFileInEditor = (fileName: string) =>
20-
window.showTextDocument(Uri.file(join(dvcDemoPath, fileName)))
21-
2228
describe('recommendRedHatExtensionOnce', () => {
2329
it('should only recommend the red hat yaml extension once per session', async () => {
30+
recommendRedHatExtensionOnce()
2431
stub(Extensions, 'isInstalled').returns(false)
2532
const mockShowInformationMessage = stub(
2633
window,

extension/src/vscode/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ export enum ContextKey {
66
EXPERIMENT_CHECKPOINTS = 'dvc.experiment.checkpoints',
77
EXPERIMENT_RUNNING = 'dvc.experiment.running',
88
EXPERIMENT_RUNNING_WORKSPACE = 'dvc.experiment.running.workspace',
9+
EXPERIMENTS_FILE_ACTIVE = 'dvc.experiments.file.active',
910
EXPERIMENTS_FILTERED = 'dvc.experiments.filtered',
1011
EXPERIMENTS_SORTED = 'dvc.experiments.sorted',
1112
EXPERIMENTS_WEBVIEW_ACTIVE = 'dvc.experiments.webview.active',
1213
MULTIPLE_PROJECTS = 'dvc.multiple.projects',
13-
PARAMS_FILE_ACTIVE = 'dvc.params.file.active',
1414
PLOTS_WEBVIEW_ACTIVE = 'dvc.plots.webview.active',
1515
PROJECT_AVAILABLE = 'dvc.project.available',
1616
PROJECT_HAS_DATA = 'dvc.project.hasData',

0 commit comments

Comments
 (0)