in src/common/code_suggestions/code_suggestions.ts [31:88]
constructor(context: vscode.ExtensionContext, manager: GitLabPlatformManager) {
this.stateManager = new CodeSuggestionsStateManager(manager, context);
const platformManagerForCodeSuggestions = new GitLabPlatformManagerForCodeSuggestions(manager);
this.#subscriptions.push(
platformManagerForCodeSuggestions,
vscode.commands.registerCommand(COMMAND_TOGGLE_CODE_SUGGESTIONS, () =>
toggleCodeSuggestions({ stateManager: this.stateManager }),
),
vscode.commands.registerCommand(SHOW_QUICK_PICK_MENU, () =>
showDuoQuickPickMenu({ stateManager: this.stateManager }),
),
);
this.statusBarItem = new CodeSuggestionsStatusBarItem(this.stateManager);
this.#gutterIcon = new CodeSuggestionsGutterIcon(context, this.stateManager);
this.legacyApiFallbackConfig = new LegacyApiFallbackConfig(platformManagerForCodeSuggestions);
const updateCodeSuggestionsStateForEditor = (editor?: vscode.TextEditor) => {
if (!editor) return;
this.legacyApiFallbackConfig
.verifyGitLabVersion()
.catch(() => this.legacyApiFallbackConfig.flagLegacyVersion());
};
const register = () => {
this.providerDisposable = vscode.languages.registerInlineCompletionItemProvider(
[{ scheme: 'file' }, { notebookType: '*' }, { scheme: 'gitlab-web-ide' }],
new CodeSuggestionsProvider({
manager: platformManagerForCodeSuggestions,
legacyApiFallbackConfig: this.legacyApiFallbackConfig,
stateManager: this.stateManager,
}),
);
updateCodeSuggestionsStateForEditor(vscode.window.activeTextEditor);
this.activeTextEditorChangeDisposable = vscode.window.onDidChangeActiveTextEditor(
updateCodeSuggestionsStateForEditor,
);
};
const enableOrDisableSuggestions = () => {
const disabledByUser = this.stateManager.isDisabledByUser();
if (disabledByUser) {
log.debug('Disabling code completion');
this.providerDisposable?.dispose();
this.activeTextEditorChangeDisposable?.dispose();
} else {
log.debug('Enabling code completion');
register();
}
};
this.stateManager.onDidChangeDisabledByUserState(enableOrDisableSuggestions);
enableOrDisableSuggestions();
}