-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contrib): fix preview in vscode / project management (#6878)
Signed-off-by: Thomas Bétrancourt <[email protected]>
- Loading branch information
Showing
32 changed files
with
760 additions
and
225 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,60 @@ | ||
import * as vscode from "vscode"; | ||
import * as uri from "vscode-uri"; | ||
import * as path from "path"; | ||
|
||
|
||
export function isCDSWorkflowFile(document: vscode.TextDocument) { | ||
if (!isCDSFile(document)) { | ||
return false; | ||
} | ||
|
||
if (getParentDirectory(document?.uri) !== 'workflows') { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
export function isCDSWorkerModelFile(document: vscode.TextDocument) { | ||
if (!isCDSFile(document)) { | ||
return false; | ||
} | ||
|
||
if (getParentDirectory(document?.uri) !== 'worker-models') { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
export function isCDSActionFile(document: vscode.TextDocument) { | ||
if (!isCDSFile(document)) { | ||
return false; | ||
} | ||
|
||
if (getParentDirectory(document?.uri) !== 'actions') { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
function isCDSFile(document: vscode.TextDocument) { | ||
if (document.languageId !== 'yaml') { | ||
return false; | ||
} | ||
|
||
if (document.isUntitled) { | ||
return false; | ||
} | ||
|
||
return getParentDirectory(getParentPath(document.uri)) === '.cds'; | ||
} | ||
|
||
function getParentPath(filepath: uri.URI) { | ||
return uri.Utils.dirname(uri.Utils.resolvePath(filepath)); | ||
} | ||
|
||
function getParentDirectory(filepath: uri.URI): string { | ||
return path.basename(getParentPath(filepath).path); | ||
} |
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,4 @@ | ||
export interface Context { | ||
readonly context: string; | ||
readonly host: string | ||
} |
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,7 @@ | ||
export interface Project { | ||
readonly key: string; | ||
readonly name: string; | ||
readonly description: string | ||
readonly favorite: 'true' | 'false'; | ||
readonly found: boolean; | ||
} |
1 change: 1 addition & 0 deletions
1
...ib/vscode-cds/src/lib/cds/models/index.ts → contrib/vscode-cds/src/cds/models/index.ts
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { Context } from './Context'; | ||
export { Project } from './Project'; |
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,14 @@ | ||
import { Command } from "."; | ||
import { Cache } from "../utils/cache"; | ||
|
||
export const ClearCacheCommandID = 'vscode-cds.clearCache'; | ||
|
||
export class ClearCacheCommand implements Command { | ||
getID(): string { | ||
return ClearCacheCommandID | ||
} | ||
|
||
async run(): Promise<void> { | ||
Cache.clear(); | ||
} | ||
} |
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,15 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export interface Command { | ||
getID(): string | ||
run(): Promise<void> | ||
} | ||
|
||
export function registerCommand(context: vscode.ExtensionContext, command: Command) { | ||
context.subscriptions.push(vscode.commands.registerCommand(command.getID(), async () => { | ||
await command.run(); | ||
})); | ||
} | ||
|
||
export { SetCurrentContextCommand as SetCurrentContext, SetCurrentContextCommandID } from './set-current-context'; | ||
export { SetCurrentProjectCommand as SetCurrentProject, SetCurrentProjectCommandID } from './set-current-project'; |
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,21 @@ | ||
import * as vscode from "vscode"; | ||
|
||
import { Command } from "."; | ||
import { isCDSWorkflowFile } from "../cds/file_utils"; | ||
import { CDSPreview } from "../preview"; | ||
|
||
export const PreviewWorkflowCommandID = 'vscode-cds.previewWorkflow'; | ||
|
||
export class PreviewWorkflowCommand implements Command { | ||
constructor(private instance: CDSPreview) { } | ||
|
||
getID(): string { | ||
return PreviewWorkflowCommandID | ||
} | ||
|
||
async run(): Promise<void> { | ||
if (vscode.window.activeTextEditor?.document.uri && isCDSWorkflowFile(vscode.window.activeTextEditor.document)) { | ||
this.instance.load(vscode.window.activeTextEditor?.document.uri); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,23 @@ | ||
export const setCurrentContextCommandID = 'vscode-cds.setCurrentContext'; | ||
import { Command } from "."; | ||
import { selectContext } from "../forms/select-context"; | ||
import { CDS } from "../cds"; | ||
import { Journal } from "../utils/journal"; | ||
import { updateContext } from "../utils/context"; | ||
|
||
export const SetCurrentContextCommandID = 'vscode-cds.setCurrentContext'; | ||
|
||
export class SetCurrentContextCommand implements Command { | ||
getID(): string { | ||
return SetCurrentContextCommandID | ||
} | ||
|
||
async run(): Promise<void> { | ||
const context = await selectContext(); | ||
try { | ||
await CDS.setCurrentContext(context.context); | ||
await updateContext(); | ||
} catch (e) { | ||
Journal.logError(e as Error); | ||
} | ||
} | ||
} |
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,23 @@ | ||
import { Command } from "."; | ||
import { selectProject } from "../forms/select-project"; | ||
import { CDS } from "../cds"; | ||
import { Journal } from "../utils/journal"; | ||
import { setProject } from "../events/project"; | ||
|
||
export const SetCurrentProjectCommandID = 'vscode-cds.setCurrentProject'; | ||
|
||
export class SetCurrentProjectCommand implements Command { | ||
getID(): string { | ||
return SetCurrentProjectCommandID | ||
} | ||
|
||
async run(): Promise<void> { | ||
const project = await selectProject(); | ||
try { | ||
await CDS.setCurrentProject(project); | ||
setProject(project); | ||
} catch (e) { | ||
Journal.logError(e as Error); | ||
} | ||
} | ||
} |
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,33 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
import { SetCurrentProjectCommandID } from '../commands'; | ||
import { onProjectChanged } from '../events/project'; | ||
import { onGitRepositoryChanged } from '../events/git-repository'; | ||
|
||
let instance: vscode.StatusBarItem; | ||
|
||
export function createProjectStatusBarItem(context: vscode.ExtensionContext) { | ||
instance = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100); | ||
instance.command = SetCurrentProjectCommandID; | ||
instance.tooltip = 'Current CDS project'; | ||
context.subscriptions.push(instance); | ||
|
||
context.subscriptions.push(onGitRepositoryChanged(repository => { | ||
if (repository) { | ||
instance.show(); | ||
} else { | ||
instance.hide(); | ||
} | ||
})); | ||
|
||
context.subscriptions.push(onProjectChanged(project => { | ||
if (project) { | ||
instance.text = `${project.name} (${project.key})`; | ||
} else { | ||
instance.text = 'Select a CDS project'; | ||
} | ||
|
||
instance.color = (!!!project || project.found) ? '' : '#FF0000'; | ||
instance.show(); | ||
})); | ||
} |
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.