Skip to content

Commit

Permalink
Chore: get language information (#6109)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Feb 7, 2025
1 parent 707b07e commit 6f9f9f5
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { showUpgradeWarningMessage } from "../../utilities/messaging";
import { Command } from "../Command";
import { generateClient } from "./generateClient";
import { generatePlugin } from "./generatePlugin";
import { displayGenerationResults } from "./generation-util";
import { getLanguageInformation, getLanguageInformationForDescription } from "./getLanguageInformation";
import { displayGenerationResults, getLanguageInformation } from "./generation-util";
import { getLanguageInformationForDescription } from "../../kiotaInterop/languageInformation";
import { confirmDeletionOnCleanOutput } from "../../utilities/generation";

export class GenerateClientCommand extends Command {
Expand Down Expand Up @@ -50,7 +50,7 @@ export class GenerateClientCommand extends Command {
return;
}

let languagesInformation = await getLanguageInformation(this._context);
let languagesInformation = await getLanguageInformation();
let availableStateInfo: Partial<GenerateState>;
if (isDeeplinkEnabled(deepLinkParams)) {
if (!deepLinkParams.name && this._openApiTreeProvider.apiTitle) {
Expand Down Expand Up @@ -177,7 +177,7 @@ export class GenerateClientCommand extends Command {
} else {
await displayGenerationResults(this._openApiTreeProvider, config);
}
await vscode.commands.executeCommand('kiota.workspace.refresh');
await vscode.commands.executeCommand('kiota.workspace.refresh');
}

clearDeepLinkParams(); // Clear the state after successful generation
Expand Down Expand Up @@ -329,10 +329,10 @@ export class GenerateClientCommand extends Command {
});

let languagesInformation = await getLanguageInformationForDescription(
this._context,
this._openApiTreeProvider.descriptionUrl,
settings.clearCache
);
{
descriptionUrl: this._openApiTreeProvider.descriptionUrl,
clearCache: settings.clearCache
});
if (languagesInformation) {
this._dependenciesViewProvider.update(languagesInformation, language);
await vscode.commands.executeCommand(treeViewFocusCommand);
Expand Down
19 changes: 17 additions & 2 deletions vscode/microsoft-kiota/src/commands/generate/generation-util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as vscode from "vscode";
import * as fs from 'fs';
import * as vscode from "vscode";

import { KIOTA_WORKSPACE_FILE, treeViewId } from "../../constants";
import { LanguagesInformation } from "../../kiotaInterop";
import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider";
import { getWorkspaceJsonPath, updateTreeViewIcons } from "../../util";
import { getLanguageInformationInternal } from "../../kiotaInterop/languageInformation";

let _languageInformation: LanguagesInformation | undefined; // doesn't change over the lifecycle of the extension

export async function displayGenerationResults(openApiTreeProvider: OpenApiTreeProvider, config: any) {
const clientNameOrPluginName = config.clientClassName || config.pluginName;
Expand All @@ -19,4 +23,15 @@ export async function displayGenerationResults(openApiTreeProvider: OpenApiTreeP
openApiTreeProvider.resetInitialState();
await updateTreeViewIcons(treeViewId, false, true);
await vscode.commands.executeCommand('kiota.workspace.refresh');
}
}

export async function getLanguageInformation(): Promise<LanguagesInformation | undefined> {
if (_languageInformation) {
return _languageInformation;
}
const result = await getLanguageInformationInternal();
if (result) {
_languageInformation = result;
}
return result;
};

This file was deleted.

33 changes: 33 additions & 0 deletions vscode/microsoft-kiota/src/kiotaInterop/languageInformation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as rpc from "vscode-jsonrpc/node";

import { LanguagesInformation } from ".";
import connectToKiota from "./connect";

interface LanguageInformationConfiguration {
descriptionUrl: string; clearCache: boolean;
}

export function getLanguageInformationInternal(): Promise<LanguagesInformation | undefined> {
return connectToKiota<LanguagesInformation>(async (connection) => {
const request = new rpc.RequestType0<LanguagesInformation, void>(
"Info"
);
return await connection.sendRequest(
request,
);
});
};

export function getLanguageInformationForDescription({ descriptionUrl, clearCache }: LanguageInformationConfiguration):
Promise<LanguagesInformation | undefined> {
return connectToKiota<LanguagesInformation>(async (connection) => {
const request = new rpc.RequestType2<string, boolean, LanguagesInformation, void>(
"InfoForDescription"
);
return await connection.sendRequest(
request,
descriptionUrl,
clearCache
);
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as sinon from 'sinon';


import { setupKiotaStubs } from './stubs.util';
import { getLanguageInformationForDescription, getLanguageInformationInternal } from '../languageInformation';

const sampleLanguageInfo = {
CSharp: {

Check warning on line 8 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `CSharp` must match one of the following formats: camelCase
MaturityLevel: 2,

Check warning on line 9 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `MaturityLevel` must match one of the following formats: camelCase
SupportExperience: 0,

Check warning on line 10 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `SupportExperience` must match one of the following formats: camelCase
Dependencies: [

Check warning on line 11 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `Dependencies` must match one of the following formats: camelCase
{
Name: "Microsoft.Kiota.Abstractions",

Check warning on line 13 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `Name` must match one of the following formats: camelCase
Version: "1.16.4",

Check warning on line 14 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `Version` must match one of the following formats: camelCase
DependencyType: 0,

Check warning on line 15 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `DependencyType` must match one of the following formats: camelCase
}
],
DependencyInstallCommand: "dotnet add package {0} --version {1}",

Check warning on line 18 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `DependencyInstallCommand` must match one of the following formats: camelCase
ClientClassName: "",

Check warning on line 19 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `ClientClassName` must match one of the following formats: camelCase
ClientNamespaceName: "",

Check warning on line 20 in vscode/microsoft-kiota/src/kiotaInterop/tests/languageInformation.spec.ts

View workflow job for this annotation

GitHub Actions / build_extension

Object Literal Property name `ClientNamespaceName` must match one of the following formats: camelCase
StructuredMimeTypes: [
],
}
};

describe("Language Information", () => {
let connectionStub: sinon.SinonStub;

beforeEach(() => {
const stubs = setupKiotaStubs();
connectionStub = stubs.connectionStub;
});

afterEach(() => {
sinon.restore();
});


test('should return language information for a description when successful', async () => {
const mockResults = sampleLanguageInfo;
connectionStub.resolves(mockResults);
const results = await getLanguageInformationForDescription({ clearCache: false, descriptionUrl: 'test.com' });
expect(results).toBeDefined();
});

test('should return internal language information when successful', async () => {
const mockResults = sampleLanguageInfo;

connectionStub.resolves(mockResults);
const results = await getLanguageInformationInternal();
expect(results).toBeDefined();
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from "path";
import * as sinon from "sinon";
import * as vscode from 'vscode';
import * as generateModule from "../../../commands/generate/generateClientCommand";
import * as languageInfoModule from "../../../commands/generate/getLanguageInformation";
import * as languageInfoModule from "../../../commands/generate/generation-util";
import * as deepLinkParamsHandler from "../../../handlers/deepLinkParamsHandler";
import { KiotaLogEntry } from "../../../kiotaInterop";
import * as generateStepsModule from "../../../modules/steps/generateSteps";
Expand Down Expand Up @@ -48,6 +48,7 @@ let context: vscode.ExtensionContext = {
} as vscode.Extension<any>
};


let extensionSettings = {
includeAdditionalData:false,
backingStore: false,
Expand Down Expand Up @@ -121,7 +122,7 @@ suite('GenerateClientCommand Test Suite', () => {
await generateClientCommand.execute();
assert.strictEqual((treeProvider.getSelectedPaths()).length, 1);
vscodeWindowSpy.verify();
sinon.assert.calledOnceWithMatch(getlanguageInfoFn, context);
sinon.assert.calledOnceWithMatch(getlanguageInfoFn);
let stateInfo: Partial<generateStepsModule.GenerateState> = {
clientClassName: treeProvider.clientClassName,
clientNamespaceName: treeProvider.clientNamespaceName,
Expand Down Expand Up @@ -175,7 +176,7 @@ suite('GenerateClientCommand Test Suite', () => {
assert.strictEqual((treeProvider.getSelectedPaths()).length, 1);
assert.strictEqual(!treeProvider.descriptionUrl, false);
vscodeWindowSpy.verify();
sinon.assert.calledOnceWithMatch(getlanguageInfoFn, context);
sinon.assert.calledOnceWithMatch(getlanguageInfoFn);
let stateInfo = await transformToGenerationConfig(pluginParams);
sinon.assert.calledOnceWithMatch(generateStepsFn, stateInfo, undefined , pluginParams);
sinon.assert.calledOnce(showUpgradeWarningMessageStub);
Expand Down Expand Up @@ -232,7 +233,7 @@ suite('GenerateClientCommand Test Suite', () => {

// assertions
vscodeWindowSpy.verify();
sinon.assert.calledOnceWithMatch(getlanguageInfoFn, context);
sinon.assert.calledOnceWithMatch(getlanguageInfoFn);
var updatedDeepLinkParams: Partial<IntegrationParams> = JSON.parse(JSON.stringify(pluginParams));
updatedDeepLinkParams["name"] = sanitizedApiTitle;
sinon.assert.calledOnce(generateStepsFn);
Expand Down

0 comments on commit 6f9f9f5

Please sign in to comment.