-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(autoedits): make it reactive to config changes #6537
Changes from 7 commits
8907266
1116bc2
a393484
f72b35d
bee12bc
0f22a0e
3652c82
1a8008e
5920f2e
e74bf61
19feded
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,8 @@ import { isReinstalling } from '../uninstall/reinstall' | |
import type { CommandResult } from './CommandResult' | ||
import { showAccountMenu } from './auth/account-menu' | ||
import { showSignInMenu, showSignOutMenu, tokenCallbackHandler } from './auth/auth' | ||
import { AutoeditsProvider } from './autoedits/autoedits-provider' | ||
import { createAutoEditsProvider } from './autoedits/create-autoedits-provider' | ||
import { autoeditsOutputChannelLogger } from './autoedits/output-channel-logger' | ||
import { registerAutoEditTestRenderCommand } from './autoedits/renderer/mock-renderer' | ||
import type { MessageProviderOptions } from './chat/MessageProvider' | ||
import { ChatsController, CodyChatEditorViewType } from './chat/chat-view/ChatsController' | ||
|
@@ -707,30 +708,26 @@ function registerAutoEdits(chatClient: ChatClient, disposables: vscode.Disposabl | |
) | ||
) | ||
.pipe( | ||
map(([config, authStatus, autoeditEnabled]) => { | ||
if (shouldEnableExperimentalAutoedits(config, autoeditEnabled, authStatus)) { | ||
const provider = new AutoeditsProvider(chatClient) | ||
const completionRegistration = | ||
vscode.languages.registerInlineCompletionItemProvider( | ||
[{ scheme: 'file', language: '*' }, { notebookType: '*' }], | ||
provider | ||
) | ||
|
||
// Command used to trigger autoedits manually via command palette and is also used by e2e test | ||
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' | ||
) | ||
} | ||
) | ||
return vscode.Disposable.from(provider, completionRegistration) | ||
distinctUntilChanged((a, b) => { | ||
return ( | ||
isEqual(a[0].configuration, b[0].configuration) && | ||
isEqual(a[1], b[1]) && | ||
isEqual(a[2], b[2]) | ||
) | ||
}), | ||
Comment on lines
+714
to
+720
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😭 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simply copied from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😭😭😭 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think there's a TODO to address it. We should look into it at some point. |
||
switchMap(([config, authStatus, autoeditEnabled]) => { | ||
if (!shouldEnableExperimentalAutoedits(config, autoeditEnabled, authStatus)) { | ||
return NEVER | ||
} | ||
return [] | ||
return createAutoEditsProvider({ | ||
config, | ||
authStatus, | ||
chatClient, | ||
}) | ||
}), | ||
catchError(error => { | ||
autoeditsOutputChannelLogger.logError('registerAutoedits', 'Error', error) | ||
return NEVER | ||
}) | ||
) | ||
.subscribe({}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we migrate settings from people with the old configuration field in their settings.json? If I have
"cody.autocomplete.enabled": false
in my settings I expectCONFIG_KEY.suggestionsMode
to be false too when I upgrade to the new version. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, sorry I missed this.
Should we add a manual override here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we programmatically migrate the current setting value to a new field? For example, if
autocomplete.enabled
is set tofalse
,suggestions.mode
should be manually updated tooff
. Also, let's create an issue to follow up and remove this code later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added override and create issue: https://linear.app/sourcegraph/issue/CODY-4631/remove-backward-compatibility-override-for-autocomplete-after