Skip to content

Commit d33c256

Browse files
authored
refactor(amazonq): move getIndentedCode, cleanup telemetry aws#5765
- move getIndentedCode to textDocumentUtilities - use cwsprChatInteractionType from aws-toolkit-common
1 parent 62e9cfb commit d33c256

File tree

5 files changed

+23
-40
lines changed

5 files changed

+23
-40
lines changed

packages/core/src/amazonq/commons/controllers/contentController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import { disposeOnEditorClose } from '../../../shared/utilities/editorUtilities'
1212
import {
1313
applyChanges,
1414
createTempFileForDiff,
15+
getIndentedCode,
1516
getSelectionFromRange,
1617
} from '../../../shared/utilities/textDocumentUtilities'
17-
import { extractFileAndCodeSelectionFromMessage, fs, getErrorMsg, getIndentedCode, ToolkitError } from '../../../shared'
18+
import { extractFileAndCodeSelectionFromMessage, fs, getErrorMsg, ToolkitError } from '../../../shared'
1819

1920
class ContentProvider implements vscode.TextDocumentContentProvider {
2021
constructor(private uri: vscode.Uri) {}

packages/core/src/amazonq/util/functionUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
/**
7-
* Converts an array of key-value pairs into a Map object.
7+
* Tries to create map and returns empty map if failed.
88
*
99
* @param {[unknown, unknown][]} arr - An array of tuples, where each tuple represents a key-value pair.
1010
* @returns {Map<unknown, unknown>} A new Map object created from the input array.

packages/core/src/shared/telemetry/vscodeTelemetry.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,24 +199,6 @@
199199
"type": "int",
200200
"description": "Number of characters in request"
201201
},
202-
{
203-
"name": "cwsprChatInteractionType",
204-
"allowedValues": [
205-
"acceptDiff",
206-
"insertAtCursor",
207-
"copySnippet",
208-
"copy",
209-
"clickLink",
210-
"clickFollowUp",
211-
"hoverReference",
212-
"upvote",
213-
"downvote",
214-
"clickBodyLink",
215-
"viewDiff"
216-
],
217-
"type": "string",
218-
"description": "Indicates the specific interaction type with a message in a conversation"
219-
},
220202
{
221203
"name": "cwsprChatInteractionTarget",
222204
"type": "string",

packages/core/src/shared/utilities/textDocumentUtilities.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as _path from 'path'
77
import * as vscode from 'vscode'
88
import { getTabSizeSetting } from './editorUtilities'
99
import { tempDirPath } from '../filesystemUtilities'
10-
import { fs, getIndentedCode, ToolkitError } from '../index'
10+
import { fs, indent, ToolkitError } from '../index'
1111
import { getLogger } from '../logger'
1212

1313
/**
@@ -165,3 +165,22 @@ export async function createTempFileForDiff(
165165
await applyChanges(doc, range, code)
166166
return tempFileUri
167167
}
168+
169+
/**
170+
* Indents the given code based on the current document's indentation at the selection start.
171+
*
172+
* @param message The message object containing the code.
173+
* @param doc The VSCode document where the code is applied.
174+
* @param selection The selection range in the document.
175+
* @returns The processed code to be applied to the document.
176+
*/
177+
export function getIndentedCode(message: any, doc: vscode.TextDocument, selection: vscode.Selection) {
178+
const indentRange = new vscode.Range(new vscode.Position(selection.start.line, 0), selection.active)
179+
let indentation = doc.getText(indentRange)
180+
181+
if (indentation.trim().length !== 0) {
182+
indentation = ' '.repeat(indentation.length - indentation.trimStart().length)
183+
}
184+
185+
return indent(message.code, indentation.length)
186+
}

packages/core/src/shared/utilities/textUtilities.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -417,22 +417,3 @@ export function extractFileAndCodeSelectionFromMessage(message: any) {
417417
const selection = message?.context?.focusAreaContext?.selectionInsideExtendedCodeBlock as vscode.Selection
418418
return { filePath, selection }
419419
}
420-
421-
/**
422-
* Indents the given code based on the current document's indentation at the selection start.
423-
*
424-
* @param {any} message - The message object containing the code.
425-
* @param {vscode.TextDocument} doc - The VSCode document where the code is applied.
426-
* @param {vscode.Selection} selection - The selection range in the document.
427-
* @returns {string} - The processed code to be applied to the document.
428-
*/
429-
export function getIndentedCode(message: any, doc: vscode.TextDocument, selection: vscode.Selection) {
430-
const indentRange = new vscode.Range(new vscode.Position(selection.start.line, 0), selection.active)
431-
let indentation = doc.getText(indentRange)
432-
433-
if (indentation.trim().length !== 0) {
434-
indentation = ' '.repeat(indentation.length - indentation.trimStart().length)
435-
}
436-
437-
return indent(message.code, indentation.length)
438-
}

0 commit comments

Comments
 (0)