mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
/*---------------------------------------------------------
|
|
* Copyright (C) Microsoft Corporation. All rights reserved.
|
|
*--------------------------------------------------------*/
|
|
|
|
import { workspace, languages, window, commands, ExtensionContext, Disposable } from 'vscode';
|
|
import ContentProvider, { encodeLocation } from './provider';
|
|
|
|
export function activate(context: ExtensionContext) {
|
|
|
|
const provider = new ContentProvider();
|
|
|
|
// register content provider for scheme `references`
|
|
// register document link provider for scheme `references`
|
|
const providerRegistrations = Disposable.from(
|
|
workspace.registerTextDocumentContentProvider(ContentProvider.scheme, provider),
|
|
languages.registerDocumentLinkProvider({ scheme: ContentProvider.scheme }, provider)
|
|
);
|
|
|
|
// register command that crafts an uri with the `references` scheme,
|
|
// open the dynamic document, and shows it in the next editor
|
|
const commandRegistration = commands.registerTextEditorCommand('editor.printReferences', editor => {
|
|
const uri = encodeLocation(editor.document.uri, editor.selection.active);
|
|
return workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, editor.viewColumn! + 1));
|
|
});
|
|
|
|
context.subscriptions.push(
|
|
provider,
|
|
commandRegistration,
|
|
providerRegistrations
|
|
);
|
|
}
|