@@ -13,7 +13,7 @@ import {promisify} from 'util';
13
13
import * as lsp from 'vscode-languageserver/node' ;
14
14
15
15
import { ServerOptions } from '../common/initialize' ;
16
- import { ProjectLanguageService , ProjectLoadingFinish , ProjectLoadingStart , SuggestIvyLanguageService , SuggestStrictMode } from '../common/notifications' ;
16
+ import { ProjectLanguageService , ProjectLoadingFinish , ProjectLoadingStart , SuggestStrictMode } from '../common/notifications' ;
17
17
import { NgccProgressToken , NgccProgressType } from '../common/progress' ;
18
18
import { GetComponentsWithTemplateFile , GetTcbParams , GetTcbRequest , GetTcbResponse , IsInAngularProject , IsInAngularProjectParams } from '../common/requests' ;
19
19
@@ -22,7 +22,6 @@ import {tsDiagnosticToLspDiagnostic} from './diagnostic';
22
22
import { resolveAndRunNgcc } from './ngcc' ;
23
23
import { ServerHost } from './server_host' ;
24
24
import { filePathToUri , isConfiguredProject , isDebugMode , lspPositionToTsPosition , lspRangeToTsPositions , MruTracker , tsDisplayPartsToText , tsTextSpanToLspRange , uriToFilePath } from './utils' ;
25
- import { resolve , Version } from './version_provider' ;
26
25
27
26
export interface SessionOptions {
28
27
host : ServerHost ;
@@ -50,7 +49,6 @@ export class Session {
50
49
private readonly connection : lsp . Connection ;
51
50
private readonly projectService : ts . server . ProjectService ;
52
51
private readonly logger : ts . server . Logger ;
53
- private readonly angularCoreVersionMap = new WeakMap < ts . server . Project , Version > ( ) ;
54
52
private readonly ivy : boolean ;
55
53
private readonly configuredProjToExternalProj = new Map < string , string > ( ) ;
56
54
private readonly logToConsole : boolean ;
@@ -322,7 +320,7 @@ export class Session {
322
320
return params ;
323
321
}
324
322
325
- private enableLanguageServiceForProject ( project : ts . server . Project , angularCore : string ) {
323
+ private enableLanguageServiceForProject ( project : ts . server . Project ) {
326
324
const { projectName} = project ;
327
325
if ( ! project . languageServiceEnabled ) {
328
326
project . enableLanguageService ( ) ;
@@ -335,7 +333,6 @@ export class Session {
335
333
if ( ! this . ivy ) {
336
334
// Immediately enable Legacy / View Engine language service
337
335
this . info ( `Enabling View Engine language service for ${ projectName } .` ) ;
338
- this . promptToEnableIvyIfAvailable ( project , angularCore ) ;
339
336
return ;
340
337
}
341
338
this . info ( `Enabling Ivy language service for ${ projectName } .` ) ;
@@ -346,6 +343,15 @@ export class Session {
346
343
this . runGlobalAnalysisForNewlyLoadedProject ( project ) ;
347
344
}
348
345
346
+ private disableLanguageServiceForProject ( project : ts . server . Project , reason : string ) {
347
+ if ( ! project . languageServiceEnabled ) {
348
+ return ;
349
+ }
350
+ project . disableLanguageService (
351
+ `Disabling language service for ${ project . projectName } because ${ reason } .` ) ;
352
+ }
353
+
354
+
349
355
/**
350
356
* Invoke the compiler for the first time so that external templates get
351
357
* matched to the project they belong to.
@@ -405,14 +411,17 @@ export class Session {
405
411
this . connection . sendNotification ( ProjectLoadingFinish ) ;
406
412
}
407
413
const { project} = event . data ;
408
- const angularCore = this . findAngularCoreOrDisableLanguageService ( project ) ;
414
+ const angularCore = this . findAngularCore ( project ) ;
409
415
if ( angularCore ) {
410
416
if ( this . ivy && isExternalAngularCore ( angularCore ) ) {
411
417
// Do not wait on this promise otherwise we'll be blocking other requests
412
- this . runNgcc ( project , angularCore ) ;
418
+ this . runNgcc ( project ) ;
413
419
} else {
414
- this . enableLanguageServiceForProject ( project , angularCore ) ;
420
+ this . enableLanguageServiceForProject ( project ) ;
415
421
}
422
+ } else {
423
+ this . disableLanguageServiceForProject (
424
+ project , `project is not an Angular project ('@angular/core' could not be found)` ) ;
416
425
}
417
426
break ;
418
427
}
@@ -1051,12 +1060,11 @@ export class Session {
1051
1060
1052
1061
/**
1053
1062
* Find the main declaration file for `@angular/core` in the specified
1054
- * `project`. If found, return the declaration file. Otherwise, disable the
1055
- * language service and return undefined.
1063
+ * `project`.
1056
1064
*
1057
1065
* @returns main declaration file in `@angular/core`.
1058
1066
*/
1059
- private findAngularCoreOrDisableLanguageService ( project : ts . server . Project ) : string | undefined {
1067
+ private findAngularCore ( project : ts . server . Project ) : string | undefined {
1060
1068
const { projectName} = project ;
1061
1069
if ( ! project . languageServiceEnabled ) {
1062
1070
this . info (
@@ -1070,28 +1078,22 @@ export class Session {
1070
1078
return undefined ;
1071
1079
}
1072
1080
const angularCore = project . getFileNames ( ) . find ( isAngularCore ) ;
1073
- if ( angularCore === undefined ) {
1074
- project . disableLanguageService ( ) ;
1081
+ if ( angularCore === undefined && project . getExcludedFiles ( ) . some ( isAngularCore ) ) {
1075
1082
this . info (
1076
- `Disabling language service for ${ projectName } because it is not an Angular project ` +
1077
- `('@angular/core' could not be found).` ) ;
1078
- if ( project . getExcludedFiles ( ) . some ( isAngularCore ) ) {
1079
- this . info (
1080
- `Please check your tsconfig.json to make sure 'node_modules' directory is not excluded.` ) ;
1081
- }
1083
+ `Please check your tsconfig.json to make sure 'node_modules' directory is not excluded.` ) ;
1082
1084
}
1083
1085
return angularCore ;
1084
1086
}
1085
1087
1086
1088
/**
1087
1089
* Disable the language service, run ngcc, then re-enable language service.
1088
1090
*/
1089
- private async runNgcc ( project : ts . server . Project , angularCore : string ) : Promise < void > {
1091
+ private async runNgcc ( project : ts . server . Project ) : Promise < void > {
1090
1092
if ( ! isConfiguredProject ( project ) ) {
1091
1093
return ;
1092
1094
}
1093
1095
// Disable language service until ngcc is completed.
1094
- project . disableLanguageService ( ) ;
1096
+ this . disableLanguageServiceForProject ( project , 'ngcc is running' ) ;
1095
1097
const configFilePath = project . getConfigFilePath ( ) ;
1096
1098
1097
1099
this . connection . sendProgress ( NgccProgressType , NgccProgressToken , {
@@ -1131,21 +1133,7 @@ export class Session {
1131
1133
// disabled, there's no way users could use the extension even after
1132
1134
// resolving ngcc issues. On the client side, we will warn users about
1133
1135
// potentially degraded experience.
1134
- this . enableLanguageServiceForProject ( project , angularCore ) ;
1135
- }
1136
-
1137
- private promptToEnableIvyIfAvailable ( project : ts . server . Project , coreDts : string ) : void {
1138
- let angularCoreVersion = this . angularCoreVersionMap . get ( project ) ;
1139
- if ( angularCoreVersion === undefined ) {
1140
- angularCoreVersion = resolve ( '@angular/core' , coreDts ) ?. version ;
1141
- }
1142
-
1143
- if ( angularCoreVersion !== undefined && ! this . ivy && angularCoreVersion . major >= 9 ) {
1144
- this . connection . sendNotification ( SuggestIvyLanguageService , {
1145
- message :
1146
- 'Would you like to enable the new Ivy-native language service to get the latest features and bug fixes?' ,
1147
- } ) ;
1148
- }
1136
+ this . enableLanguageServiceForProject ( project ) ;
1149
1137
}
1150
1138
}
1151
1139
0 commit comments