diff --git a/extensions/typescript/src/commands.ts b/extensions/typescript/src/commands.ts new file mode 100644 index 00000000000..704fec3df5e --- /dev/null +++ b/extensions/typescript/src/commands.ts @@ -0,0 +1,99 @@ +/*--------------------------------------------------------------------------------------------- + * 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 './typescriptMain'; +import { Command } from './utils/commandManager'; + +export class ReloadTypeScriptProjectsCommand implements Command { + public readonly id = 'typescript.reloadProjects'; + + public constructor( + private readonly lazyClientHost: () => TypeScriptServiceClientHost + ) { } + + public execute() { + this.lazyClientHost().reloadProjects(); + } +} + +export class ReloadJavaScriptProjectsCommand implements Command { + public readonly id = 'javascript.reloadProjects'; + + public constructor( + private readonly lazyClientHost: () => TypeScriptServiceClientHost + ) { } + + public execute() { + this.lazyClientHost().reloadProjects(); + } +} + +export class SelectTypeScriptVersionCommand implements Command { + public readonly id = 'typescript.selectTypeScriptVersion'; + + public constructor( + private readonly lazyClientHost: () => TypeScriptServiceClientHost + ) { } + + public execute() { + this.lazyClientHost().serviceClient.onVersionStatusClicked(); + } +} + +export class OpenTsServerLogCommand implements Command { + public readonly id = 'typescript.openTsServerLog'; + + public constructor( + private readonly lazyClientHost: () => TypeScriptServiceClientHost + ) { } + + public execute() { + this.lazyClientHost().serviceClient.openTsServerLogFile(); + } +} + +export class RestartTsServerCommand implements Command { + public readonly id = 'typescript.restartTsServer'; + + public constructor( + private readonly lazyClientHost: () => TypeScriptServiceClientHost + ) { } + + public execute() { + this.lazyClientHost().serviceClient.restartTsServer(); + } +} + +export class TypeScriptGoToProjectConfigCommand implements Command { + public readonly id = 'typescript.goToProjectConfig'; + + public constructor( + private readonly lazyClientHost: () => TypeScriptServiceClientHost, + ) { } + + public execute() { + const editor = vscode.window.activeTextEditor; + if (editor) { + this.lazyClientHost().goToProjectConfig(true, editor.document.uri); + } + } +} + +export class JavaScriptGoToProjectConfigCommand implements Command { + public readonly id = 'javascript.goToProjectConfig'; + + public constructor( + private readonly lazyClientHost: () => TypeScriptServiceClientHost, + ) { } + + public execute() { + const editor = vscode.window.activeTextEditor; + if (editor) { + this.lazyClientHost().goToProjectConfig(false, editor.document.uri); + } + } +} \ No newline at end of file diff --git a/extensions/typescript/src/extension.ts b/extensions/typescript/src/extension.ts index 6a194e3f4e7..e07d7524799 100644 --- a/extensions/typescript/src/extension.ts +++ b/extensions/typescript/src/extension.ts @@ -5,7 +5,9 @@ import * as vscode from 'vscode'; import { CommandManager } from './utils/commandManager'; -import { ReloadTypeScriptProjectsCommand, SelectTypeScriptVersionCommand, ReloadJavaScriptProjectsCommand, RestartTsServerCommand, OpenTsServerLogCommand, TypeScriptGoToProjectConfigCommand, JavaScriptGoToProjectConfigCommand, TypeScriptServiceClientHost } from './typescriptMain'; +import { TypeScriptServiceClientHost } from './typescriptMain'; +import * as commands from './commands'; + import TypeScriptTaskProviderManager from './features/taskProvider'; import { getContributedTypeScriptServerPlugins, TypeScriptServerPlugin } from './utils/plugins'; import * as ProjectStatus from './utils/projectStatus'; @@ -70,11 +72,11 @@ function registerCommands( commandManager: CommandManager, lazyClientHost: () => TypeScriptServiceClientHost ) { - 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)); + commandManager.register(new commands.ReloadTypeScriptProjectsCommand(lazyClientHost)); + commandManager.register(new commands.ReloadJavaScriptProjectsCommand(lazyClientHost)); + commandManager.register(new commands.SelectTypeScriptVersionCommand(lazyClientHost)); + commandManager.register(new commands.OpenTsServerLogCommand(lazyClientHost)); + commandManager.register(new commands.RestartTsServerCommand(lazyClientHost)); + commandManager.register(new commands.TypeScriptGoToProjectConfigCommand(lazyClientHost)); + commandManager.register(new commands.JavaScriptGoToProjectConfigCommand(lazyClientHost)); } diff --git a/extensions/typescript/src/typescriptMain.ts b/extensions/typescript/src/typescriptMain.ts index 85b74c9455c..a598699abd6 100644 --- a/extensions/typescript/src/typescriptMain.ts +++ b/extensions/typescript/src/typescriptMain.ts @@ -33,100 +33,10 @@ import { openOrCreateConfigFile, isImplicitProjectConfigFile } from './utils/tsc import { tsLocationToVsPosition } from './utils/convert'; import FormattingConfigurationManager from './features/formattingConfigurationManager'; import * as languageConfigurations from './utils/languageConfigurations'; -import { CommandManager, Command } from './utils/commandManager'; +import { CommandManager } from './utils/commandManager'; import DiagnosticsManager from './features/diagnostics'; import { LanguageDescription } from './utils/languageDescription'; -export class ReloadTypeScriptProjectsCommand implements Command { - public readonly id = 'typescript.reloadProjects'; - - public constructor( - private readonly lazyClientHost: () => TypeScriptServiceClientHost - ) { } - - public execute() { - this.lazyClientHost().reloadProjects(); - } -} - -export class ReloadJavaScriptProjectsCommand implements Command { - public readonly id = 'javascript.reloadProjects'; - - public constructor( - private readonly lazyClientHost: () => TypeScriptServiceClientHost - ) { } - - public execute() { - this.lazyClientHost().reloadProjects(); - } -} - -export class SelectTypeScriptVersionCommand implements Command { - public readonly id = 'typescript.selectTypeScriptVersion'; - - public constructor( - private readonly lazyClientHost: () => TypeScriptServiceClientHost - ) { } - - public execute() { - this.lazyClientHost().serviceClient.onVersionStatusClicked(); - } -} - -export class OpenTsServerLogCommand implements Command { - public readonly id = 'typescript.openTsServerLog'; - - public constructor( - private readonly lazyClientHost: () => TypeScriptServiceClientHost - ) { } - - public execute() { - this.lazyClientHost().serviceClient.openTsServerLogFile(); - } -} - -export class RestartTsServerCommand implements Command { - public readonly id = 'typescript.restartTsServer'; - - public constructor( - private readonly lazyClientHost: () => TypeScriptServiceClientHost - ) { } - - public execute() { - this.lazyClientHost().serviceClient.restartTsServer(); - } -} - -export class TypeScriptGoToProjectConfigCommand implements Command { - public readonly id = 'typescript.goToProjectConfig'; - - public constructor( - private readonly lazyClientHost: () => TypeScriptServiceClientHost, - ) { } - - public execute() { - const editor = window.activeTextEditor; - if (editor) { - this.lazyClientHost().goToProjectConfig(true, editor.document.uri); - } - } -} - -export class JavaScriptGoToProjectConfigCommand implements Command { - public readonly id = 'javascript.goToProjectConfig'; - - public constructor( - private readonly lazyClientHost: () => TypeScriptServiceClientHost, - ) { } - - public execute() { - const editor = window.activeTextEditor; - if (editor) { - this.lazyClientHost().goToProjectConfig(false, editor.document.uri); - } - } -} - const validateSetting = 'validate.enable'; class LanguageProvider {