Skip to content

Conversation

Will-ShaoHua
Copy link
Contributor

@Will-ShaoHua Will-ShaoHua commented Jul 27, 2025

Problem

  1. completion and edits code path are tightly coupled
  2. completion is executed in a blocking manner whereas this will cause edits suggestion to have "stale" context.

Solution

  1. completely separate out edits code path from completion
  2. introduce a separate language server API for edits

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

readonly editsSessionManager: SessionManager
) {}

async init(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this init to the constructor so that inlineCompletionHandler does not need to be undefined?

@@ -181,6 +270,8 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
/** If user clicks "Upgrade" multiple times, cancel the previous wait-promise. */
#waitUntilSubscriptionCancelSource?: CancellationTokenSource

private cache: Map<string, GenerateSuggestionsResponse> = new Map()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used

@andrewyuq andrewyuq requested a review from Copilot August 1, 2025 20:00
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This refactor removes the amazonQServiceManager parameter from supplemental context utility functions, simplifying the API and centralizing service management responsibility. The change appears to be part of consolidating how code path triggering is handled.

  • Remove optional amazonQServiceManager parameter from supplemental context functions
  • Update all function calls to match the simplified signature
  • Maintain existing functionality while improving separation of concerns

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
supplementalContextUtil.ts Remove amazonQServiceManager parameter from fetchSupplementalContext function signature
supplementalContextUtil.test.ts Update test calls to match simplified function signature
crossFileContextUtil.ts Remove amazonQServiceManager parameter from fetchProjectContext function
codeWhispererService.ts Add comprehensive refactoring including new file context method, abstract supplemental context construction, and service-specific implementations
codeWhispererService.test.ts Add mock implementation for new abstract constructSupplementalContext method
trigger.ts New file implementing trigger logic for completions and edits
sessionManager.ts Add support for separate completion and edit session managers
logInlineCompletionSessionResultsHandler.ts New handler for logging inline completion session results
inlineCompletionHandler.ts New dedicated handler for inline completions
editCompletionHandler.ts New dedicated handler for edit completions
documentChangedListener.ts New listener for tracking document changes
codewhispererController.ts New controller orchestrating completion handlers
codeWhispererServer.ts Major refactor replacing inline implementation with controller-based architecture
codeDiffTracker.ts Add AcceptedInlineSuggestionEntry interface
autoTrigger.ts Update previousDecision parameter to allow undefined

// add cancellation check
// add error check
this.logging.info(request.editorState?.document?.text ?? '')
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the entire document text could expose sensitive information in logs. Consider logging only metadata like document length or a sanitized summary instead.

Suggested change
this.logging.info(request.editorState?.document?.text ?? '')
const docTextLength = request.editorState?.document?.text?.length ?? 0
const filename = request.fileContext?.filename ?? 'unknown'
this.logging.info(`Document length: ${docTextLength}, Filename: ${filename}`)

Copilot uses AI. Check for mistakes.

Comment on lines 273 to 274
private cache: Map<string, GenerateSuggestionsResponse> = new Map()

Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache is declared but never used in the visible code. Consider implementing cache logic or removing this unused field to avoid confusion.

Suggested change
private cache: Map<string, GenerateSuggestionsResponse> = new Map()

Copilot uses AI. Check for mistakes.

token: CancellationToken
): Promise<InlineCompletionListWithReferences> {
if (!this.inlineCompletionHandler) {
throw new Error('')
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty error message provides no useful information for debugging. Consider adding a descriptive message like 'InlineCompletionHandler not initialized'.

Suggested change
throw new Error('')
throw new Error('InlineCompletionHandler not initialized')

Copilot uses AI. Check for mistakes.

token: CancellationToken
): Promise<InlineCompletionListWithReferences> {
if (!this.editCompletionHandler) {
throw new Error('')
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty error message provides no useful information for debugging. Consider adding a descriptive message like 'EditCompletionHandler not initialized'.

Suggested change
throw new Error('')
throw new Error('EditCompletionHandler not initialized')

Copilot uses AI. Check for mistakes.


async onLogInlineCompletionSessionResultsHandler(params: LogInlineCompletionSessionResultsParams) {
if (!this.logInlineCompletionSessionResultsHandler) {
throw new Error('')
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty error message provides no useful information for debugging. Consider adding a descriptive message like 'LogInlineCompletionSessionResultsHandler not initialized'.

Suggested change
throw new Error('')
throw new Error('LogInlineCompletionSessionResultsHandler not initialized')

Copilot uses AI. Check for mistakes.

if (this.customizationArn) request.customizationArn = this.customizationArn
const response = await this.client.generateCompletions(this.withProfileArn(request)).promise()
this.logging.info(
`GenerateCompletion response:
"version": "debounced gc",
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded string 'debounced gc' in logging appears to be debug code that should be removed or made configurable.

Suggested change
"version": "debounced gc",

Copilot uses AI. Check for mistakes.

@Will-ShaoHua Will-ShaoHua changed the title refactor: trigger code path refactor: trigger code path & non-blocking edits trigger Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants