@@ -41,13 +41,14 @@ import CodeActionProvider from './features/codeActionProvider';
4141import ReferenceCodeLensProvider from './features/referencesCodeLensProvider' ;
4242import { JsDocCompletionProvider , TryCompleteJsDocCommand } from './features/jsDocCompletionProvider' ;
4343import { DirectiveCommentCompletionProvider } from './features/directiveCommentCompletionProvider' ;
44+ import TypeScriptTaskProvider from './features/taskProvider' ;
4445
4546import ImplementationCodeLensProvider from './features/implementationsCodeLensProvider' ;
4647
4748import * as BuildStatus from './utils/buildStatus' ;
4849import * as ProjectStatus from './utils/projectStatus' ;
4950import TypingsStatus , { AtaProgressReporter } from './utils/typingsStatus' ;
50- import * as VersionStatus from './utils/versionStatus' ;
51+ import VersionStatus from './utils/versionStatus' ;
5152import { getContributedTypeScriptServerPlugins , TypeScriptServerPlugin } from "./utils/plugins" ;
5253
5354interface LanguageDescription {
@@ -67,72 +68,100 @@ interface ProjectConfigMessageItem extends MessageItem {
6768 id : ProjectConfigAction ;
6869}
6970
71+ const MODE_ID_TS = 'typescript' ;
72+ const MODE_ID_TSX = 'typescriptreact' ;
73+ const MODE_ID_JS = 'javascript' ;
74+ const MODE_ID_JSX = 'javascriptreact' ;
75+
76+ const standardLanguageDescriptions : LanguageDescription [ ] = [
77+ {
78+ id : 'typescript' ,
79+ diagnosticSource : 'ts' ,
80+ modeIds : [ MODE_ID_TS , MODE_ID_TSX ] ,
81+ configFile : 'tsconfig.json'
82+ } , {
83+ id : 'javascript' ,
84+ diagnosticSource : 'js' ,
85+ modeIds : [ MODE_ID_JS , MODE_ID_JSX ] ,
86+ configFile : 'jsconfig.json'
87+ }
88+ ] ;
7089
7190export function activate ( context : ExtensionContext ) : void {
72- const MODE_ID_TS = 'typescript' ;
73- const MODE_ID_TSX = 'typescriptreact' ;
74- const MODE_ID_JS = 'javascript' ;
75- const MODE_ID_JSX = 'javascriptreact' ;
76-
7791 const plugins = getContributedTypeScriptServerPlugins ( ) ;
78- const clientHost = new TypeScriptServiceClientHost ( [
79- {
80- id : 'typescript' ,
81- diagnosticSource : 'ts' ,
82- modeIds : [ MODE_ID_TS , MODE_ID_TSX ] ,
83- configFile : 'tsconfig.json'
84- } ,
85- {
86- id : 'javascript' ,
87- diagnosticSource : 'js' ,
88- modeIds : [ MODE_ID_JS , MODE_ID_JSX ] ,
89- configFile : 'jsconfig.json'
90- }
91- ] , context . storagePath , context . globalState , context . workspaceState , plugins ) ;
92- context . subscriptions . push ( clientHost ) ;
9392
94- const client = clientHost . serviceClient ;
93+ const lazyClientHost = ( ( ) => {
94+ let clientHost : TypeScriptServiceClientHost | undefined ;
95+ return ( ) => {
96+ if ( ! clientHost ) {
97+ clientHost = new TypeScriptServiceClientHost ( standardLanguageDescriptions , context . storagePath , context . globalState , context . workspaceState , plugins ) ;
98+ context . subscriptions . push ( clientHost ) ;
99+
100+ const host = clientHost ;
101+ clientHost . serviceClient . onReady ( ) . then ( ( ) => {
102+ context . subscriptions . push ( ProjectStatus . create ( host . serviceClient ,
103+ path => new Promise < boolean > ( resolve => setTimeout ( ( ) => resolve ( host . handles ( path ) ) , 750 ) ) ,
104+ context . workspaceState ) ) ;
105+ } , ( ) => {
106+ // Nothing to do here. The client did show a message;
107+ } ) ;
108+ }
109+ return clientHost ;
110+ } ;
111+ } ) ( ) ;
112+
95113
96114 context . subscriptions . push ( commands . registerCommand ( 'typescript.reloadProjects' , ( ) => {
97- clientHost . reloadProjects ( ) ;
115+ lazyClientHost ( ) . reloadProjects ( ) ;
98116 } ) ) ;
99117
100118 context . subscriptions . push ( commands . registerCommand ( 'javascript.reloadProjects' , ( ) => {
101- clientHost . reloadProjects ( ) ;
119+ lazyClientHost ( ) . reloadProjects ( ) ;
102120 } ) ) ;
103121
104122 context . subscriptions . push ( commands . registerCommand ( 'typescript.selectTypeScriptVersion' , ( ) => {
105- client . onVersionStatusClicked ( ) ;
123+ lazyClientHost ( ) . serviceClient . onVersionStatusClicked ( ) ;
106124 } ) ) ;
107125
108126 context . subscriptions . push ( commands . registerCommand ( 'typescript.openTsServerLog' , ( ) => {
109- client . openTsServerLogFile ( ) ;
127+ lazyClientHost ( ) . serviceClient . openTsServerLogFile ( ) ;
110128 } ) ) ;
111129
112130 context . subscriptions . push ( commands . registerCommand ( 'typescript.restartTsServer' , ( ) => {
113- client . restartTsServer ( ) ;
131+ lazyClientHost ( ) . serviceClient . restartTsServer ( ) ;
114132 } ) ) ;
115133
134+ context . subscriptions . push ( workspace . registerTaskProvider ( new TypeScriptTaskProvider ( ( ) => lazyClientHost ( ) . serviceClient ) ) ) ;
135+
116136 const goToProjectConfig = ( isTypeScript : boolean ) => {
117137 const editor = window . activeTextEditor ;
118138 if ( editor ) {
119- clientHost . goToProjectConfig ( isTypeScript , editor . document . uri ) ;
139+ lazyClientHost ( ) . goToProjectConfig ( isTypeScript , editor . document . uri ) ;
120140 }
121141 } ;
122142 context . subscriptions . push ( commands . registerCommand ( 'typescript.goToProjectConfig' , goToProjectConfig . bind ( null , true ) ) ) ;
123143 context . subscriptions . push ( commands . registerCommand ( 'javascript.goToProjectConfig' , goToProjectConfig . bind ( null , false ) ) ) ;
124144
125- const jsDocCompletionCommand = new TryCompleteJsDocCommand ( client ) ;
145+ const jsDocCompletionCommand = new TryCompleteJsDocCommand ( ( ) => lazyClientHost ( ) . serviceClient ) ;
126146 context . subscriptions . push ( commands . registerCommand ( TryCompleteJsDocCommand . COMMAND_NAME , jsDocCompletionCommand . tryCompleteJsDoc , jsDocCompletionCommand ) ) ;
127147
128- window . onDidChangeActiveTextEditor ( VersionStatus . showHideStatus , null , context . subscriptions ) ;
129- client . onReady ( ) . then ( ( ) => {
130- context . subscriptions . push ( ProjectStatus . create ( client ,
131- path => new Promise < boolean > ( resolve => setTimeout ( ( ) => resolve ( clientHost . handles ( path ) ) , 750 ) ) ,
132- context . workspaceState ) ) ;
133- } , ( ) => {
134- // Nothing to do here. The client did show a message;
135- } ) ;
148+ const supportedLanguage = [ ] . concat . apply ( [ ] , standardLanguageDescriptions . map ( x => x . modeIds ) . concat ( plugins . map ( x => x . languages ) ) ) ;
149+ function didOpenTextDocument ( textDocument : TextDocument ) : boolean {
150+ if ( supportedLanguage . indexOf ( textDocument . languageId ) >= 0 ) {
151+ openListener . dispose ( ) ;
152+ // Force activation
153+ void lazyClientHost ( ) ;
154+ return true ;
155+ }
156+ return false ;
157+ } ;
158+ const openListener = workspace . onDidOpenTextDocument ( didOpenTextDocument ) ;
159+ for ( let textDocument of workspace . textDocuments ) {
160+ if ( didOpenTextDocument ( textDocument ) ) {
161+ break ;
162+ }
163+ }
164+
136165 BuildStatus . update ( { queueLength : 0 } ) ;
137166}
138167
@@ -423,6 +452,7 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
423452 private languages : LanguageProvider [ ] = [ ] ;
424453 private languagePerId : ObjectMap < LanguageProvider > ;
425454 private readonly disposables : Disposable [ ] = [ ] ;
455+ private readonly versionStatus : VersionStatus ;
426456
427457 constructor (
428458 descriptions : LanguageDescription [ ] ,
@@ -446,7 +476,10 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
446476 configFileWatcher . onDidDelete ( handleProjectCreateOrDelete , this , this . disposables ) ;
447477 configFileWatcher . onDidChange ( handleProjectChange , this , this . disposables ) ;
448478
449- this . client = new TypeScriptServiceClient ( this , storagePath , globalState , workspaceState , plugins , this . disposables ) ;
479+ this . versionStatus = new VersionStatus ( ) ;
480+ this . disposables . push ( this . versionStatus ) ;
481+
482+ this . client = new TypeScriptServiceClient ( this , storagePath , globalState , workspaceState , this . versionStatus , plugins , this . disposables ) ;
450483 this . languagePerId = Object . create ( null ) ;
451484 for ( const description of descriptions ) {
452485 const manager = new LanguageProvider ( this . client , description ) ;
0 commit comments