Skip to content

Commit

Permalink
skip predefined q&a when deeplinking
Browse files Browse the repository at this point in the history
  • Loading branch information
fey101 committed Aug 27, 2024
1 parent b00543e commit d905b04
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 221 deletions.
5 changes: 3 additions & 2 deletions vscode/microsoft-kiota/src/dependenciesViewProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { generationLanguageToString, KiotaGenerationLanguage, LanguageInformation, LanguagesInformation } from './kiotaInterop';
import { KiotaGenerationLanguage } from './enums';
import { generationLanguageToString, LanguageInformation, LanguagesInformation } from './kiotaInterop';

export class DependenciesViewProvider implements vscode.WebviewViewProvider {
private _view?: vscode.WebviewView;
Expand Down Expand Up @@ -62,4 +63,4 @@ export class DependenciesViewProvider implements vscode.WebviewViewProvider {
</html>`;
}

}
}
38 changes: 38 additions & 0 deletions vscode/microsoft-kiota/src/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export enum GenerationType {
// eslint-disable-next-line @typescript-eslint/naming-convention
Client = 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
Plugin = 1,
// eslint-disable-next-line @typescript-eslint/naming-convention
ApiManifest = 2,
};

export enum KiotaGenerationLanguage {
// eslint-disable-next-line @typescript-eslint/naming-convention
CSharp = 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
Java = 1,
// eslint-disable-next-line @typescript-eslint/naming-convention
TypeScript = 2,
// eslint-disable-next-line @typescript-eslint/naming-convention
PHP = 3,
// eslint-disable-next-line @typescript-eslint/naming-convention
Python = 4,
// eslint-disable-next-line @typescript-eslint/naming-convention
Go = 5,
// eslint-disable-next-line @typescript-eslint/naming-convention
Swift = 6,
// eslint-disable-next-line @typescript-eslint/naming-convention
Ruby = 7,
// eslint-disable-next-line @typescript-eslint/naming-convention
CLI = 8,
};

export enum KiotaPluginType {
// eslint-disable-next-line @typescript-eslint/naming-convention
OpenAI = 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
ApiManifest = 1,
// eslint-disable-next-line @typescript-eslint/naming-convention
ApiPlugin = 2,
};
70 changes: 42 additions & 28 deletions vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from "vscode";
import TelemetryReporter from '@vscode/extension-telemetry';
import * as path from 'path';
import * as fs from 'fs';
import { OpenApiTreeNode, OpenApiTreeProvider } from "./openApiTreeProvider";
import * as path from 'path';
import * as vscode from "vscode";
import { CodeLensProvider } from "./codelensProvider";
import { KIOTA_WORKSPACE_FILE, dependenciesInfo, extensionId, statusBarCommandId, treeViewFocusCommand, treeViewId } from "./constants";
import { DependenciesViewProvider } from "./dependenciesViewProvider";
import { GenerationType, KiotaGenerationLanguage, KiotaPluginType } from "./enums";
import { ExtensionSettings, getExtensionSettings } from "./extensionSettings";
import { generateClient } from "./generateClient";
import { generatePlugin } from "./generatePlugin";
import { getKiotaVersion } from "./getKiotaVersion";
import { getLanguageInformation, getLanguageInformationForDescription } from "./getLanguageInformation";
import {
ClientOrPluginProperties,
ConsumerOperation,
generationLanguageToString,
getLogEntriesForLevel,
KiotaGenerationLanguage,
KiotaLogEntry,
KiotaPluginType,
LogLevel,
parseGenerationLanguage,
parsePluginType,
generationLanguageToString,
getLogEntriesForLevel,
} from "./kiotaInterop";
import { GenerateState, GenerationType, filterSteps, generateSteps, parseGenerationType, searchSteps } from "./steps";
import { getKiotaVersion } from "./getKiotaVersion";
import { checkForLockFileAndPrompt } from "./migrateFromLockFile";
import { OpenApiTreeNode, OpenApiTreeProvider } from "./openApiTreeProvider";
import { searchDescription } from "./searchDescription";
import { generateClient } from "./generateClient";
import { getLanguageInformation, getLanguageInformationForDescription } from "./getLanguageInformation";
import { DependenciesViewProvider } from "./dependenciesViewProvider";
import { GenerateState, filterSteps, generateSteps, searchSteps, transformToGenerationconfig } from "./steps";
import { updateClients } from "./updateClients";
import { ExtensionSettings, getExtensionSettings } from "./extensionSettings";
import {
getSanitizedString, getWorkspaceJsonDirectory, getWorkspaceJsonPath,
handleMigration, isClientType, isPluginType, parseGenerationLanguage,
parseGenerationType, parsePluginType, updateTreeViewIcons, validateDeepLinkQueryParams
} from "./util";
import { loadTreeView } from "./workspaceTreeProvider";
import { generatePlugin } from "./generatePlugin";
import { CodeLensProvider } from "./codelensProvider";
import { KIOTA_WORKSPACE_FILE, dependenciesInfo, extensionId, statusBarCommandId, treeViewFocusCommand, treeViewId } from "./constants";
import { getWorkspaceJsonDirectory, getWorkspaceJsonPath, handleMigration, isClientType, isPluginType, updateTreeViewIcons } from "./util";
import { checkForLockFileAndPrompt } from "./migrateFromLockFile";

let kiotaStatusBarItem: vscode.StatusBarItem;
let kiotaOutputChannel: vscode.LogOutputChannel;
Expand Down Expand Up @@ -60,18 +61,22 @@ export async function activate(
await loadTreeView(context);
await checkForLockFileAndPrompt(context);
let codeLensProvider = new CodeLensProvider();
let deepLinkParams: Record<string, string|undefined> = {};
context.subscriptions.push(
vscode.window.registerUriHandler({
handleUri: async (uri: vscode.Uri) => {
if (uri.path === "/") {
return;
}
console.log(uri);
const queryParameters = getQueryParameters(uri);
console.log(queryParameters);
if (uri.path.toLowerCase() === "/opendescription") {
reporter.sendTelemetryEvent("DeepLink.OpenDescription");
const descriptionUrl = queryParameters["descriptionurl"];
if (descriptionUrl) {
await openTreeViewWithProgress(() => openApiTreeProvider.setDescriptionUrl(descriptionUrl));
deepLinkParams = validateDeepLinkQueryParams(queryParameters);
reporter.sendTelemetryEvent("DeepLink.OpenDescription", deepLinkParams);

if (deepLinkParams.descriptionUrl) {
await openTreeViewWithProgress(() => openApiTreeProvider.setDescriptionUrl(deepLinkParams.descriptionUrl!));
return;
}
}
Expand Down Expand Up @@ -135,15 +140,24 @@ export async function activate(
}

let languagesInformation = await getLanguageInformation(context);
const pluginName = getPluginName();
config = await generateSteps(
{
let availableStateInfo: any = {};
if(deepLinkParams){
if (!deepLinkParams["name"] && openApiTreeProvider.apiTitle ){
deepLinkParams["name"] = getSanitizedString(openApiTreeProvider.apiTitle);
}
availableStateInfo = transformToGenerationconfig(deepLinkParams);
}else{
const pluginName = getPluginName();
availableStateInfo = {
clientClassName: openApiTreeProvider.clientClassName,
clientNamespaceName: openApiTreeProvider.clientNamespaceName,
language: openApiTreeProvider.language,
outputPath: openApiTreeProvider.outputPath,
pluginName
},
};
}
config = await generateSteps(
availableStateInfo,
languagesInformation
);
const generationType = parseGenerationType(config.generationType);
Expand Down
4 changes: 2 additions & 2 deletions vscode/microsoft-kiota/src/extensionSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import { KiotaGenerationLanguage } from "./kiotaInterop";
import { KiotaGenerationLanguage } from "./enums";

export function getExtensionSettings(extensionId: string) : ExtensionSettings {
return {
Expand Down Expand Up @@ -50,4 +50,4 @@ export interface ExtensionSettings {
interface LanguageSerializationConfiguration {
serializers: string[];
deserializers: string[];
}
}
7 changes: 4 additions & 3 deletions vscode/microsoft-kiota/src/generateClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaGenerationLanguage, KiotaLogEntry } from "./kiotaInterop";
import * as rpc from "vscode-jsonrpc/node";
import * as vscode from "vscode";
import * as rpc from "vscode-jsonrpc/node";
import { KiotaGenerationLanguage } from "./enums";
import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaLogEntry } from "./kiotaInterop";
import { getWorkspaceJsonDirectory } from "./util";

export function generateClient(context: vscode.ExtensionContext,
Expand Down Expand Up @@ -50,4 +51,4 @@ export function generateClient(context: vscode.ExtensionContext,
} as GenerationConfiguration,
);
}, workingDirectory);
};
};
7 changes: 4 additions & 3 deletions vscode/microsoft-kiota/src/generatePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaGenerationLanguage, KiotaLogEntry, KiotaPluginType } from "./kiotaInterop";
import * as rpc from "vscode-jsonrpc/node";
import * as vscode from "vscode";
import * as rpc from "vscode-jsonrpc/node";
import { KiotaPluginType } from "./enums";
import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaLogEntry } from "./kiotaInterop";
import { getWorkspaceJsonDirectory } from "./util";

export function generatePlugin(context: vscode.ExtensionContext,
Expand Down Expand Up @@ -35,4 +36,4 @@ export function generatePlugin(context: vscode.ExtensionContext,
} as GenerationConfiguration,
);
}, workingDirectory);
};
};
73 changes: 4 additions & 69 deletions vscode/microsoft-kiota/src/kiotaInterop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";
import * as cp from 'child_process';
import * as vscode from "vscode";
import * as rpc from 'vscode-jsonrpc/node';
import { KiotaGenerationLanguage, KiotaPluginType } from './enums';
import { ensureKiotaIsPresent, getKiotaPath } from './kiotaInstall';
import { getWorkspaceJsonDirectory } from "./util";

Expand Down Expand Up @@ -87,35 +88,6 @@ export interface KiotaSearchResultItem {
VersionLabels?: string[];
}

export enum KiotaGenerationLanguage {
// eslint-disable-next-line @typescript-eslint/naming-convention
CSharp = 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
Java = 1,
// eslint-disable-next-line @typescript-eslint/naming-convention
TypeScript = 2,
// eslint-disable-next-line @typescript-eslint/naming-convention
PHP = 3,
// eslint-disable-next-line @typescript-eslint/naming-convention
Python = 4,
// eslint-disable-next-line @typescript-eslint/naming-convention
Go = 5,
// eslint-disable-next-line @typescript-eslint/naming-convention
Swift = 6,
// eslint-disable-next-line @typescript-eslint/naming-convention
Ruby = 7,
// eslint-disable-next-line @typescript-eslint/naming-convention
CLI = 8,
}
export enum KiotaPluginType {
// eslint-disable-next-line @typescript-eslint/naming-convention
OpenAI = 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
ApiManifest = 1,
// eslint-disable-next-line @typescript-eslint/naming-convention
ApiPlugin = 2,
}

export enum ConsumerOperation {
// eslint-disable-next-line @typescript-eslint/naming-convention
Add,
Expand All @@ -126,20 +98,6 @@ export enum ConsumerOperation {
// eslint-disable-next-line @typescript-eslint/naming-convention
Generate
}
export function parsePluginType(values: string[]): KiotaPluginType[] {
return values.map(value => {
switch (value.toLowerCase()) {
case "openai":
return KiotaPluginType.OpenAI;
case "apimanifest":
return KiotaPluginType.ApiManifest;
case "apiplugin":
return KiotaPluginType.ApiPlugin;
default:
throw new Error(`unknown plugin type: ${value}`);
}
});
}

export function generationLanguageToString(language: KiotaGenerationLanguage): string {
switch (language) {
Expand All @@ -165,30 +123,7 @@ export function generationLanguageToString(language: KiotaGenerationLanguage): s
throw new Error("unknown language");
}
}
export function parseGenerationLanguage(value: string): KiotaGenerationLanguage {
switch (value) {
case "CSharp":
return KiotaGenerationLanguage.CSharp;
case "Java":
return KiotaGenerationLanguage.Java;
case "TypeScript":
return KiotaGenerationLanguage.TypeScript;
case "PHP":
return KiotaGenerationLanguage.PHP;
case "Python":
return KiotaGenerationLanguage.Python;
case "Go":
return KiotaGenerationLanguage.Go;
case "Swift":
return KiotaGenerationLanguage.Swift;
case "Ruby":
return KiotaGenerationLanguage.Ruby;
case "CLI":
return KiotaGenerationLanguage.CLI;
default:
throw new Error("unknown language");
}
}

export const allGenerationLanguages = [
KiotaGenerationLanguage.CSharp,
KiotaGenerationLanguage.Go,
Expand Down Expand Up @@ -306,4 +241,4 @@ export interface PluginObjectProperties extends WorkspaceObjectProperties {
types: string[];
}

export type ClientOrPluginProperties = ClientObjectProperties | PluginObjectProperties;
export type ClientOrPluginProperties = ClientObjectProperties | PluginObjectProperties;
Loading

0 comments on commit d905b04

Please sign in to comment.