Add tokenization and context provider API types
- Implemented window delineation tests for indentation-based tokenization. - Created tokenizer module with various tokenization strategies including TTokenizer and ApproximateTokenizer. - Added type definitions for authentication parameters and code citation notifications. - Introduced context provider API for extensions to supply additional context items to Copilot. - Defined core types and schemas for position and range. - Established status types for agent status management in IDEs.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Range, commands, window, type Disposable } from 'vscode';
|
||||
import { CopilotNamedAnnotationList } from '../../../../../../platform/completions-core/common/openai/copilotAnnotations';
|
||||
import { DisposableStore, IDisposable } from '../../../../../../util/vs/base/common/lifecycle';
|
||||
import { IInstantiationService, type ServicesAccessor } from '../../../../../../util/vs/platform/instantiation/common/instantiation';
|
||||
import * as constants from '../constants';
|
||||
import { registerCommand } from '../telemetry';
|
||||
import { wrapDoc } from '../textDocumentManager';
|
||||
import { CopilotSuggestionsPanelManager } from './copilotSuggestionsPanelManager';
|
||||
|
||||
// Exported for testing
|
||||
export enum PanelNavigationType {
|
||||
Previous = 'previous',
|
||||
Next = 'next',
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface contains data associated to a completion displayed in the panel.
|
||||
*/
|
||||
export interface PanelCompletion {
|
||||
insertText: string;
|
||||
range: Range;
|
||||
copilotAnnotations?: CopilotNamedAnnotationList;
|
||||
postInsertionCallback: () => PromiseLike<void> | void;
|
||||
}
|
||||
|
||||
export function registerPanelSupport(accessor: ServicesAccessor): Disposable {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const suggestionsPanelManager = instantiationService.createInstance(CopilotSuggestionsPanelManager);
|
||||
|
||||
const disposableStore = new DisposableStore();
|
||||
|
||||
function registerOpenPanelCommand(id: string): IDisposable {
|
||||
return registerCommand(accessor, id, async () => {
|
||||
// hide ghost text while opening the generation ui
|
||||
await commands.executeCommand('editor.action.inlineSuggest.hide');
|
||||
await instantiationService.invokeFunction(commandOpenPanel, suggestionsPanelManager);
|
||||
});
|
||||
}
|
||||
|
||||
// Register both commands to also support command palette
|
||||
disposableStore.add(registerOpenPanelCommand(constants.CMDOpenPanelChat));
|
||||
disposableStore.add(registerOpenPanelCommand(constants.CMDOpenPanelClient));
|
||||
|
||||
// No command palette support needed for these commands
|
||||
disposableStore.add(suggestionsPanelManager.registerCommands());
|
||||
|
||||
return disposableStore;
|
||||
}
|
||||
|
||||
function commandOpenPanel(accessor: ServicesAccessor, suggestionsPanelManager: CopilotSuggestionsPanelManager) {
|
||||
const editor = window.activeTextEditor;
|
||||
if (!editor) { return; }
|
||||
const wrapped = wrapDoc(editor.document);
|
||||
if (!wrapped) { return; }
|
||||
|
||||
const { line, character } = editor.selection.active;
|
||||
|
||||
suggestionsPanelManager.renderPanel(editor.document, { line, character }, wrapped);
|
||||
return commands.executeCommand('setContext', constants.CopilotPanelVisible, true);
|
||||
}
|
||||
Reference in New Issue
Block a user