提交 229ab747 编写于 作者: M Matt Bierner

Move TS extension activate to own file

上级 dec4686c
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
"onCommand:typescript.openTsServerLog", "onCommand:typescript.openTsServerLog",
"onCommand:workbench.action.tasks.runTask" "onCommand:workbench.action.tasks.runTask"
], ],
"main": "./out/typescriptMain", "main": "./out/extension",
"contributes": { "contributes": {
"languages": [ "languages": [
{ {
......
/*---------------------------------------------------------------------------------------------
* 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 { CommandManager } from './utils/commandManager';
import { ReloadTypeScriptProjectsCommand, SelectTypeScriptVersionCommand, ReloadJavaScriptProjectsCommand, RestartTsServerCommand, OpenTsServerLogCommand, TypeScriptGoToProjectConfigCommand, JavaScriptGoToProjectConfigCommand, LanguageDescription, TypeScriptServiceClientHost } from './typescriptMain';
import TypeScriptTaskProviderManager from './features/taskProvider';
import { getContributedTypeScriptServerPlugins } from './utils/plugins';
import * as ProjectStatus from './utils/projectStatus';
import * as languageModeIds from './utils/languageModeIds';
import * as languageConfigurations from './utils/languageConfigurations';
export const standardLanguageDescriptions: LanguageDescription[] = [
{
id: 'typescript',
diagnosticSource: 'ts',
modeIds: [languageModeIds.typescript, languageModeIds.typescriptreact],
configFile: 'tsconfig.json'
}, {
id: 'javascript',
diagnosticSource: 'js',
modeIds: [languageModeIds.javascript, languageModeIds.javascriptreact],
configFile: 'jsconfig.json'
}
];
export function activate(context: vscode.ExtensionContext): void {
const plugins = getContributedTypeScriptServerPlugins();
const commandManager = new CommandManager();
context.subscriptions.push(commandManager);
const lazyClientHost = (() => {
let clientHost: TypeScriptServiceClientHost | undefined;
return () => {
if (!clientHost) {
clientHost = new TypeScriptServiceClientHost(standardLanguageDescriptions, context.workspaceState, plugins, commandManager);
context.subscriptions.push(clientHost);
const host = clientHost;
clientHost.serviceClient.onReady().then(() => {
context.subscriptions.push(ProjectStatus.create(host.serviceClient, host.serviceClient.telemetryReporter,
path => new Promise<boolean>(resolve => setTimeout(() => resolve(host.handles(path)), 750)),
context.workspaceState));
}, () => {
// Nothing to do here. The client did show a message;
});
}
return clientHost;
};
})();
commandManager.register(new ReloadTypeScriptProjectsCommand(lazyClientHost));
commandManager.register(new ReloadJavaScriptProjectsCommand(lazyClientHost));
commandManager.register(new SelectTypeScriptVersionCommand(lazyClientHost));
commandManager.register(new OpenTsServerLogCommand(lazyClientHost));
commandManager.register(new RestartTsServerCommand(lazyClientHost));
commandManager.register(new TypeScriptGoToProjectConfigCommand(lazyClientHost));
commandManager.register(new JavaScriptGoToProjectConfigCommand(lazyClientHost));
context.subscriptions.push(new TypeScriptTaskProviderManager(() => lazyClientHost().serviceClient));
context.subscriptions.push(vscode.languages.setLanguageConfiguration(languageModeIds.jsxTags, languageConfigurations.jsxTags));
const supportedLanguage = [].concat.apply([], standardLanguageDescriptions.map(x => x.modeIds).concat(plugins.map(x => x.languages)));
function didOpenTextDocument(textDocument: vscode.TextDocument): boolean {
if (supportedLanguage.indexOf(textDocument.languageId) >= 0) {
openListener.dispose();
// Force activation
void lazyClientHost();
return true;
}
return false;
}
const openListener = vscode.workspace.onDidOpenTextDocument(didOpenTextDocument);
for (let textDocument of vscode.workspace.textDocuments) {
if (didOpenTextDocument(textDocument)) {
break;
}
}
}
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/TypeScript%20Indent.tmPreferences * https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/TypeScript%20Indent.tmPreferences
* ------------------------------------------------------------------------------------------ */ * ------------------------------------------------------------------------------------------ */
import { env, languages, commands, workspace, window, ExtensionContext, Memento, Diagnostic, Range, Disposable, Uri, MessageItem, DiagnosticSeverity, TextDocument } from 'vscode'; import { env, languages, commands, workspace, window, Memento, Diagnostic, Range, Disposable, Uri, MessageItem, DiagnosticSeverity, TextDocument } from 'vscode';
// This must be the first statement otherwise modules might got loaded with // This must be the first statement otherwise modules might got loaded with
// the wrong locale. // the wrong locale.
...@@ -25,21 +25,18 @@ import TypeScriptServiceClient from './typescriptServiceClient'; ...@@ -25,21 +25,18 @@ import TypeScriptServiceClient from './typescriptServiceClient';
import { ITypeScriptServiceClientHost } from './typescriptService'; import { ITypeScriptServiceClientHost } from './typescriptService';
import BufferSyncSupport from './features/bufferSyncSupport'; import BufferSyncSupport from './features/bufferSyncSupport';
import TypeScriptTaskProviderManager from './features/taskProvider';
import * as ProjectStatus from './utils/projectStatus';
import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus'; import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus';
import VersionStatus from './utils/versionStatus'; import VersionStatus from './utils/versionStatus';
import { getContributedTypeScriptServerPlugins, TypeScriptServerPlugin } from './utils/plugins'; import { TypeScriptServerPlugin } from './utils/plugins';
import { openOrCreateConfigFile, isImplicitProjectConfigFile } from './utils/tsconfig'; import { openOrCreateConfigFile, isImplicitProjectConfigFile } from './utils/tsconfig';
import { tsLocationToVsPosition } from './utils/convert'; import { tsLocationToVsPosition } from './utils/convert';
import FormattingConfigurationManager from './features/formattingConfigurationManager'; import FormattingConfigurationManager from './features/formattingConfigurationManager';
import * as languageModeIds from './utils/languageModeIds';
import * as languageConfigurations from './utils/languageConfigurations'; import * as languageConfigurations from './utils/languageConfigurations';
import { CommandManager, Command } from './utils/commandManager'; import { CommandManager, Command } from './utils/commandManager';
import DiagnosticsManager from './features/diagnostics'; import DiagnosticsManager from './features/diagnostics';
interface LanguageDescription { export interface LanguageDescription {
id: string; id: string;
diagnosticSource: string; diagnosticSource: string;
modeIds: string[]; modeIds: string[];
...@@ -47,21 +44,7 @@ interface LanguageDescription { ...@@ -47,21 +44,7 @@ interface LanguageDescription {
isExternal?: boolean; isExternal?: boolean;
} }
const standardLanguageDescriptions: LanguageDescription[] = [ export class ReloadTypeScriptProjectsCommand implements Command {
{
id: 'typescript',
diagnosticSource: 'ts',
modeIds: [languageModeIds.typescript, languageModeIds.typescriptreact],
configFile: 'tsconfig.json'
}, {
id: 'javascript',
diagnosticSource: 'js',
modeIds: [languageModeIds.javascript, languageModeIds.javascriptreact],
configFile: 'jsconfig.json'
}
];
class ReloadTypeScriptProjectsCommand implements Command {
public readonly id = 'typescript.reloadProjects'; public readonly id = 'typescript.reloadProjects';
public constructor( public constructor(
...@@ -73,7 +56,7 @@ class ReloadTypeScriptProjectsCommand implements Command { ...@@ -73,7 +56,7 @@ class ReloadTypeScriptProjectsCommand implements Command {
} }
} }
class ReloadJavaScriptProjectsCommand implements Command { export class ReloadJavaScriptProjectsCommand implements Command {
public readonly id = 'javascript.reloadProjects'; public readonly id = 'javascript.reloadProjects';
public constructor( public constructor(
...@@ -85,7 +68,7 @@ class ReloadJavaScriptProjectsCommand implements Command { ...@@ -85,7 +68,7 @@ class ReloadJavaScriptProjectsCommand implements Command {
} }
} }
class SelectTypeScriptVersionCommand implements Command { export class SelectTypeScriptVersionCommand implements Command {
public readonly id = 'typescript.selectTypeScriptVersion'; public readonly id = 'typescript.selectTypeScriptVersion';
public constructor( public constructor(
...@@ -97,7 +80,7 @@ class SelectTypeScriptVersionCommand implements Command { ...@@ -97,7 +80,7 @@ class SelectTypeScriptVersionCommand implements Command {
} }
} }
class OpenTsServerLogCommand implements Command { export class OpenTsServerLogCommand implements Command {
public readonly id = 'typescript.openTsServerLog'; public readonly id = 'typescript.openTsServerLog';
public constructor( public constructor(
...@@ -109,7 +92,7 @@ class OpenTsServerLogCommand implements Command { ...@@ -109,7 +92,7 @@ class OpenTsServerLogCommand implements Command {
} }
} }
class RestartTsServerCommand implements Command { export class RestartTsServerCommand implements Command {
public readonly id = 'typescript.restartTsServer'; public readonly id = 'typescript.restartTsServer';
public constructor( public constructor(
...@@ -121,7 +104,7 @@ class RestartTsServerCommand implements Command { ...@@ -121,7 +104,7 @@ class RestartTsServerCommand implements Command {
} }
} }
class TypeScriptGoToProjectConfigCommand implements Command { export class TypeScriptGoToProjectConfigCommand implements Command {
public readonly id = 'typescript.goToProjectConfig'; public readonly id = 'typescript.goToProjectConfig';
public constructor( public constructor(
...@@ -136,7 +119,7 @@ class TypeScriptGoToProjectConfigCommand implements Command { ...@@ -136,7 +119,7 @@ class TypeScriptGoToProjectConfigCommand implements Command {
} }
} }
class JavaScriptGoToProjectConfigCommand implements Command { export class JavaScriptGoToProjectConfigCommand implements Command {
public readonly id = 'javascript.goToProjectConfig'; public readonly id = 'javascript.goToProjectConfig';
public constructor( public constructor(
...@@ -151,63 +134,6 @@ class JavaScriptGoToProjectConfigCommand implements Command { ...@@ -151,63 +134,6 @@ class JavaScriptGoToProjectConfigCommand implements Command {
} }
} }
export function activate(context: ExtensionContext): void {
const plugins = getContributedTypeScriptServerPlugins();
const commandManager = new CommandManager();
context.subscriptions.push(commandManager);
const lazyClientHost = (() => {
let clientHost: TypeScriptServiceClientHost | undefined;
return () => {
if (!clientHost) {
clientHost = new TypeScriptServiceClientHost(standardLanguageDescriptions, context.workspaceState, plugins, commandManager);
context.subscriptions.push(clientHost);
const host = clientHost;
clientHost.serviceClient.onReady().then(() => {
context.subscriptions.push(ProjectStatus.create(host.serviceClient, host.serviceClient.telemetryReporter,
path => new Promise<boolean>(resolve => setTimeout(() => resolve(host.handles(path)), 750)),
context.workspaceState));
}, () => {
// Nothing to do here. The client did show a message;
});
}
return clientHost;
};
})();
commandManager.register(new ReloadTypeScriptProjectsCommand(lazyClientHost));
commandManager.register(new ReloadJavaScriptProjectsCommand(lazyClientHost));
commandManager.register(new SelectTypeScriptVersionCommand(lazyClientHost));
commandManager.register(new OpenTsServerLogCommand(lazyClientHost));
commandManager.register(new RestartTsServerCommand(lazyClientHost));
commandManager.register(new TypeScriptGoToProjectConfigCommand(lazyClientHost));
commandManager.register(new JavaScriptGoToProjectConfigCommand(lazyClientHost));
context.subscriptions.push(new TypeScriptTaskProviderManager(() => lazyClientHost().serviceClient));
context.subscriptions.push(languages.setLanguageConfiguration(languageModeIds.jsxTags, languageConfigurations.jsxTags));
const supportedLanguage = [].concat.apply([], standardLanguageDescriptions.map(x => x.modeIds).concat(plugins.map(x => x.languages)));
function didOpenTextDocument(textDocument: TextDocument): boolean {
if (supportedLanguage.indexOf(textDocument.languageId) >= 0) {
openListener.dispose();
// Force activation
void lazyClientHost();
return true;
}
return false;
}
const openListener = workspace.onDidOpenTextDocument(didOpenTextDocument);
for (let textDocument of workspace.textDocuments) {
if (didOpenTextDocument(textDocument)) {
break;
}
}
}
const validateSetting = 'validate.enable'; const validateSetting = 'validate.enable';
class LanguageProvider { class LanguageProvider {
...@@ -422,7 +348,7 @@ const styleCheckDiagnostics = [ ...@@ -422,7 +348,7 @@ const styleCheckDiagnostics = [
7030 // not all code paths return a value 7030 // not all code paths return a value
]; ];
class TypeScriptServiceClientHost implements ITypeScriptServiceClientHost { export class TypeScriptServiceClientHost implements ITypeScriptServiceClientHost {
private readonly ataProgressReporter: AtaProgressReporter; private readonly ataProgressReporter: AtaProgressReporter;
private readonly typingsStatus: TypingsStatus; private readonly typingsStatus: TypingsStatus;
private readonly client: TypeScriptServiceClient; private readonly client: TypeScriptServiceClient;
...@@ -453,7 +379,7 @@ class TypeScriptServiceClientHost implements ITypeScriptServiceClientHost { ...@@ -453,7 +379,7 @@ class TypeScriptServiceClientHost implements ITypeScriptServiceClientHost {
configFileWatcher.onDidDelete(handleProjectCreateOrDelete, this, this.disposables); configFileWatcher.onDidDelete(handleProjectCreateOrDelete, this, this.disposables);
configFileWatcher.onDidChange(handleProjectChange, this, this.disposables); configFileWatcher.onDidChange(handleProjectChange, this, this.disposables);
this.versionStatus = new VersionStatus(resource => this.client.normalizePath(resource)); this.versionStatus = new VersionStatus(resource => this.client ? this.client.normalizePath(resource) : null);
this.disposables.push(this.versionStatus); this.disposables.push(this.versionStatus);
this.client = new TypeScriptServiceClient(this, workspaceState, this.versionStatus, plugins); this.client = new TypeScriptServiceClient(this, workspaceState, this.versionStatus, plugins);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册