-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add experiment icons to editor/title when params file is open #1740
Changes from all commits
f1a3871
5d8cc37
f2b9fdf
b3a3e23
f97ca0a
92872b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Event, EventEmitter, Memento } from 'vscode' | ||
import { Event, EventEmitter, Memento, window } from 'vscode' | ||
import { ExperimentsModel } from './model' | ||
import { pickExperiments } from './model/quickPicks' | ||
import { pickAndModifyParams } from './model/queue/quickPick' | ||
|
@@ -34,6 +34,8 @@ import { EventName } from '../telemetry/constants' | |
import { Toast } from '../vscode/toast' | ||
import { getInput } from '../vscode/inputBox' | ||
import { createTypedAccumulator } from '../util/object' | ||
import { setContextValue } from '../vscode/context' | ||
import { standardizePath } from '../fileSystem/path' | ||
|
||
export const ExperimentsScale = { | ||
...ColumnType, | ||
|
@@ -42,6 +44,7 @@ export const ExperimentsScale = { | |
} as const | ||
|
||
export class Experiments extends BaseRepository<TableData> { | ||
public readonly onDidChangeIsParamsFileFocused: Event<string | undefined> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] If there are multiple projects in the workspace and a params file for a particular project is in the active editor then we don't want to prompt the user for which project they want to run the command against. |
||
public readonly onDidChangeExperiments: Event<ExperimentsOutput | void> | ||
public readonly onDidChangeColumns: Event<void> | ||
public readonly onDidChangeCheckpoints: Event<void> | ||
|
@@ -55,6 +58,10 @@ export class Experiments extends BaseRepository<TableData> { | |
private readonly columns: ColumnsModel | ||
private readonly checkpoints: CheckpointsModel | ||
|
||
private readonly paramsFileFocused = this.dispose.track( | ||
new EventEmitter<string | undefined>() | ||
) | ||
|
||
private readonly experimentsChanged = this.dispose.track( | ||
new EventEmitter<ExperimentsOutput | void>() | ||
) | ||
|
@@ -80,6 +87,7 @@ export class Experiments extends BaseRepository<TableData> { | |
|
||
this.internalCommands = internalCommands | ||
|
||
this.onDidChangeIsParamsFileFocused = this.paramsFileFocused.event | ||
this.onDidChangeExperiments = this.experimentsChanged.event | ||
this.onDidChangeColumns = this.columnsChanged.event | ||
this.onDidChangeCheckpoints = this.checkpointsChanged.event | ||
|
@@ -113,6 +121,7 @@ export class Experiments extends BaseRepository<TableData> { | |
|
||
this.handleMessageFromWebview() | ||
this.setupInitialData() | ||
this.setActiveEditorContext() | ||
} | ||
|
||
public update() { | ||
|
@@ -537,4 +546,44 @@ export class Experiments extends BaseRepository<TableData> { | |
|
||
return experiment?.id | ||
} | ||
|
||
private setActiveEditorContext() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
const setActiveEditorContext = (active: boolean) => { | ||
setContextValue('dvc.params.fileActive', active) | ||
const activeDvcRoot = active ? this.dvcRoot : undefined | ||
this.paramsFileFocused.fire(activeDvcRoot) | ||
} | ||
|
||
this.dispose.track( | ||
this.onDidChangeColumns(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] Covers startup and changes to files (adding/deleting). |
||
const path = standardizePath(window.activeTextEditor?.document.fileName) | ||
if (!path) { | ||
return | ||
} | ||
|
||
if (!this.columns.getParamsFiles().has(path)) { | ||
return | ||
} | ||
setActiveEditorContext(true) | ||
}) | ||
) | ||
|
||
this.dispose.track( | ||
window.onDidChangeActiveTextEditor(event => { | ||
const path = standardizePath(event?.document.fileName) | ||
if (!path) { | ||
setActiveEditorContext(false) | ||
return | ||
} | ||
|
||
if (path.includes(this.dvcRoot)) { | ||
if (this.columns.getParamsFiles().has(path)) { | ||
setActiveEditorContext(true) | ||
return | ||
} | ||
setActiveEditorContext(false) | ||
} | ||
}) | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Uri } from 'vscode' | ||
|
||
export const standardizePath = (path?: string): string | undefined => { | ||
if (!path) { | ||
return | ||
} | ||
return Uri.file(path).fsPath | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[F] For some reason these do not take ORs with brackets. We may want to split in the future so I think this duplication is ok... and I also hate it.... and it's ok.