-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Focus pipeline when dvc.yaml file is open in the active editor (#4273)
- Loading branch information
1 parent
99a30f4
commit 320e9c5
Showing
8 changed files
with
194 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { dirname } from 'path' | ||
import { EventEmitter, window } from 'vscode' | ||
import { Disposable, Disposer } from '@hediet/std/disposable' | ||
import { ContextKey, setContextValue } from '../vscode/context' | ||
import { standardizePossiblePath } from '../fileSystem/path' | ||
|
||
const setContextOnDidChangeActiveEditor = ( | ||
setActiveEditorContext: (path: string) => void, | ||
dvcRoot: string | ||
): Disposable => | ||
window.onDidChangeActiveTextEditor(event => { | ||
const path = standardizePossiblePath(event?.document.fileName) | ||
if (!path) { | ||
setActiveEditorContext('') | ||
return | ||
} | ||
|
||
if (!path.includes(dvcRoot)) { | ||
return | ||
} | ||
|
||
setActiveEditorContext(path) | ||
}) | ||
|
||
export const setContextForEditorTitleIcons = ( | ||
dvcRoot: string, | ||
disposer: (() => void) & Disposer, | ||
pipelineFileFocused: EventEmitter<string | undefined> | ||
): void => { | ||
const setActiveEditorContext = (path: string) => { | ||
const pipeline = path.endsWith('dvc.yaml') ? dirname(path) : undefined | ||
void setContextValue(ContextKey.PIPELINE_FILE_ACTIVE, !!pipeline) | ||
pipelineFileFocused.fire(pipeline) | ||
} | ||
|
||
const activePath = window.activeTextEditor?.document?.fileName | ||
if (activePath?.startsWith(dvcRoot)) { | ||
setActiveEditorContext(activePath) | ||
} | ||
|
||
disposer.track( | ||
setContextOnDidChangeActiveEditor(setActiveEditorContext, dvcRoot) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters