mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-02 06:21:50 +01:00
Move lazyClientHost to own file
This commit is contained in:
@@ -9,16 +9,10 @@ import { Api, getExtensionApi } from './api';
|
||||
import { registerCommands } from './commands/index';
|
||||
import { LanguageConfigurationManager } from './features/languageConfiguration';
|
||||
import * as task from './features/task';
|
||||
import TypeScriptServiceClientHost from './typeScriptServiceClientHost';
|
||||
import { flatten } from './utils/arrays';
|
||||
import { createLazyClientHost, lazilyActivateClient } from './lazyClientHost';
|
||||
import { CommandManager } from './utils/commandManager';
|
||||
import * as electron from './utils/electron';
|
||||
import * as fileSchemes from './utils/fileSchemes';
|
||||
import { standardLanguageDescriptions } from './utils/languageDescription';
|
||||
import * as ProjectStatus from './utils/largeProjectStatus';
|
||||
import { lazy, Lazy } from './utils/lazy';
|
||||
import LogDirectoryProvider from './utils/logDirectoryProvider';
|
||||
import ManagedFileContextManager from './utils/managedFileContext';
|
||||
import { PluginManager } from './utils/plugins';
|
||||
|
||||
export function activate(
|
||||
@@ -33,7 +27,9 @@ export function activate(
|
||||
const onCompletionAccepted = new vscode.EventEmitter<vscode.CompletionItem>();
|
||||
context.subscriptions.push(onCompletionAccepted);
|
||||
|
||||
const lazyClientHost = createLazyClientHost(context, pluginManager, commandManager, item => {
|
||||
const logDirectoryProvider = new LogDirectoryProvider(context);
|
||||
|
||||
const lazyClientHost = createLazyClientHost(context, pluginManager, commandManager, logDirectoryProvider, item => {
|
||||
onCompletionAccepted.fire(item);
|
||||
});
|
||||
|
||||
@@ -50,84 +46,6 @@ export function activate(
|
||||
return getExtensionApi(onCompletionAccepted.event, pluginManager);
|
||||
}
|
||||
|
||||
function createLazyClientHost(
|
||||
context: vscode.ExtensionContext,
|
||||
pluginManager: PluginManager,
|
||||
commandManager: CommandManager,
|
||||
onCompletionAccepted: (item: vscode.CompletionItem) => void,
|
||||
): Lazy<TypeScriptServiceClientHost> {
|
||||
return lazy(() => {
|
||||
const logDirectoryProvider = new LogDirectoryProvider(context);
|
||||
|
||||
const clientHost = new TypeScriptServiceClientHost(
|
||||
standardLanguageDescriptions,
|
||||
context.workspaceState,
|
||||
pluginManager,
|
||||
commandManager,
|
||||
logDirectoryProvider,
|
||||
onCompletionAccepted);
|
||||
|
||||
context.subscriptions.push(clientHost);
|
||||
|
||||
clientHost.serviceClient.onReady(() => {
|
||||
context.subscriptions.push(
|
||||
ProjectStatus.create(
|
||||
clientHost.serviceClient,
|
||||
clientHost.serviceClient.telemetryReporter));
|
||||
});
|
||||
|
||||
return clientHost;
|
||||
});
|
||||
}
|
||||
|
||||
function lazilyActivateClient(
|
||||
lazyClientHost: Lazy<TypeScriptServiceClientHost>,
|
||||
pluginManager: PluginManager,
|
||||
) {
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
|
||||
const supportedLanguage = flatten([
|
||||
...standardLanguageDescriptions.map(x => x.modeIds),
|
||||
...pluginManager.plugins.map(x => x.languages)
|
||||
]);
|
||||
|
||||
let hasActivated = false;
|
||||
const maybeActivate = (textDocument: vscode.TextDocument): boolean => {
|
||||
if (!hasActivated && isSupportedDocument(supportedLanguage, textDocument)) {
|
||||
hasActivated = true;
|
||||
// Force activation
|
||||
void lazyClientHost.value;
|
||||
|
||||
disposables.push(new ManagedFileContextManager(resource => {
|
||||
return lazyClientHost.value.serviceClient.toPath(resource);
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const didActivate = vscode.workspace.textDocuments.some(maybeActivate);
|
||||
if (!didActivate) {
|
||||
const openListener = vscode.workspace.onDidOpenTextDocument(doc => {
|
||||
if (maybeActivate(doc)) {
|
||||
openListener.dispose();
|
||||
}
|
||||
}, undefined, disposables);
|
||||
}
|
||||
|
||||
return vscode.Disposable.from(...disposables);
|
||||
}
|
||||
|
||||
function isSupportedDocument(
|
||||
supportedLanguage: string[],
|
||||
document: vscode.TextDocument
|
||||
): boolean {
|
||||
if (supportedLanguage.indexOf(document.languageId) < 0) {
|
||||
return false;
|
||||
}
|
||||
return fileSchemes.isSupportedScheme(document.uri.scheme);
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
rimraf.sync(electron.getInstanceDir());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import TypeScriptServiceClientHost from './typeScriptServiceClientHost';
|
||||
import { flatten } from './utils/arrays';
|
||||
import { CommandManager } from './utils/commandManager';
|
||||
import * as fileSchemes from './utils/fileSchemes';
|
||||
import { standardLanguageDescriptions } from './utils/languageDescription';
|
||||
import * as ProjectStatus from './utils/largeProjectStatus';
|
||||
import { lazy, Lazy } from './utils/lazy';
|
||||
import LogDirectoryProvider from './utils/logDirectoryProvider';
|
||||
import ManagedFileContextManager from './utils/managedFileContext';
|
||||
import { PluginManager } from './utils/plugins';
|
||||
|
||||
export function createLazyClientHost(
|
||||
context: vscode.ExtensionContext,
|
||||
pluginManager: PluginManager,
|
||||
commandManager: CommandManager,
|
||||
logDirectoryProvider: LogDirectoryProvider,
|
||||
onCompletionAccepted: (item: vscode.CompletionItem) => void,
|
||||
): Lazy<TypeScriptServiceClientHost> {
|
||||
return lazy(() => {
|
||||
const clientHost = new TypeScriptServiceClientHost(
|
||||
standardLanguageDescriptions,
|
||||
context.workspaceState,
|
||||
pluginManager,
|
||||
commandManager,
|
||||
logDirectoryProvider,
|
||||
onCompletionAccepted);
|
||||
|
||||
context.subscriptions.push(clientHost);
|
||||
|
||||
clientHost.serviceClient.onReady(() => {
|
||||
context.subscriptions.push(
|
||||
ProjectStatus.create(
|
||||
clientHost.serviceClient,
|
||||
clientHost.serviceClient.telemetryReporter));
|
||||
});
|
||||
|
||||
return clientHost;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function lazilyActivateClient(
|
||||
lazyClientHost: Lazy<TypeScriptServiceClientHost>,
|
||||
pluginManager: PluginManager,
|
||||
) {
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
|
||||
const supportedLanguage = flatten([
|
||||
...standardLanguageDescriptions.map(x => x.modeIds),
|
||||
...pluginManager.plugins.map(x => x.languages)
|
||||
]);
|
||||
|
||||
let hasActivated = false;
|
||||
const maybeActivate = (textDocument: vscode.TextDocument): boolean => {
|
||||
if (!hasActivated && isSupportedDocument(supportedLanguage, textDocument)) {
|
||||
hasActivated = true;
|
||||
// Force activation
|
||||
void lazyClientHost.value;
|
||||
|
||||
disposables.push(new ManagedFileContextManager(resource => {
|
||||
return lazyClientHost.value.serviceClient.toPath(resource);
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const didActivate = vscode.workspace.textDocuments.some(maybeActivate);
|
||||
if (!didActivate) {
|
||||
const openListener = vscode.workspace.onDidOpenTextDocument(doc => {
|
||||
if (maybeActivate(doc)) {
|
||||
openListener.dispose();
|
||||
}
|
||||
}, undefined, disposables);
|
||||
}
|
||||
|
||||
return vscode.Disposable.from(...disposables);
|
||||
}
|
||||
|
||||
function isSupportedDocument(
|
||||
supportedLanguage: string[],
|
||||
document: vscode.TextDocument
|
||||
): boolean {
|
||||
if (supportedLanguage.indexOf(document.languageId) < 0) {
|
||||
return false;
|
||||
}
|
||||
return fileSchemes.isSupportedScheme(document.uri.scheme);
|
||||
}
|
||||
Reference in New Issue
Block a user