create display generation results command

This commit is contained in:
thewahome 2024-08-14 10:38:57 +03:00
Родитель 239431f3f0
Коммит 1c9346c01c
4 изменённых файлов: 74 добавлений и 42 удалений

Просмотреть файл

@ -0,0 +1,30 @@
import { ExtensionContext } from "vscode";
import { OpenApiTreeProvider } from "../../openApiTreeProvider";
import { GenerateState } from "../../steps";
import { Command } from "../Command";
import { GeneratedOutputState } from "../GeneratedOutputState";
import { displayGenerationResults } from "./generation-results";
export class DisplayGenerationResultsCommand extends Command {
private _context: ExtensionContext;
private _openApiTreeProvider: OpenApiTreeProvider;
public constructor(context: ExtensionContext, openApiTreeProvider: OpenApiTreeProvider) {
super();
this._context = context;
this._openApiTreeProvider = openApiTreeProvider;
}
async execute(config: Partial<GenerateState>): Promise<void> {
const generatedOutput = this._context.workspaceState.get<GeneratedOutputState>('generatedOutput');
if (generatedOutput) {
const { outputPath } = generatedOutput;
await displayGenerationResults(config, outputPath, this._openApiTreeProvider);
// Clear the state
void this._context.workspaceState.update('generatedOutput', undefined);
}
}
}

Просмотреть файл

@ -1,25 +1,25 @@
import * as vscode from "vscode";
import { ExtensionContext } from "vscode";
import { extensionId, treeViewFocusCommand, treeViewId } from "../constants";
import { DependenciesViewProvider } from '../dependenciesViewProvider';
import { ExtensionSettings, getExtensionSettings } from "../extensionSettings";
import { generateClient } from '../generateClient';
import { generatePlugin } from '../generatePlugin';
import { getLanguageInformation, getLanguageInformationForDescription } from "../getLanguageInformation";
import { extensionId, treeViewFocusCommand } from "../../constants";
import { DependenciesViewProvider } from '../../dependenciesViewProvider';
import { ExtensionSettings, getExtensionSettings } from "../../extensionSettings";
import { generateClient } from '../../generateClient';
import { generatePlugin } from '../../generatePlugin';
import { getLanguageInformation, getLanguageInformationForDescription } from "../../getLanguageInformation";
import {
ConsumerOperation,
getLogEntriesForLevel, KiotaGenerationLanguage, KiotaLogEntry, KiotaPluginType,
LogLevel, parseGenerationLanguage, parsePluginType
} from "../kiotaInterop";
import { OpenApiTreeProvider } from "../openApiTreeProvider";
import { GenerateState, generateSteps, GenerationType, parseGenerationType } from "../steps";
import { getWorkspaceJsonDirectory, getWorkspaceJsonPath, updateTreeViewIcons } from "../util";
import { exportLogsAndShowErrors } from '../utilities/logging';
import { showUpgradeWarningMessage } from "../utilities/messaging";
import { GeneratedOutputState } from './GeneratedOutputState';
import { loadLockFile } from "../utilities/file";
import { Command } from "./Command";
} from "../../kiotaInterop";
import { OpenApiTreeProvider } from "../../openApiTreeProvider";
import { GenerateState, generateSteps, GenerationType, parseGenerationType } from "../../steps";
import { getWorkspaceJsonDirectory } from "../../util";
import { exportLogsAndShowErrors } from '../../utilities/logging';
import { showUpgradeWarningMessage } from "../../utilities/messaging";
import { Command } from "../Command";
import { GeneratedOutputState } from '../GeneratedOutputState';
import { displayGenerationResults } from "./generation-results";
export class GenerateClientCommand extends Command {
@ -92,21 +92,11 @@ export class GenerateClientCommand extends Command {
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
await vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(config.workingDirectory ?? getWorkspaceJsonDirectory()), true);
} else {
await this.displayGenerationResults(config, outputPath);
await displayGenerationResults(config, outputPath, this._openApiTreeProvider);
}
}
}
public async displayGenerationResults(config: Partial<GenerateState>, _outputPath: string) {
const clientNameOrPluginName = config.clientClassName || config.pluginName;
this._openApiTreeProvider.refreshView();
const workspaceJsonPath = getWorkspaceJsonPath();
await loadLockFile({ fsPath: workspaceJsonPath }, this._openApiTreeProvider, clientNameOrPluginName);
await vscode.commands.executeCommand('kiota.workspace.refresh');
this._openApiTreeProvider.resetInitialState();
await updateTreeViewIcons(treeViewId, false, true);
}
async generateClientAndRefreshUI(config: Partial<GenerateState>, settings: ExtensionSettings, outputPath: string, selectedPaths: string[]): Promise<KiotaLogEntry[] | undefined> {
const language =
typeof config.language === "string"

Просмотреть файл

@ -0,0 +1,22 @@
import * as vscode from "vscode";
import { treeViewId } from "../../constants";
import { OpenApiTreeProvider } from "../../openApiTreeProvider";
import { GenerateState } from "../../steps";
import { getWorkspaceJsonPath, updateTreeViewIcons } from "../../util";
import { loadLockFile } from "../../utilities/file";
async function displayGenerationResults(config: Partial<GenerateState>, _outputPath: string, openApiTreeProvider: OpenApiTreeProvider) {
const clientNameOrPluginName = config.clientClassName || config.pluginName;
openApiTreeProvider.refreshView();
const workspaceJsonPath = getWorkspaceJsonPath();
await loadLockFile({ fsPath: workspaceJsonPath }, openApiTreeProvider, clientNameOrPluginName);
await vscode.commands.executeCommand('kiota.workspace.refresh');
openApiTreeProvider.resetInitialState();
await updateTreeViewIcons(treeViewId, false, true);
}
export {
displayGenerationResults
};

Просмотреть файл

@ -9,8 +9,7 @@ import { CodeLensProvider } from "./codelensProvider";
import { CloseDescriptionCommand } from './commands/CloseDescriptionCommand';
import { EditPathsCommand } from './commands/EditPathsCommand';
import { FilterDescriptionCommand } from './commands/FilterDescriptionCommand';
import { GenerateClientCommand } from './commands/GenerateClientCommand';
import { GeneratedOutputState } from './commands/GeneratedOutputState';
import { GenerateClientCommand } from './commands/generate-client/GenerateClientCommand';
import { KiotaStatusCommand } from "./commands/KiotaStatusCommand";
import { AddToSelectedEndpointsCommand } from './commands/open-api-tree-node/AddToSelectedEndpointsCommand';
import { OpenDocumentationPageCommand } from "./commands/open-api-tree-node/OpenDocumentationPageCommand";
@ -19,8 +18,8 @@ import { RemoveFromSelectedEndpointsCommand } from './commands/open-api-tree-nod
import { RegenerateButtonCommand } from './commands/regenerate/RegenerateButtonCommand';
import { RegenerateCommand } from './commands/regenerate/RegenerateCommand';
import { SearchOrOpenApiDescriptionCommand } from './commands/SearchOrOpenApiDescriptionCommand';
import { updateStatusBarItem } from './utilities/status-bar';
import { UpdateClientsCommand } from './commands/UpdateClientsCommand';
import { updateStatusBarItem } from './utilities/status-bar';
import { dependenciesInfo, extensionId, statusBarCommandId, treeViewId } from "./constants";
import { DependenciesViewProvider } from "./dependenciesViewProvider";
@ -30,6 +29,7 @@ import { OpenApiTreeNode, OpenApiTreeProvider } from "./openApiTreeProvider";
import { GenerateState } from "./steps";
import { loadLockFile, openTreeViewWithProgress } from './utilities/file';
import { loadTreeView } from "./workspaceTreeProvider";
import { DisplayGenerationResultsCommand } from './commands/generate-client/DisplayGenerationResultsCommand';
let kiotaStatusBarItem: vscode.StatusBarItem;
let clientOrPluginKey: string;
@ -62,6 +62,7 @@ export async function activate(
const removeFromSelectedEndpointsCommand = new RemoveFromSelectedEndpointsCommand(openApiTreeProvider);
const removeAllFromSelectedEndpointsCommand = new RemoveAllFromSelectedEndpointsCommand(openApiTreeProvider);
const updateClientsCommand = new UpdateClientsCommand(context);
const displayGenerationResultsCommand = new DisplayGenerationResultsCommand(context, openApiTreeProvider);
const reporter = new TelemetryReporter(context.extension.packageJSON.telemetryInstrumentationKey);
await loadTreeView(context);
@ -95,10 +96,7 @@ export async function activate(
(x) => loadLockFile(x, openApiTreeProvider)
),
registerCommandWithTelemetry(reporter, statusBarCommandId, await kiotaStatusCommand.execute()),
vscode.window.registerWebviewViewProvider(
dependenciesInfo,
dependenciesInfoProvider
),
vscode.window.registerWebviewViewProvider(dependenciesInfo, dependenciesInfoProvider),
vscode.window.registerTreeDataProvider(treeViewId, openApiTreeProvider),
registerCommandWithTelemetry(reporter, `${treeViewId}.openDocumentationPage`, (openApiTreeNode: OpenApiTreeNode) => openDocumentationPageCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, `${treeViewId}.addToSelectedEndpoints`, (openApiTreeNode: OpenApiTreeNode) => addToSelectedEndpointsCommand.execute(openApiTreeNode)),
@ -106,15 +104,7 @@ export async function activate(
registerCommandWithTelemetry(reporter, `${treeViewId}.removeFromSelectedEndpoints`, (openApiTreeNode: OpenApiTreeNode) => removeFromSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, `${treeViewId}.removeAllFromSelectedEndpoints`, (openApiTreeNode: OpenApiTreeNode) => removeAllFromSelectedEndpointsCommand.execute(openApiTreeNode)),
registerCommandWithTelemetry(reporter, `${treeViewId}.generateClient`, () => generateClientCommand.execute()),
vscode.workspace.onDidChangeWorkspaceFolders(async () => {
const generatedOutput = context.workspaceState.get<GeneratedOutputState>('generatedOutput');
if (generatedOutput) {
const { outputPath } = generatedOutput;
await generateClientCommand.displayGenerationResults(config, outputPath);
// Clear the state
void context.workspaceState.update('generatedOutput', undefined);
}
}),
vscode.workspace.onDidChangeWorkspaceFolders(async () => displayGenerationResultsCommand.execute(config)),
registerCommandWithTelemetry(reporter, `${treeViewId}.searchOrOpenApiDescription`, () => searchOrOpenApiDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, `${treeViewId}.closeDescription`, () => closeDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, `${treeViewId}.filterDescription`, () => filterDescriptionCommand.execute()),