Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/amazonq/util/functionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown, unknown>} A new Map object created from the input array.
Expand Down
18 changes: 0 additions & 18 deletions packages/core/src/shared/telemetry/vscodeTelemetry.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 20 additions & 1 deletion packages/core/src/shared/utilities/textDocumentUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -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)
}
19 changes: 0 additions & 19 deletions packages/core/src/shared/utilities/textUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading