Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d80850f
fix: pure addition edit suggestion should be treated as Completions s…
Will-ShaoHua Aug 15, 2025
3b8d6bc
fix: patch
Will-ShaoHua Aug 15, 2025
cd55b8e
fix: patch
Will-ShaoHua Aug 15, 2025
ad543e1
fix: patch
Will-ShaoHua Aug 15, 2025
0d085ae
fix: patch
Will-ShaoHua Aug 18, 2025
66480a3
Merge remote-tracking branch 'upstream/main' into fix
Will-ShaoHua Aug 18, 2025
ed467f9
Merge remote-tracking branch 'upstream/main' into fix
Will-ShaoHua Sep 29, 2025
97e7c10
fix: wip
Will-ShaoHua Sep 30, 2025
058164b
fix: wip
Will-ShaoHua Sep 30, 2025
fc7d505
fix: fix 1 case
Will-ShaoHua Sep 30, 2025
d72d327
fix: a
Will-ShaoHua Sep 30, 2025
c96f8f1
fix: comment
Will-ShaoHua Sep 30, 2025
9ae6045
fix: comment
Will-ShaoHua Sep 30, 2025
5983592
fix: cleanup test
Will-ShaoHua Sep 30, 2025
692b92b
fix: cleanup
Will-ShaoHua Oct 1, 2025
2404748
fix: rename
Will-ShaoHua Oct 1, 2025
bee02b5
fix: cleanup
Will-ShaoHua Oct 1, 2025
63ae62e
Merge remote-tracking branch 'upstream/main' into fix
Will-ShaoHua Oct 1, 2025
f206479
fix: file move
Will-ShaoHua Oct 1, 2025
51b8278
fix: file move
Will-ShaoHua Oct 1, 2025
035fc04
Merge remote-tracking branch 'upstream/main' into fix
Will-ShaoHua Oct 2, 2025
a1602c2
Merge remote-tracking branch 'upstream/main' into fix
Will-ShaoHua Oct 2, 2025
d67d784
fix: asd
Will-ShaoHua Oct 2, 2025
11942e9
fix: imporve
Will-ShaoHua Oct 4, 2025
178faea
fix: patch
Will-ShaoHua Oct 4, 2025
aa26de4
fix: add test
Will-ShaoHua Oct 6, 2025
8a7c019
Merge remote-tracking branch 'upstream/main' into fix
Will-ShaoHua Oct 7, 2025
a1a241f
fix: patch
Will-ShaoHua Oct 7, 2025
92c25f2
fix: test
Will-ShaoHua Oct 7, 2025
c64ea41
fix: t
Will-ShaoHua Oct 7, 2025
175a9b0
fix: t
Will-ShaoHua Oct 7, 2025
c3918f3
fix: t
Will-ShaoHua Oct 7, 2025
35ee185
fix: comment
Will-ShaoHua Oct 7, 2025
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 @@ -26,7 +26,7 @@ import {
SuggestionType,
} from '../../shared/codeWhispererService'
import { CodewhispererLanguage, getSupportedLanguageId } from '../../shared/languageDetection'
import { truncateOverlapWithRightContext } from './utils/mergeRightUtils'
import { mergeSuggestionsWithRightContext, truncateOverlapWithRightContext } from './utils/mergeRightUtils'
import { CodeWhispererSession, SessionManager } from './session/sessionManager'
import { CodePercentageTracker } from './tracker/codePercentageTracker'
import { getCompletionType, getEndPositionForAcceptedSuggestion, getErrorMessage, safeGet } from '../../shared/utils'
Expand Down Expand Up @@ -64,47 +64,6 @@ import { IdleWorkspaceManager } from '../workspaceContext/IdleWorkspaceManager'
import { URI } from 'vscode-uri'
import { isUsingIAMAuth } from '../../shared/utils'

const mergeSuggestionsWithRightContext = (
rightFileContext: string,
suggestions: Suggestion[],
includeImportsWithSuggestions: boolean,
range?: Range
): InlineCompletionItemWithReferences[] => {
return suggestions.map(suggestion => {
const insertText: string = truncateOverlapWithRightContext(rightFileContext, suggestion.content)
let references = suggestion.references
?.filter(
ref =>
!(
ref.recommendationContentSpan?.start && insertText.length <= ref.recommendationContentSpan.start
) && insertText.length
)
.map(r => {
return {
licenseName: r.licenseName,
referenceUrl: r.url,
referenceName: r.repository,
position: r.recommendationContentSpan && {
startCharacter: r.recommendationContentSpan.start,
endCharacter: r.recommendationContentSpan.end
? Math.min(r.recommendationContentSpan.end, insertText.length - 1)
: r.recommendationContentSpan.end,
},
}
})

return {
itemId: suggestion.itemId,
insertText: insertText,
range,
references: references?.length ? references : undefined,
mostRelevantMissingImports: includeImportsWithSuggestions
? suggestion.mostRelevantMissingImports
: undefined,
}
})
}

export const CodewhispererServerFactory =
(serviceManager: (credentialsProvider?: any) => AmazonQBaseServiceManager): Server =>
({ credentialsProvider, lsp, workspace, telemetry, logging, runtime, sdkInitializator }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { AmazonQError, AmazonQServiceConnectionExpiredError } from '../../shared
import { DocumentChangedListener } from './documentChangedListener'
import { EMPTY_RESULT, EDIT_DEBOUNCE_INTERVAL_MS } from './contants/constants'
import { StreakTracker } from './tracker/streakTracker'
import { processEditSuggestion } from './utils/diffUtils'

export class EditCompletionHandler {
private readonly editsEnabled: boolean
Expand Down Expand Up @@ -396,6 +397,13 @@ export class EditCompletionHandler {
textDocument?.uri || ''
)

const processedSuggestion = processEditSuggestion(
suggestion.content,
session.startPosition,
session.document
)
const isInlineEdit = processedSuggestion.type === SuggestionType.EDIT

if (isSimilarToRejected) {
// Mark as rejected in the session
session.setSuggestionState(suggestion.itemId, 'Reject')
Expand All @@ -405,14 +413,14 @@ export class EditCompletionHandler {
// Return empty item that will be filtered out
return {
insertText: '',
isInlineEdit: true,
isInlineEdit: isInlineEdit,
itemId: suggestion.itemId,
}
}

return {
insertText: suggestion.content,
isInlineEdit: true,
insertText: processedSuggestion.suggestionContent,
isInlineEdit: isInlineEdit,
itemId: suggestion.itemId,
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
import * as assert from 'assert'
import { categorizeUnifieddiff, extractAdditions, removeOverlapCodeFromSuggestion } from './diffUtils'

describe('extractAdditions', function () {
it('singleline', function () {
const udiff = `--- file:///Volumes/workplace/ide/sample_projects/Calculator/src/main/hello/MathUtil.java
+++ file:///Volumes/workplace/ide/sample_projects/Calculator/src/main/hello/MathUtil.java
@@ -1,9 +1,10 @@
public class MathUtil {
// write a function to add 2 numbers
public static int add(int a, int b) {

+ return a + b;
}

// write a function to subtract 2 numbers
public static int subtract(int a, int b) {
return a - b;`

const r = extractAdditions(udiff)
assert.strictEqual(r, ' return a + b;')
})

it('multiline', function () {
const udiff = `--- file:///Volumes/workplace/ide/sample_projects/Calculator/src/main/hello/MathUtil.java
+++ file:///Volumes/workplace/ide/sample_projects/Calculator/src/main/hello/MathUtil.java
@@ -1,9 +1,17 @@
public class MathUtil {
// write a function to add 2 numbers
public static int add(int a, int b) {

+ if (a > Integer.MAX_VALUE - b){
+ throw new IllegalArgumentException("Overflow!");
+ }
+ else if (a < Integer.MIN_VALUE - b){
+ throw new IllegalArgumentException("Underflow");
+ }
+ else{
+ return a + b;
+ }
}

// write a function to subtract 2 numbers
public static int subtract(int a, int b) {
return a - b;`

const r = extractAdditions(udiff)
assert.strictEqual(
r,
` if (a > Integer.MAX_VALUE - b){
throw new IllegalArgumentException("Overflow!");
}
else if (a < Integer.MIN_VALUE - b){
throw new IllegalArgumentException("Underflow");
}
else{
return a + b;
}`
)
})
})

describe('categorizeUnifieddiffv2 should return correct type (addOnly, edit, deleteOnly)', function () {
interface Case {
udiff: string
}

describe('addOnly', function () {
const addOnlyCases: Case[] = [
{
udiff: `--- file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
+++ file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
@@ -6,7 +6,11 @@

// write a function to subtract 2 numbers
public static int subtract(int a, int b) {
return a - b;
}
-
+
+ // write a function to multiply 2 numbers
+ public static int multiply(int a, int b) {
+ return a * b;
+ }
}`,
},
{
udiff: `--- file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
+++ file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
@@ -6,7 +6,11 @@

// write a function to subtract 2 numbers
public static int subtract(int a, int b) {
return a - b;
}
-
+
+
+ // write a function to multiply 2 numbers
+ public static int multiply(int a, int b) {
+ return a * b;
+ }
}`,
},
{
udiff: `--- file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
+++ file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
@@ -6,7 +6,11 @@

// write a function to subtract 2 numbers
public static int subtract(int a, int b) {
return a - b;
}
-
+
+ // write a function to multiply 2 numbers
+ public static int multiply(int a, int b) {
+ return a * b;
+ }
}`,
},
{
udiff: `--- file:///Volumes/workplace/ide/sample_projects/Calculator/src/main/hello/MathUtil.java
+++ file:///Volumes/workplace/ide/sample_projects/Calculator/src/main/hello/MathUtil.java
@@ -1,9 +1,10 @@
public class MathUtil {
// write a function to add 2 numbers
public static int add(int a, int b) {

+ return a + b;
}

// write a function to subtract 2 numbers
public static int subtract(int a, int b) {
return a - b;`,
},
{
udiff: `--- file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
+++ file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
@@ -3,7 +3,9 @@
public static int add(int a, int b) {
return a + b;
}

// write a function to subtract 2 numbers
-
+ public static int subtract(int a, int b) {
+ return a - b;
+ }
}`,
},
{
udiff: `--- file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
+++ file:///Volumes/workplace/ide/sample_projects/Calculator-2/src/main/hello/MathUtil.java
@@ -4,8 +4,8 @@
return a + b;
}

// write a function to subtract 2 numbers
public static int subtract(int a, int b) {
- return
+ return a - b;
}
}`,
},
]

for (let i = 0; i < addOnlyCases.length; i++) {
it(`case ${i}`, function () {
const actual = categorizeUnifieddiff(addOnlyCases[i].udiff)
assert.strictEqual(actual, 'addOnly')
})
}
})

describe('edit', function () {
const cases: Case[] = [
{
udiff: `--- a/src/main/hello/MathUtil.java
+++ b/src/main/hello/MathUtil.java
@@ -1,11 +1,11 @@
public class MathUtil {
// write a function to add 2 numbers
- public static int add(int a, int b) {
+ public static double add(double a, double b) {
return a + b;
}

// write a function to subtract 2 numbers
public static int subtract(int a, int b) {
public static double subtract(double a, double b) {
return a - b;
}
}`,
},
{
udiff: `--- a/server/aws-lsp-codewhisperer/src/shared/codeWhispererService.ts
+++ b/server/aws-lsp-codewhisperer/src/shared/codeWhispererService.ts
@@ -502,11 +502,7 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
: undefined
}

- private withProfileArn<T extends object>(request: T): T {
- if (!this.profileArn) return request
-
- return { ...request, profileArn: this.profileArn }
- }
+ // ddddddddddddddddd

async generateSuggestions(request: BaseGenerateSuggestionsRequest): Promise<GenerateSuggestionsResponse> {
// Cast is now safe because GenerateTokenSuggestionsRequest extends GenerateCompletionsRequest`,
},
]

for (let i = 0; i < cases.length; i++) {
it(`case ${i}`, function () {
const actual = categorizeUnifieddiff(cases[i].udiff)
assert.strictEqual(actual, 'edit')
})
}
})
})

describe('removeOverlapCodeFromSuggestion', function () {
interface Case {
s1: string
s2: string
expected: string
}

const cases: Case[] = [
{
s1: `return`,
s2: `return a + b`,
expected: ` a + b`,
},
{
s1: ` `,
s2: `return a + b`,
expected: `return a + b`,
},
{
s1: ` System.out.print`,
s2: `println("a + b =", a + b)
return a + b`,
expected: `ln("a + b =", a + b)
return a + b`,
},
]

for (let i = 0; i < cases.length; i++) {
it(`test case${i}`, function () {
const c = cases[i]
const actual = removeOverlapCodeFromSuggestion(c.s1, c.s2)
assert.strictEqual(actual, c.expected)
})
}
})
Loading
Loading