-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autoedits): make it reactive to config changes (#6537)
## Context Currently `auto-edits` is not reactive to config changes and hence requires vscode reloading. If the user doesn't reload vscode `auto-edits` suggestion doesn't do away because the `auto-edits` provider is not `disposed` on the config change. This results into: 1. If the user turns off the suggestion mode: they will keep on seeing the `auto-edits` suggestions. 2. If user switches from the `auto-edits` to `autocomplete` mode, they will see the suggestion from both `autocomplete` and `auto-edits`. 3. The PR makes `auto-edits` reactive to the `authStatus` and `config` change similar to `autocomplete`, so that `auto-edits` is reactive and destroyed/created on the config changes without reloading vscode. 4. Build on top of: #6523 Example image below: <img width="607" alt="image" src="https://github.com/user-attachments/assets/c87a06d6-063e-46f1-b87e-8ef9ba59f519" /> ## Test plan 1. Add the breakpoints at `dispose` function and `provideInlineCompletion` function for `autocomplete` and `auto-edits` and make sure they are disposed and created upon config changes without reloading vscode. 2. CI
- Loading branch information
1 parent
059b5d5
commit dc16680
Showing
3 changed files
with
87 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Observable, map } from 'observable-fns' | ||
import * as vscode from 'vscode' | ||
|
||
import { | ||
type AuthenticatedAuthStatus, | ||
type ChatClient, | ||
NEVER, | ||
type PickResolvedConfiguration, | ||
type UnauthenticatedAuthStatus, | ||
createDisposables, | ||
skipPendingOperation, | ||
} from '@sourcegraph/cody-shared' | ||
import { AutoeditsProvider } from './autoedits-provider' | ||
import { autoeditsOutputChannelLogger } from './output-channel-logger' | ||
|
||
interface AutoeditsItemProviderArgs { | ||
config: PickResolvedConfiguration<{ configuration: true }> | ||
authStatus: UnauthenticatedAuthStatus | Pick<AuthenticatedAuthStatus, 'authenticated' | 'endpoint'> | ||
chatClient: ChatClient | ||
} | ||
|
||
export function createAutoEditsProvider({ | ||
config: { configuration }, | ||
authStatus, | ||
chatClient, | ||
}: AutoeditsItemProviderArgs): Observable<void> { | ||
if (!configuration.experimentalAutoeditsEnabled) { | ||
return NEVER | ||
} | ||
|
||
if (!authStatus.authenticated) { | ||
if (!authStatus.pendingValidation) { | ||
autoeditsOutputChannelLogger.logDebug('createProvider', 'You are not signed in.') | ||
} | ||
return NEVER | ||
} | ||
|
||
return Observable.of(undefined).pipe( | ||
skipPendingOperation(), | ||
createDisposables(() => { | ||
const provider = new AutoeditsProvider(chatClient) | ||
return [ | ||
vscode.commands.registerCommand('cody.command.autoedits-manual-trigger', async () => { | ||
await vscode.commands.executeCommand('editor.action.inlineSuggest.hide') | ||
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger') | ||
}), | ||
vscode.languages.registerInlineCompletionItemProvider( | ||
[{ scheme: 'file', language: '*' }, { notebookType: '*' }], | ||
provider | ||
), | ||
provider, | ||
] | ||
}), | ||
map(() => undefined) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters