-
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.
Display DAG in Markdown Preview editor (#4244)
* wire up prototype for displaying DAG * recommend installing mermaid support extension * update package.json * add unit test for extension recommendation * add integration test for showing the DAG * stub call to dag in extension test * handle dag command throwing error
- Loading branch information
1 parent
25248b1
commit ee124ed
Showing
18 changed files
with
362 additions
and
19 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
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
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,27 @@ | ||
import { AvailableCommands, InternalCommands } from '../commands/internal' | ||
import { BaseData } from '../data' | ||
|
||
export class PipelineData extends BaseData<string> { | ||
constructor(dvcRoot: string, internalCommands: InternalCommands) { | ||
super( | ||
dvcRoot, | ||
internalCommands, | ||
[{ name: 'update', process: () => this.update() }], | ||
['dvc.yaml'] | ||
) | ||
|
||
void this.managedUpdate() | ||
} | ||
|
||
public managedUpdate() { | ||
return this.processManager.run('update') | ||
} | ||
|
||
public async update(): Promise<void> { | ||
const dag = await this.internalCommands.executeCommand( | ||
AvailableCommands.DAG, | ||
this.dvcRoot | ||
) | ||
return this.notifyChanged(dag) | ||
} | ||
} |
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,34 @@ | ||
import { join } from 'path' | ||
import { appendFileSync, writeFileSync } from 'fs-extra' | ||
import { PipelineData } from './data' | ||
import { DeferredDisposable } from '../class/deferred' | ||
import { InternalCommands } from '../commands/internal' | ||
import { TEMP_DAG_FILE } from '../cli/dvc/constants' | ||
|
||
export class Pipeline extends DeferredDisposable { | ||
private readonly dvcRoot: string | ||
private readonly data: PipelineData | ||
|
||
constructor(dvcRoot: string, internalCommands: InternalCommands) { | ||
super() | ||
this.dvcRoot = dvcRoot | ||
this.data = this.dispose.track(new PipelineData(dvcRoot, internalCommands)) | ||
|
||
void this.initialize() | ||
} | ||
|
||
public forceRerender() { | ||
return appendFileSync(join(this.dvcRoot, TEMP_DAG_FILE), '\n') | ||
} | ||
|
||
private async initialize() { | ||
this.dispose.track( | ||
this.data.onDidUpdate(data => | ||
writeFileSync(join(this.dvcRoot, TEMP_DAG_FILE), data) | ||
) | ||
) | ||
|
||
await this.data.isReady() | ||
return this.deferred.resolve() | ||
} | ||
} |
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,13 @@ | ||
import { WorkspacePipeline } from './workspace' | ||
import { RegisteredCommands } from '../commands/external' | ||
import { InternalCommands } from '../commands/internal' | ||
|
||
export const registerPipelineCommands = ( | ||
pipelines: WorkspacePipeline, | ||
internalCommands: InternalCommands | ||
): void => { | ||
internalCommands.registerExternalCommand( | ||
RegisteredCommands.PIPELINE_SHOW_DAG, | ||
() => pipelines.showDag() | ||
) | ||
} |
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,63 @@ | ||
import { join } from 'path' | ||
import { commands, Uri } from 'vscode' | ||
import { Pipeline } from '.' | ||
import { TEMP_DAG_FILE } from '../cli/dvc/constants' | ||
import { BaseWorkspace } from '../workspace' | ||
import { | ||
MARKDOWN_MERMAID_EXTENSION_ID, | ||
recommendMermaidSupportExtension | ||
} from '../vscode/recommend' | ||
import { InternalCommands } from '../commands/internal' | ||
import { getOnDidChangeExtensions, isInstalled } from '../vscode/extensions' | ||
|
||
export class WorkspacePipeline extends BaseWorkspace<Pipeline> { | ||
private isMermaidSupportInstalled = isInstalled(MARKDOWN_MERMAID_EXTENSION_ID) | ||
|
||
constructor(internalCommands: InternalCommands) { | ||
super(internalCommands) | ||
|
||
const onDidChangeExtensions = getOnDidChangeExtensions() | ||
this.dispose.track( | ||
onDidChangeExtensions(() => { | ||
const wasMermaidInstalled = this.isMermaidSupportInstalled | ||
this.isMermaidSupportInstalled = isInstalled( | ||
MARKDOWN_MERMAID_EXTENSION_ID | ||
) | ||
if (!wasMermaidInstalled && this.isMermaidSupportInstalled) { | ||
this.renderDagAsMermaid() | ||
} | ||
}) | ||
) | ||
} | ||
|
||
public createRepository(dvcRoot: string) { | ||
const pipeline = this.dispose.track( | ||
new Pipeline(dvcRoot, this.internalCommands) | ||
) | ||
|
||
this.setRepository(dvcRoot, pipeline) | ||
|
||
return pipeline | ||
} | ||
|
||
public async showDag() { | ||
const cwd = await this.getOnlyOrPickProject() | ||
|
||
if (!cwd) { | ||
return | ||
} | ||
|
||
void recommendMermaidSupportExtension() | ||
|
||
return commands.executeCommand( | ||
'markdown.showPreview', | ||
Uri.file(join(cwd, TEMP_DAG_FILE)) | ||
) | ||
} | ||
|
||
private renderDagAsMermaid() { | ||
for (const dvcRoot of this.getDvcRoots()) { | ||
void this.getRepository(dvcRoot).forceRerender() | ||
} | ||
} | ||
} |
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
Oops, something went wrong.