зеркало из https://github.com/microsoft/kiota.git
Fix: Workspace file display (#5029)
This commit is contained in:
Родитель
c6d2789b52
Коммит
72e3f8b9b1
|
@ -409,6 +409,10 @@
|
|||
{
|
||||
"command": "kiota.regenerate",
|
||||
"title": "%kiota.openApiExplorer.regenerateButton.title%"
|
||||
},
|
||||
{
|
||||
"command": "kiota.workspace.refresh",
|
||||
"title": "%kiota.openApiExplorer.refresh.title%"
|
||||
}
|
||||
],
|
||||
"languages": [
|
||||
|
|
|
@ -29,5 +29,6 @@
|
|||
"kiota.openApiExplorer.openFile.title": "Open file",
|
||||
"kiota.workspace.name": "My Workspace",
|
||||
"kiota.openApiExplorer.regenerateButton.title": "Re-generate",
|
||||
"kiota.openApiExplorer.editPaths.title": "Edit paths"
|
||||
"kiota.openApiExplorer.editPaths.title": "Edit paths",
|
||||
"kiota.openApiExplorer.refresh.title": "Refresh"
|
||||
}
|
||||
|
|
|
@ -444,6 +444,7 @@ export async function activate(
|
|||
openApiTreeProvider.setSelectionChanged(false);
|
||||
const workspaceJsonPath = getWorkspaceJsonPath();
|
||||
await loadLockFile({fsPath: workspaceJsonPath}, openApiTreeProvider, clientNameOrPluginName );
|
||||
await vscode.commands.executeCommand('kiota.workspace.refresh');
|
||||
await updateTreeViewIcons(treeViewId, false, true);
|
||||
}
|
||||
async function regenerateClient(clientKey: string, clientObject:any, settings: ExtensionSettings, selectedPaths?: string[]): Promise<void> {
|
||||
|
|
|
@ -42,6 +42,7 @@ export function getWorkspaceJsonDirectory(clientNameOrPluginName?: string): stri
|
|||
return workspaceFolder;
|
||||
}
|
||||
|
||||
//used to store output in the App Package directory in the case where the workspace is a Teams Toolkit Project
|
||||
export function findAppPackageDirectory(directory: string): string | null {
|
||||
if (!fs.existsSync(directory)) {
|
||||
return null;
|
||||
|
|
|
@ -6,42 +6,54 @@ import { getWorkspaceJsonPath } from './util';
|
|||
|
||||
|
||||
export class WorkspaceTreeProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
|
||||
constructor(public isWSPresent: boolean) {
|
||||
}
|
||||
async getChildren(element?: vscode.TreeItem): Promise<vscode.TreeItem[]> {
|
||||
if (!this.isWSPresent) {
|
||||
return [];
|
||||
}
|
||||
if (!element) {
|
||||
return [new vscode.TreeItem(KIOTA_WORKSPACE_FILE, vscode.TreeItemCollapsibleState.None)];
|
||||
}
|
||||
public isWSPresent: boolean;
|
||||
private _onDidChangeTreeData: vscode.EventEmitter<vscode.TreeItem | undefined | null | void> = new vscode.EventEmitter<vscode.TreeItem | undefined | null | void>();
|
||||
readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | null | void> = this._onDidChangeTreeData.event;
|
||||
constructor( isWSPresent: boolean) {
|
||||
this.isWSPresent = isWSPresent;
|
||||
}
|
||||
|
||||
async refreshView(): Promise<void> {
|
||||
this._onDidChangeTreeData.fire();
|
||||
}
|
||||
|
||||
async getChildren(element?: vscode.TreeItem): Promise<vscode.TreeItem[]> {
|
||||
if (!this.isWSPresent) {
|
||||
return [];
|
||||
}
|
||||
|
||||
getTreeItem(element: vscode.TreeItem): vscode.TreeItem {
|
||||
if (element) {
|
||||
element.command = {
|
||||
command: 'kiota.workspace.openWorkspaceFile',
|
||||
title: vscode.l10n.t("Open File"),
|
||||
arguments: [vscode.Uri.file(getWorkspaceJsonPath())]
|
||||
};
|
||||
element.contextValue = 'file';
|
||||
}
|
||||
return element;
|
||||
if (!element) {
|
||||
return [new vscode.TreeItem(KIOTA_WORKSPACE_FILE, vscode.TreeItemCollapsibleState.None)];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
getTreeItem(element: vscode.TreeItem): vscode.TreeItem {
|
||||
if (element) {
|
||||
element.command = {
|
||||
command: 'kiota.workspace.openWorkspaceFile',
|
||||
title: vscode.l10n.t("Open File"),
|
||||
arguments: [vscode.Uri.file(getWorkspaceJsonPath())]
|
||||
};
|
||||
element.contextValue = 'file';
|
||||
}
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
||||
async function openResource(resource: vscode.Uri): Promise<void> {
|
||||
await vscode.window.showTextDocument(resource);
|
||||
}
|
||||
async function isKiotaWorkspaceFilePresent(): Promise<boolean> {
|
||||
const workspaceFileDir = path.resolve(getWorkspaceJsonPath());
|
||||
try {
|
||||
await fs.promises.access(workspaceFileDir);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if(!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0){
|
||||
return false;
|
||||
}
|
||||
const workspaceFileDir = path.resolve(getWorkspaceJsonPath());
|
||||
try {
|
||||
await fs.promises.access(workspaceFileDir);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function loadTreeView(context: vscode.ExtensionContext): Promise<void> {
|
||||
|
@ -54,5 +66,6 @@ export async function loadTreeView(context: vscode.ExtensionContext): Promise<vo
|
|||
context.subscriptions.push(vscode.commands.registerCommand('kiota.workspace.openWorkspaceFile', openResource));
|
||||
context.subscriptions.push(vscode.commands.registerCommand('kiota.workspace.refresh', async () => {
|
||||
treeDataProvider.isWSPresent = await isKiotaWorkspaceFilePresent();
|
||||
await treeDataProvider.refreshView();
|
||||
}));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче