Skip to content

Commit

Permalink
Passing Active Editor Info (#1015)
Browse files Browse the repository at this point in the history
* Users/nityagi/update feature branch (#933)

* Moving auth create flow to utils (#926)

Co-authored-by: amitjoshi <[email protected]>

* Making auth provider a common module flow (#928)

* refactor: Update QuickPickProvider to handle tab input changes (#930)

The code changes in the QuickPickProvider class handle tab input changes by checking if the active tab is an instance of vscode.TabInputCustom or vscode.TabInputText. If it is, the QuickPickProvider updates the quick pick items based on the file path of the tab input.

Note: This commit message follows the convention used in recent repository commits.

* Updates to Artemis service & telemetry endpoints for gov clouds (#906)

* Updates to artemis for gov clouds

* change

* changes

---------

Co-authored-by: Shivika Gupta <[email protected]>

---------

Co-authored-by: amitjoshi438 <[email protected]>
Co-authored-by: amitjoshi <[email protected]>
Co-authored-by: Ritik Ramuka <[email protected]>
Co-authored-by: gshivi <[email protected]>
Co-authored-by: Shivika Gupta <[email protected]>

* GitHub copilot chat -  @powerpages contribution (#927)

* chore: Update package.json with extension dependencies and enabled API proposals for chat participants

* feat: Add PowerPagesChatParticipant for chat functionality

* feat: Add logic to handle chat requests in PowerPagesChatParticipant

* feat: Removed logs

* TODO

* formatting change

* Remove unused extension dependency

* feat: Add handler for chat requests in PowerPagesChatParticipant

---------

Co-authored-by: amitjoshi <[email protected]>
Co-authored-by: tyaginidhi <[email protected]>
Co-authored-by: Nidhi Tyagi 🌟🐇🌴❄️ <[email protected]>

* [@powerpages] GitHub copilot auth handling for AIB and PAC (#947)

* chore: Update package.json with extension dependencies and enabled API proposals for chat participants

* feat: Add PowerPagesChatParticipant for chat functionality

* feat: Add logic to handle chat requests in PowerPagesChatParticipant

* feat: Removed logs

* TODO

* feat: Add logic to handle chat requests in PowerPagesChatParticipant(correct response format)

* chore: Remove unused code and update PowerPagesChatParticipant initialization

* chore: Update PowerPagesChatParticipant initialization and pac integration

* feat: Initialize organization details in PowerPagesChatParticipant

* chore: Remove unnecessary code and update OrgChangeNotifier initialization

* Fix lint warnings

* feat: Refactor PowerPagesChatParticipant class

The code changes refactor the PowerPagesChatParticipant class in the `PowerPagesChatParticipant.ts` file. The changes include:
- Fixing a typo in the `instance` property declaration
- Updating the constructor parameters to have consistent spacing
- Adding a comment to handle chat requests
- Removing a console.log statement
- Updating the `intializeOrgDetails` method to have consistent spacing
- Updating the `intializeOrgDetails` method to use destructuring assignment
- Updating the `intializeOrgDetails` method to update the `orgDetails` in the global state
- Removing unused code

Co-authored-by: amitjoshi <[email protected]>

* Added response for error scenarios

* Added & removed comments

* refactor: Update PowerPagesCopilot name in package.json

The code changes in the package.json file update the "name" property for the "powerpages" module to "Power Pages Copilot". This change reflects the updated name for the module.

Co-authored-by: amitjoshi <[email protected]>

* Code refactoring for utils and constants

* Enhanced pac auth handling

* refactor: Update PowerPagesChatParticipantConstants

The code changes in the `PowerPagesChatParticipantConstants.ts` file refactor the constants used in the PowerPages chat participant. The changes include:
- Cleaning up the code formatting

Co-authored-by: amitjoshi <[email protected]>

---------

Co-authored-by: amitjoshi <[email protected]>
Co-authored-by: tyaginidhi <[email protected]>
Co-authored-by: Nidhi Tyagi 🌟🐇🌴❄️ <[email protected]>

* Resolve merge conflicts

* [@powerpages]GitHub copilot request handling (#957)

* chore: Update package.json with extension dependencies and enabled API proposals for chat participants

* feat: Add PowerPagesChatParticipant for chat functionality

* feat: Add logic to handle chat requests in PowerPagesChatParticipant

* feat: Removed logs

* TODO

* feat: Add logic to handle chat requests in PowerPagesChatParticipant(correct response format)

* feat: Add getActiveEditorContent function for retrieving active editor data

The code changes add a new function called getActiveEditorContent to the Utils module. This function retrieves the content and parameters of the active editor in Visual Studio Code. It is used in the PowerPagesCopilot module to get the active file content and its associated parameters.

Co-authored-by: amitjoshi <[email protected]>

* chore: Remove unused code and update PowerPagesChatParticipant initialization

* chore: Update PowerPagesChatParticipant initialization and pac integration

* feat: Initialize organization details in PowerPagesChatParticipant

* @powerpages aib endpoint handling

* feat: Add getActiveEditorContent function to retrieve active editor data

The code changes introduce a new function called getActiveEditorContent in the Utils module. This function allows retrieving the content and parameters of the active editor in Visual Studio Code. It is utilized in the PowerPagesCopilot module to obtain the active file content and its associated parameters.

Co-authored-by: amitjoshi <[email protected]>

* Multiline response handling

* Todo comment for auth create exp

* feat: Handle Copilot Unavailable scenario with response to user

* Update in package.json

* chore: Remove extension dependency

* Full name for @powerpages

* refactor: Refactor PowerPagesChatParticipant class
- Removing unused code

* chat api insider version

* refactor: Refactor PowerPagesChatParticipant import paths

* Update package.json version to 1.0.1-dev and other refactoring

* refactor: Remove unused code in PowerPagesChatParticipant class

* refactor: Moved Dataverse details fetch to utils

* refactor: Added entity check to utils

* refactor: Update localization strings and package version

* chore: Remove @types/vscode dependency and update package-lock.json and package.json

* chore: Update @types/vscode dependency to version 1.89.0

* chore: Remove @types/vscode dependency and update package-lock.json and package.json

---------

Co-authored-by: amitjoshi <[email protected]>
Co-authored-by: tyaginidhi <[email protected]>

* [PowerPages] Copilot Availability Check for @powerpages (#962)

* feat: Add environmentID field to OrgDetails interface

The code changes add an optional `environmentID` field to the `OrgDetails` interface in the `PowerPagesChatParticipantTypes.ts` file. This field represents the ID of the environment associated with the organization. It is used in the `getEndpoint` function in the `PowerPagesChatParticipantUtils.ts` file to retrieve the intelligence endpoint and geo name for the specified organization and environment.

Co-authored-by: amitjoshi <[email protected]>
Co-authored-by: tyaginidhi <[email protected]>

* feat: Update PowerPagesChatParticipantUtils to return componentInfo and entityName

The code changes in PowerPagesChatParticipantUtils modify the getComponentInfo function to return an object with two properties: componentInfo and entityName. This change allows for better handling of component information and entity details for the active file. The updated function is used in PowerPagesChatParticipant to retrieve the necessary data for sending API requests.

Co-authored-by: amitjoshi <[email protected]>

* feat: Modify getComponentInfo to return componentInfo and entityName

The code changes in PowerPagesChatParticipantUtils modify the getComponentInfo function to return an object with two properties: componentInfo and entityName. This change improves the handling of component information and entity details for the active file. The updated function is used in PowerPagesChatParticipant to retrieve the necessary data for sending API requests.

---------

Co-authored-by: amitjoshi <[email protected]>

* feat: Add telemetry event names for GitHub Power Pages agent (#969)

* feat: Add telemetry event names for GitHub Power Pages agent

* chore: Update telemetry event names for GitHub Power Pages agent

---------

Co-authored-by: amitjoshi <[email protected]>
Co-authored-by: tyaginidhi <[email protected]>

* feat: Add selected code support to getActiveEditorContent function

* feat: Add support for retrieving active editor content and parameters

The code changes in the `getActiveEditorContent` function of the `Utils.ts` file add support for retrieving the content and parameters of the active editor in Visual Studio Code. This function now handles selected code, visible code, and full file content scenarios. It also updates the `activeFileData` object with the appropriate content and line range information. This change improves the functionality of the `getActiveEditorContent` function and enhances the overall user experience.

Co-authored-by: amitjoshi <[email protected]>

* feat: Improve getActiveEditorContent function to handle selected code, visible code, and full file content scenario

Co-authored-by: amitjoshi <[email protected]>

* feat: Commented visible code part functionality

* passing activeFileContent for prodev copilot

* Removed redundant code

* pr comments

---------

Co-authored-by: tyaginidhi <[email protected]>
Co-authored-by: amitjoshi <[email protected]>
Co-authored-by: Ritik Ramuka <[email protected]>
Co-authored-by: gshivi <[email protected]>
Co-authored-by: Shivika Gupta <[email protected]>
Co-authored-by: Nidhi Tyagi 🌟🐇🌴❄️ <[email protected]>
  • Loading branch information
7 people authored Aug 14, 2024
1 parent a66c2f2 commit ffe2bca
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 36 deletions.
2 changes: 1 addition & 1 deletion l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@
"The {0} represents profile's Azure Cloud Instances"
]
}
}
}
4 changes: 4 additions & 0 deletions loc/translations-export/vscode-powerplatform.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++7f6276dc63b573d177b7d6e17f787b108e3c8c7d449324ac13a6d06b1be59d8e">
<source xml:lang="en">Please enter a name for the webpage.</source>
</trans-unit>
<trans-unit id="++CODE++f39f65c4f7d519a37b66a00d02a6def9e3721080363dae761b907793330333cd">
<source xml:lang="en">Please provide a prompt to get started.
You can get help with writing code for Power Pages sites in HTML, CSS, and JS languages.</source>
</trans-unit>
<trans-unit id="++CODE++1bac158cc07a75506df3774db0ad7c188c19ccad4943c4cf03da8b6700ef9ce4">
<source xml:lang="en">Power Pages Copilot is now connected to the environment: {0} : {1}</source>
<note>{0} represents the environment name</note>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import * as vscode from 'vscode';
import { createChatParticipant } from '../ChatParticipantUtils';
import { IComponentInfo, IPowerPagesChatResult } from './PowerPagesChatParticipantTypes';
import { ITelemetry } from "../../OneDSLoggerTelemetry/telemetry/ITelemetry";
import TelemetryReporter from '@vscode/extension-telemetry';
import { sendApiRequest } from '../../copilot/IntelligenceApiService';
import { PacWrapper } from '../../../client/pac/PacWrapper';
import { intelligenceAPIAuthentication } from '../../services/AuthenticationProvider';
import { ActiveOrgOutput } from '../../../client/pac/PacTypes';
import { AUTHENTICATION_FAILED_MSG, COPILOT_NOT_AVAILABLE_MSG, DISCLAIMER_MESSAGE, NO_PROMPT_MESSAGE, PAC_AUTH_NOT_FOUND, POWERPAGES_CHAT_PARTICIPANT_ID, RESPONSE_AWAITED_MSG, SKIP_CODES, STATER_PROMPTS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO, WELCOME_MESSAGE, WELCOME_PROMPT } from './PowerPagesChatParticipantConstants';
import { ORG_DETAILS_KEY, handleOrgChangeSuccess, initializeOrgDetails } from '../../utilities/OrgHandlerUtils';
import { getComponentInfo, getEndpoint, provideChatParticipantFollowups } from './PowerPagesChatParticipantUtils';
import { createAndReferenceLocation, getComponentInfo, getEndpoint, provideChatParticipantFollowups } from './PowerPagesChatParticipantUtils';
import { checkCopilotAvailability, getActiveEditorContent } from '../../utilities/Utils';
import { IIntelligenceAPIEndpointInformation } from '../../services/Interfaces';
import { v4 as uuidv4 } from 'uuid';
import { ITelemetry } from '../../OneDSLoggerTelemetry/telemetry/ITelemetry';
import { orgChangeErrorEvent, orgChangeEvent } from '../../../client/OrgChangeNotifier';

export class PowerPagesChatParticipant {
Expand Down Expand Up @@ -131,41 +131,47 @@ export class PowerPagesChatParticipant {

if (userPrompt === WELCOME_PROMPT) {
stream.markdown(WELCOME_MESSAGE);
return{
return {
metadata: {
command: STATER_PROMPTS
}
}
}

if (!userPrompt) {

stream.markdown(NO_PROMPT_MESSAGE);

return {
metadata: {
command: STATER_PROMPTS
}
};
}

const { activeFileContent, activeFileUri, startLine, endLine, activeFileParams } = getActiveEditorContent();

const location = activeFileUri ? createAndReferenceLocation(activeFileUri, startLine, endLine) : undefined;

if (location) {
stream.reference(location);
}

if (request.command) {
//TODO: Handle command scenarios

} else {
const { activeFileParams } = getActiveEditorContent();

const { componentInfo, entityName }: IComponentInfo = await getComponentInfo(this.telemetry, this.orgUrl, activeFileParams, this.powerPagesAgentSessionId);

const llmResponse = await sendApiRequest([{ displayText: userPrompt, code: '' }], activeFileParams, this.orgID, intelligenceApiToken, this.powerPagesAgentSessionId, entityName, componentInfo, this.telemetry, intelligenceAPIEndpointInfo.intelligenceEndpoint, intelligenceAPIEndpointInfo.geoName, intelligenceAPIEndpointInfo.crossGeoDataMovementEnabledPPACFlag);
const llmResponse = await sendApiRequest([{ displayText: userPrompt, code: activeFileContent }], activeFileParams, this.orgID, intelligenceApiToken, this.powerPagesAgentSessionId, entityName, componentInfo, this.telemetry, intelligenceAPIEndpointInfo.intelligenceEndpoint, intelligenceAPIEndpointInfo.geoName, intelligenceAPIEndpointInfo.crossGeoDataMovementEnabledPPACFlag);

const scenario = llmResponse.length > 1 ? llmResponse[llmResponse.length - 1] : llmResponse[0].displayText;

this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO, { scenario: scenario, sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID })

llmResponse.forEach((response: { displayText: string | vscode.MarkdownString; code: string; }) => {

if (response.displayText) {
stream.markdown(response.displayText);
stream.markdown('\n');
}
if (response.code && !SKIP_CODES.includes(response.code)) {
stream.markdown('\n```javascript\n' + response.code + '\n```');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export function isEntityInSupportedList(entity: string): boolean {
return SUPPORTED_ENTITIES.includes(entity);
}

export function createAndReferenceLocation(activeFileUri: vscode.Uri, startLine: number, endLine: number): vscode.Location {

const positionStart = new vscode.Position(startLine, 0),
positionEnd = new vscode.Position(endLine, 0),
activeFileRange = new vscode.Range(positionStart, positionEnd),
location = new vscode.Location(activeFileUri, activeFileRange);

return location;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function provideChatParticipantFollowups(result: IPowerPagesChatResult, _context: vscode.ChatContext, _token: vscode.CancellationToken) {
if (result.metadata.command === STATER_PROMPTS) {
Expand All @@ -68,3 +77,4 @@ export function provideChatParticipantFollowups(result: IPowerPagesChatResult, _
];
}
}

1 change: 0 additions & 1 deletion src/common/copilot/IntelligenceApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export async function sendApiRequest(userPrompt: UserPrompt[], activeFileParams:
}
}


const requestInit: RequestInit = {
method: "POST",
headers: {
Expand Down
11 changes: 6 additions & 5 deletions src/common/copilot/PowerPagesCopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { v4 as uuidv4 } from 'uuid'
import { PacWrapper } from "../../client/pac/PacWrapper";
import { ITelemetry } from "../OneDSLoggerTelemetry/telemetry/ITelemetry";
import { ADX_ENTITYFORM, ADX_ENTITYLIST, AUTH_CREATE_FAILED, AUTH_CREATE_MESSAGE, AuthProfileNotFound, COPILOT_IN_POWERPAGES, COPILOT_UNAVAILABLE, CopilotStylePathSegments, EXPLAIN_CODE, SELECTED_CODE_INFO, SELECTED_CODE_INFO_ENABLED, THUMBS_DOWN, THUMBS_UP, UserPrompt, WebViewMessage, sendIconSvg } from "./constants";
import { IActiveFileParams, IOrgInfo } from './model';
import { IOrgInfo } from './model';
import { checkCopilotAvailability, escapeDollarSign, getActiveEditorContent, getNonce, getSelectedCode, getSelectedCodeLineRange, getUserName, openWalkthrough, showConnectedOrgMessage, showInputBoxAndGetOrgUrl, showProgressWithNotification } from "../utilities/Utils";
import { CESUserFeedback } from "./user-feedback/CESSurvey";
import { ActiveOrgOutput } from "../../client/pac/PacTypes";
Expand Down Expand Up @@ -236,8 +236,7 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider {
sendTelemetryEvent(this.telemetry, { eventName: CopilotUserPromptedEvent, copilotSessionId: sessionID, aibEndpoint: this.aibEndpoint ?? '', orgId: orgID, isSuggestedPrompt: String(data.value.isSuggestedPrompt), crossGeoDataMovementEnabledPPACFlag: this.crossGeoDataMovementEnabledPPACFlag }); //TODO: Add active Editor info
orgID
? (async () => {
const { activeFileParams } = getActiveEditorContent();
await this.authenticateAndSendAPIRequest(data.value.userPrompt, activeFileParams, orgID, this.telemetry);
await this.authenticateAndSendAPIRequest(data.value.userPrompt, orgID, this.telemetry);
})()
: (() => {
this.sendMessageToWebview({ type: 'apiResponse', value: AuthProfileNotFound });
Expand Down Expand Up @@ -359,7 +358,7 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider {
}
}

private async authenticateAndSendAPIRequest(data: UserPrompt[], activeFileParams: IActiveFileParams, orgID: string, telemetry: ITelemetry) {
private async authenticateAndSendAPIRequest(data: UserPrompt[], orgID: string, telemetry: ITelemetry) {
return intelligenceAPIAuthentication(telemetry, sessionID, orgID)
.then(async ({ accessToken, user, userId }) => {
intelligenceApiToken = accessToken;
Expand All @@ -368,6 +367,8 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider {

this.sendMessageToWebview({ type: 'userName', value: userName });

const { activeFileContent, activeFileParams } = getActiveEditorContent();

let metadataInfo = { entityName: '', formName: '' };
let componentInfo: string[] = [];

Expand All @@ -385,7 +386,7 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider {
}

}
return sendApiRequest(data, activeFileParams, orgID, intelligenceApiToken, sessionID, metadataInfo.entityName, componentInfo, telemetry, this.aibEndpoint, this.geoName, this.crossGeoDataMovementEnabledPPACFlag);
return sendApiRequest([{ displayText: data[0].displayText, code: activeFileContent }], activeFileParams, orgID, intelligenceApiToken, sessionID, metadataInfo.entityName, componentInfo, telemetry, this.aibEndpoint, this.geoName, this.crossGeoDataMovementEnabledPPACFlag);
})
.then(apiResponse => {
this.sendMessageToWebview({ type: 'apiResponse', value: apiResponse });
Expand Down
7 changes: 6 additions & 1 deletion src/common/copilot/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import * as vscode from 'vscode';

export interface IFeedbackData {
TenantId: string;
Geo: string;
Expand All @@ -19,7 +21,10 @@ export interface IActiveFileParams {

export interface IActiveFileData {
activeFileParams: IActiveFileParams;
activeFileContent: string
activeFileContent: string;
activeFileUri: vscode.Uri | undefined;
startLine: number;
endLine: number;
}

export interface IOrgInfo {
Expand Down
73 changes: 53 additions & 20 deletions src/common/utilities/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from "vscode";
import { EXTENSION_ID, EXTENSION_NAME, SETTINGS_EXPERIMENTAL_STORE_NAME } from "../constants";
import { CUSTOM_TELEMETRY_FOR_POWER_PAGES_SETTING_NAME } from "../OneDSLoggerTelemetry/telemetryConstants";
import { COPILOT_UNAVAILABLE, DataverseEntityNameMap, EntityFieldMap, FieldTypeMap } from "../copilot/constants";
import { IActiveFileData, IActiveFileParams } from "../copilot/model";
import { IActiveFileData } from "../copilot/model";
import { ITelemetry } from "../OneDSLoggerTelemetry/telemetry/ITelemetry";
import { sendTelemetryEvent } from "../copilot/telemetry/copilotTelemetry";
import { getDisabledOrgList, getDisabledTenantList } from "../copilot/utils/copilotUtil";
Expand Down Expand Up @@ -141,28 +141,50 @@ export function getUserAgent(): string {

export function getActiveEditorContent(): IActiveFileData {
const activeEditor = vscode.window.activeTextEditor;
const activeFileData: IActiveFileData = {
activeFileContent: '',
activeFileParams: {
dataverseEntity: '',
entityField: '',
fieldType: ''
} as IActiveFileParams
};
if (activeEditor) {
const document = activeEditor.document;
const fileName = document.fileName;
const relativeFileName = vscode.workspace.asRelativePath(fileName);

const activeFileParams: string[] = getLastThreePartsOfFileName(relativeFileName);

activeFileData.activeFileContent = document.getText();
activeFileData.activeFileParams.dataverseEntity = DataverseEntityNameMap.get(activeFileParams[0]) || "";
activeFileData.activeFileParams.entityField = EntityFieldMap.get(activeFileParams[1]) || "";
activeFileData.activeFileParams.fieldType = FieldTypeMap.get(activeFileParams[2]) || "";
if (!activeEditor) {
return { activeFileContent: '', startLine: 0, endLine: 0, activeFileUri: undefined, activeFileParams: { dataverseEntity: '', entityField: '', fieldType: '' } };
}

return activeFileData;
const document = activeEditor.document;
const fileName = document.fileName;
const relativeFileName = vscode.workspace.asRelativePath(fileName);
const activeFileUri = document.uri;
const activeFileParams: string[] = getLastThreePartsOfFileName(relativeFileName);

let activeFileContent = document.getText();
let startLine = 0;
let endLine = document.lineCount;

const selectedCode = getSelectedCode(activeEditor);
const selectedCodeLineRange = getSelectedCodeLineRange(activeEditor);

if (selectedCode.length > 0) {
activeFileContent = selectedCode;
startLine = selectedCodeLineRange.start;
endLine = selectedCodeLineRange.end;
}
/**
* Uncomment the below code to pass the visible code to the copilot based on the token limit.
*/
//else if (document.getText().length > 100) { // Define the token limit for context passing
// const { code, startLine: visibleStart, endLine: visibleEnd } = getVisibleCode(activeEditor);
// activeFileContent = code;
// startLine = visibleStart;
// endLine = visibleEnd;
// }

return {
activeFileContent,
startLine,
endLine,
activeFileUri,
activeFileParams: {
dataverseEntity: DataverseEntityNameMap.get(activeFileParams[0]) || "",
entityField: EntityFieldMap.get(activeFileParams[1]) || "",
fieldType: FieldTypeMap.get(activeFileParams[2]) || ""
}
};
}

export function checkCopilotAvailability(
Expand All @@ -186,3 +208,14 @@ export function checkCopilotAvailability(
return true;
}
}

export function getVisibleCode(editor: vscode.TextEditor): { code: string; startLine: number; endLine: number; } {
const visibleRanges = editor.visibleRanges;
const visibleCode = visibleRanges.map(range => editor.document.getText(range)).join('\n');
const firstVisibleRange = visibleRanges[0];
return {
code: visibleCode,
startLine: firstVisibleRange.start.line,
endLine: firstVisibleRange.end.line
};
}

0 comments on commit ffe2bca

Please sign in to comment.