diff --git a/packages/core/src/amazonq/commons/controllers/contentController.ts b/packages/core/src/amazonq/commons/controllers/contentController.ts index edcb84f9fb0..821e2988f96 100644 --- a/packages/core/src/amazonq/commons/controllers/contentController.ts +++ b/packages/core/src/amazonq/commons/controllers/contentController.ts @@ -12,9 +12,10 @@ import { disposeOnEditorClose } from '../../../shared/utilities/editorUtilities' import { applyChanges, createTempFileForDiff, + getIndentedCode, getSelectionFromRange, } from '../../../shared/utilities/textDocumentUtilities' -import { extractFileAndCodeSelectionFromMessage, fs, getErrorMsg, getIndentedCode, ToolkitError } from '../../../shared' +import { extractFileAndCodeSelectionFromMessage, fs, getErrorMsg, ToolkitError } from '../../../shared' class ContentProvider implements vscode.TextDocumentContentProvider { constructor(private uri: vscode.Uri) {} diff --git a/packages/core/src/amazonq/util/functionUtils.ts b/packages/core/src/amazonq/util/functionUtils.ts index c658b59aeef..b5d6a9bb9dc 100644 --- a/packages/core/src/amazonq/util/functionUtils.ts +++ b/packages/core/src/amazonq/util/functionUtils.ts @@ -4,7 +4,7 @@ */ /** - * Converts an array of key-value pairs into a Map object. + * Tries to create map and returns empty map if failed. * * @param {[unknown, unknown][]} arr - An array of tuples, where each tuple represents a key-value pair. * @returns {Map} A new Map object created from the input array. diff --git a/packages/core/src/shared/telemetry/vscodeTelemetry.json b/packages/core/src/shared/telemetry/vscodeTelemetry.json index 1a6f82b977a..005fc6c53ba 100644 --- a/packages/core/src/shared/telemetry/vscodeTelemetry.json +++ b/packages/core/src/shared/telemetry/vscodeTelemetry.json @@ -199,24 +199,6 @@ "type": "int", "description": "Number of characters in request" }, - { - "name": "cwsprChatInteractionType", - "allowedValues": [ - "acceptDiff", - "insertAtCursor", - "copySnippet", - "copy", - "clickLink", - "clickFollowUp", - "hoverReference", - "upvote", - "downvote", - "clickBodyLink", - "viewDiff" - ], - "type": "string", - "description": "Indicates the specific interaction type with a message in a conversation" - }, { "name": "cwsprChatInteractionTarget", "type": "string", diff --git a/packages/core/src/shared/utilities/textDocumentUtilities.ts b/packages/core/src/shared/utilities/textDocumentUtilities.ts index 4d5805ef639..71114bd2389 100644 --- a/packages/core/src/shared/utilities/textDocumentUtilities.ts +++ b/packages/core/src/shared/utilities/textDocumentUtilities.ts @@ -7,7 +7,7 @@ import * as _path from 'path' import * as vscode from 'vscode' import { getTabSizeSetting } from './editorUtilities' import { tempDirPath } from '../filesystemUtilities' -import { fs, getIndentedCode, ToolkitError } from '../index' +import { fs, indent, ToolkitError } from '../index' import { getLogger } from '../logger' /** @@ -165,3 +165,22 @@ export async function createTempFileForDiff( await applyChanges(doc, range, code) return tempFileUri } + +/** + * Indents the given code based on the current document's indentation at the selection start. + * + * @param message The message object containing the code. + * @param doc The VSCode document where the code is applied. + * @param selection The selection range in the document. + * @returns The processed code to be applied to the document. + */ +export function getIndentedCode(message: any, doc: vscode.TextDocument, selection: vscode.Selection) { + const indentRange = new vscode.Range(new vscode.Position(selection.start.line, 0), selection.active) + let indentation = doc.getText(indentRange) + + if (indentation.trim().length !== 0) { + indentation = ' '.repeat(indentation.length - indentation.trimStart().length) + } + + return indent(message.code, indentation.length) +} diff --git a/packages/core/src/shared/utilities/textUtilities.ts b/packages/core/src/shared/utilities/textUtilities.ts index d0af2e6de52..f337bb31276 100644 --- a/packages/core/src/shared/utilities/textUtilities.ts +++ b/packages/core/src/shared/utilities/textUtilities.ts @@ -417,22 +417,3 @@ export function extractFileAndCodeSelectionFromMessage(message: any) { const selection = message?.context?.focusAreaContext?.selectionInsideExtendedCodeBlock as vscode.Selection return { filePath, selection } } - -/** - * Indents the given code based on the current document's indentation at the selection start. - * - * @param {any} message - The message object containing the code. - * @param {vscode.TextDocument} doc - The VSCode document where the code is applied. - * @param {vscode.Selection} selection - The selection range in the document. - * @returns {string} - The processed code to be applied to the document. - */ -export function getIndentedCode(message: any, doc: vscode.TextDocument, selection: vscode.Selection) { - const indentRange = new vscode.Range(new vscode.Position(selection.start.line, 0), selection.active) - let indentation = doc.getText(indentRange) - - if (indentation.trim().length !== 0) { - indentation = ' '.repeat(indentation.length - indentation.trimStart().length) - } - - return indent(message.code, indentation.length) -}