Skip to content

Commit

Permalink
Merge branch 'main' into task/extension/create-updateClientsCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome committed Oct 14, 2024
2 parents 9ad1f26 + fef6ff3 commit 5105580
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 80 deletions.
31 changes: 31 additions & 0 deletions vscode/microsoft-kiota/src/commands/closeDescriptionCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as vscode from 'vscode';

import { treeViewId } from "../constants";
import { OpenApiTreeProvider } from "../openApiTreeProvider";
import { updateTreeViewIcons } from '../util';
import { Command } from "./Command";

export class CloseDescriptionCommand extends Command {

public constructor(private _openApiTreeProvider: OpenApiTreeProvider) {
super();
}

public getName(): string {
return `${treeViewId}.closeDescription`;
}

public async execute(): Promise<void> {
const yesAnswer = vscode.l10n.t("Yes");
const response = await vscode.window.showInformationMessage(
vscode.l10n.t("Do you want to remove this API description?"),
yesAnswer,
vscode.l10n.t("No")
);
if (response === yesAnswer) {
this._openApiTreeProvider.closeDescription();
await updateTreeViewIcons(treeViewId, false);
}
}

}
19 changes: 19 additions & 0 deletions vscode/microsoft-kiota/src/commands/selectLockCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { extensionId } from "../constants";
import { OpenApiTreeProvider } from "../openApiTreeProvider";
import { loadWorkspaceFile } from "../utilities/file";
import { Command } from "./Command";

export class SelectLockCommand extends Command {
constructor(private _openApiTreeProvider: OpenApiTreeProvider) {
super();
}

public getName(): string {
return `${extensionId}.selectLock`;
}

public async execute(node: any): Promise<void> {
await loadWorkspaceFile(node, this._openApiTreeProvider);
}

}
24 changes: 24 additions & 0 deletions vscode/microsoft-kiota/src/commands/statusCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as vscode from 'vscode';

import { statusBarCommandId } from "../constants";
import { Command } from "./Command";

export class StatusCommand extends Command {

public getName(): string {
return statusBarCommandId;
}

public async execute(): Promise<void> {
const yesAnswer = vscode.l10n.t("Yes");
const response = await vscode.window.showInformationMessage(
vscode.l10n.t("Open installation instructions for kiota?"),
yesAnswer,
vscode.l10n.t("No")
);
if (response === yesAnswer) {
await vscode.env.openExternal(vscode.Uri.parse("https://aka.ms/get/kiota"));
}
}

}
93 changes: 13 additions & 80 deletions vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TelemetryReporter from '@vscode/extension-telemetry';
import * as vscode from "vscode";

import { CodeLensProvider } from "./codelensProvider";
import { CloseDescriptionCommand } from './commands/closeDescriptionCommand';
import { EditPathsCommand } from './commands/editPathsCommand';
import { GenerateClientCommand } from './commands/generate/generateClientCommand';
import { displayGenerationResults } from './commands/generate/generation-util';
Expand All @@ -17,25 +18,23 @@ import { RemoveFromSelectedEndpointsCommand } from './commands/open-api-tree-vie
import { SearchOrOpenApiDescriptionCommand } from './commands/open-api-tree-view/search-or-open-api-description/searchOrOpenApiDescriptionCommand';
import { RegenerateButtonCommand } from './commands/regenerate/regenerateButtonCommand';
import { RegenerateCommand } from './commands/regenerate/regenerateCommand';
import { SelectLockCommand } from './commands/selectLockCommand';
import { StatusCommand } from './commands/statusCommand';
import { UpdateClientsCommand } from './commands/updateClientsCommand';
import { dependenciesInfo, extensionId, statusBarCommandId, treeViewId } from "./constants";
import { DependenciesViewProvider } from "./dependenciesViewProvider";
import { getExtensionSettings } from "./extensionSettings";
import { GeneratedOutputState } from './GeneratedOutputState';
import { getGenerationConfiguration } from './handlers/configurationHandler';
import { getDeepLinkParams, setDeepLinkParams } from './handlers/deepLinkParamsHandler';
import { UriHandler } from './handlers/uriHandler';
import {
ClientOrPluginProperties
} from "./kiotaInterop";
import { checkForLockFileAndPrompt } from "./migrateFromLockFile";
import { OpenApiTreeNode, OpenApiTreeProvider } from "./openApiTreeProvider";
import { WorkspaceGenerationContext } from "./types/WorkspaceGenerationContext";
import {
updateTreeViewIcons
} from "./util";
import { IntegrationParams, validateDeepLinkQueryParams } from './utilities/deep-linking';
import { IntegrationParams } from './utilities/deep-linking';
import { loadWorkspaceFile } from './utilities/file';
import { openTreeViewWithProgress } from './utilities/progress';
import { updateStatusBarItem } from './utilities/status';
import { loadTreeView } from "./workspaceTreeProvider";

Expand All @@ -61,6 +60,7 @@ export async function activate(
workspaceGenerationContext = { ...workspaceGenerationContext, ...params };
};

const uriHandler = new UriHandler(context, openApiTreeProvider);
const migrateFromLockFileCommand = new MigrateFromLockFileCommand(context);
const addAllToSelectedEndpointsCommand = new AddAllToSelectedEndpointsCommand(openApiTreeProvider);
const addToSelectedEndpointsCommand = new AddToSelectedEndpointsCommand(openApiTreeProvider);
Expand All @@ -73,55 +73,20 @@ export async function activate(
const generateClientCommand = new GenerateClientCommand(openApiTreeProvider, context, dependenciesInfoProvider, setWorkspaceGenerationContext);
const regenerateCommand = new RegenerateCommand(context, openApiTreeProvider);
const regenerateButtonCommand = new RegenerateButtonCommand(context, openApiTreeProvider);
const closeDescriptionCommand = new CloseDescriptionCommand(openApiTreeProvider);
const statusCommand = new StatusCommand();
const selectLockCommand = new SelectLockCommand(openApiTreeProvider);
const updateClientsCommand = new UpdateClientsCommand(context);

await loadTreeView(context);
await checkForLockFileAndPrompt(context);
let codeLensProvider = new CodeLensProvider();
context.subscriptions.push(
vscode.window.registerUriHandler({
handleUri: async (uri: vscode.Uri) => {
if (uri.path === "/") {
return;
}
const queryParameters = getQueryParameters(uri);
if (uri.path.toLowerCase() === "/opendescription") {
let [params, errorsArray] = validateDeepLinkQueryParams(queryParameters);
setDeepLinkParams(params);
reporter.sendTelemetryEvent("DeepLink.OpenDescription initialization status", {
"queryParameters": JSON.stringify(queryParameters),
"validationErrors": errorsArray.join(", ")
});

let deepLinkParams = getDeepLinkParams();
if (deepLinkParams.descriptionurl) {
await openTreeViewWithProgress(() => openApiTreeProvider.setDescriptionUrl(deepLinkParams.descriptionurl!));
return;
}
}
void vscode.window.showErrorMessage(
vscode.l10n.t("Invalid URL, please check the documentation for the supported URLs")
);
}
}),

vscode.window.registerUriHandler({ handleUri: async (uri: vscode.Uri) => await uriHandler.handleUri(uri) }),
vscode.languages.registerCodeLensProvider('json', codeLensProvider),
reporter,
registerCommandWithTelemetry(reporter,
`${extensionId}.selectLock`,
(x) => loadWorkspaceFile(x, openApiTreeProvider)
),
registerCommandWithTelemetry(reporter, statusBarCommandId, async () => {
const yesAnswer = vscode.l10n.t("Yes");
const response = await vscode.window.showInformationMessage(
vscode.l10n.t("Open installation instructions for kiota?"),
yesAnswer,
vscode.l10n.t("No")
);
if (response === yesAnswer) {
await vscode.env.openExternal(vscode.Uri.parse("https://aka.ms/get/kiota"));
}
}),
registerCommandWithTelemetry(reporter, selectLockCommand.getName(), async (x) => await loadWorkspaceFile(x, openApiTreeProvider)),
registerCommandWithTelemetry(reporter, statusCommand.getName(), async () => await statusCommand.execute()),
vscode.window.registerWebviewViewProvider(
dependenciesInfo,
dependenciesInfoProvider
Expand All @@ -146,19 +111,7 @@ export async function activate(
registerCommandWithTelemetry(reporter, searchOrOpenApiDescriptionCommand.getName(),
async (searchParams: Partial<IntegrationParams> = {}) => await searchOrOpenApiDescriptionCommand.execute(searchParams)
),
registerCommandWithTelemetry(reporter, `${treeViewId}.closeDescription`, async () => {
const yesAnswer = vscode.l10n.t("Yes");
const response = await vscode.window.showInformationMessage(
vscode.l10n.t("Do you want to remove this API description?"),
yesAnswer,
vscode.l10n.t("No")
);
if (response === yesAnswer) {
openApiTreeProvider.closeDescription();
await updateTreeViewIcons(treeViewId, false);
}
}
),
registerCommandWithTelemetry(reporter, closeDescriptionCommand.getName(), async () => await closeDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, filterDescriptionCommand.getName(), async () => await filterDescriptionCommand.execute()),
registerCommandWithTelemetry(reporter, editPathsCommand.getName(), async (clientOrPluginKey: string, clientOrPluginObject: ClientOrPluginProperties, generationType: string) => {
setWorkspaceGenerationContext({ clientOrPluginKey, clientOrPluginObject, generationType });
Expand Down Expand Up @@ -196,25 +149,5 @@ function registerCommandWithTelemetry(reporter: TelemetryReporter, command: stri
}, thisArg);
}

async function loadEditPaths(clientOrPluginKey: string, clientObject: any, openApiTreeProvider: OpenApiTreeProvider): Promise<void> {
await openTreeViewWithProgress(() => openApiTreeProvider.loadEditPaths(clientOrPluginKey, clientObject));
}



function getQueryParameters(uri: vscode.Uri): Record<string, string> {
const query = uri.query;
if (!query) {
return {};
}
const queryParameters = (query.startsWith('?') ? query.substring(1) : query).split("&");
const parameters = {} as Record<string, string>;
queryParameters.forEach((element) => {
const keyValue = element.split("=");
parameters[keyValue[0].toLowerCase()] = decodeURIComponent(keyValue[1]);
});
return parameters;
}

// This method is called when your extension is deactivated
export function deactivate() { }
51 changes: 51 additions & 0 deletions vscode/microsoft-kiota/src/handlers/uriHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as vscode from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';

import { OpenApiTreeProvider } from "../openApiTreeProvider";
import { validateDeepLinkQueryParams } from '../utilities/deep-linking';
import { openTreeViewWithProgress } from '../utilities/progress';
import { setDeepLinkParams, getDeepLinkParams } from './deepLinkParamsHandler';

export class UriHandler {
constructor(private context: vscode.ExtensionContext, private openApiTreeProvider: OpenApiTreeProvider) { }

async handleUri(uri: vscode.Uri) {
if (uri.path === "/") {
return;
}
const queryParameters = this.getQueryParameters(uri);
if (uri.path.toLowerCase() === "/opendescription") {
let [params, errorsArray] = validateDeepLinkQueryParams(queryParameters);
setDeepLinkParams(params);

const reporter = new TelemetryReporter(this.context.extension.packageJSON.telemetryInstrumentationKey);
reporter.sendTelemetryEvent("DeepLink.OpenDescription initialization status", {
"queryParameters": JSON.stringify(queryParameters),
"validationErrors": errorsArray.join(", ")
});

let deepLinkParams = getDeepLinkParams();
if (deepLinkParams.descriptionurl) {
await openTreeViewWithProgress(() => this.openApiTreeProvider.setDescriptionUrl(deepLinkParams.descriptionurl!));
return;
}
}
void vscode.window.showErrorMessage(
vscode.l10n.t("Invalid URL, please check the documentation for the supported URLs")
);
}

private getQueryParameters(uri: vscode.Uri): Record<string, string> {
const query = uri.query;
if (!query) {
return {};
}
const queryParameters = (query.startsWith('?') ? query.substring(1) : query).split("&");
const parameters = {} as Record<string, string>;
queryParameters.forEach((element) => {
const keyValue = element.split("=");
parameters[keyValue[0].toLowerCase()] = decodeURIComponent(keyValue[1]);
});
return parameters;
}
}

0 comments on commit 5105580

Please sign in to comment.