Skip to content

Commit

Permalink
sending localized string to copilot webview
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjoshi committed Oct 6, 2023
1 parent 2d78054 commit b8774a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/common/copilot/PowerPagesCopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { INTELLIGENCE_SCOPE_DEFAULT, PROVIDER_ID } from "../../web/client/common
import { getIntelligenceEndpoint } from "../ArtemisService";
import TelemetryReporter from "@vscode/extension-telemetry";
import { getEntityColumns, getEntityName } from "./dataverseMetadata";
import { COPILOT_STRINGS } from "./assets/copilotStrings";

let intelligenceApiToken: string;
let userID: string; // Populated from PAC or intelligence API
Expand Down Expand Up @@ -177,6 +178,8 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider {
webviewView.webview.onDidReceiveMessage(async (data) => {
switch (data.type) {
case "webViewLoaded": {
// Send the localized strings to the copilot webview
this.sendMessageToWebview({type: 'copilotStrings', value: COPILOT_STRINGS})
if (this.aibEndpoint === COPILOT_UNAVAILABLE) {
this.sendMessageToWebview({ type: 'Unavailable' });
return;
Expand Down
11 changes: 11 additions & 0 deletions src/common/copilot/assets/copilotStrings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/


import vscode from "vscode";

export const COPILOT_STRINGS = {
EXPLAIN_CODE_PROMPT: vscode.l10n.t('Explain the following code:'),
}
7 changes: 6 additions & 1 deletion src/common/copilot/assets/scripts/copilot.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
let isLoggedIn = false;
let apiResponseInProgress = false;
let selectedCode = "";
let copilotStrings = {};


const inputHistory = [];
Expand Down Expand Up @@ -404,6 +405,10 @@
const message = event.data; // The JSON data our extension sent

switch (message.type) {
case "copilotStrings": {
copilotStrings = message.value; //Localized string values object
break;
}
case "apiResponse": {
apiResponseHandler.updateResponse(message.value);
apiResponseInProgress = false;
Expand Down Expand Up @@ -472,7 +477,7 @@
}
case "explainCode": {
selectedCode = message.value.selectedCode;
const explainPrompt = 'Explain the following code:';
const explainPrompt = copilotStrings.EXPLAIN_CODE_PROMPT;
processUserInput(explainPrompt);
}

Expand Down

0 comments on commit b8774a6

Please sign in to comment.