@@ -251,17 +251,18 @@ namespace ts.server {
251
251
return < any > protocolOptions ;
252
252
}
253
253
254
- export function convertWatchOptions ( protocolOptions : protocol . ExternalProjectCompilerOptions ) : WatchOptions | undefined {
255
- let result : WatchOptions | undefined ;
256
- debugger ;
257
- watchOptionsConverters . forEach ( ( mappedValues , id ) => {
258
- const propertyValue = protocolOptions [ id ] ;
254
+ export function convertWatchOptions ( protocolOptions : protocol . ExternalProjectCompilerOptions , currentDirectory ?: string ) : WatchOptionsAndErrors | undefined {
255
+ let watchOptions : WatchOptions | undefined ;
256
+ let errors : Diagnostic [ ] | undefined ;
257
+ optionsForWatch . forEach ( option => {
258
+ const propertyValue = protocolOptions [ option . name ] ;
259
259
if ( propertyValue === undefined ) return ;
260
- ( result || ( result = { } ) ) [ id ] = isString ( propertyValue ) ?
261
- mappedValues . get ( propertyValue . toLowerCase ( ) ) :
262
- propertyValue ;
260
+ const mappedValues = watchOptionsConverters . get ( option . name ) ;
261
+ ( watchOptions || ( watchOptions = { } ) ) [ option . name ] = mappedValues ?
262
+ isString ( propertyValue ) ? mappedValues . get ( propertyValue . toLowerCase ( ) ) : propertyValue :
263
+ convertJsonOption ( option , propertyValue , currentDirectory || "" , errors || ( errors = [ ] ) ) ;
263
264
} ) ;
264
- return result ;
265
+ return watchOptions && { watchOptions , errors } ;
265
266
}
266
267
267
268
export function tryConvertScriptKindName ( scriptKindName : protocol . ScriptKindName | ScriptKind ) : ScriptKind {
@@ -560,6 +561,11 @@ namespace ts.server {
560
561
changes : Iterator < TextChange > ;
561
562
}
562
563
564
+ export interface WatchOptionsAndErrors {
565
+ watchOptions : WatchOptions ;
566
+ errors : Diagnostic [ ] | undefined ;
567
+ }
568
+
563
569
export class ProjectService {
564
570
565
571
/*@internal */
@@ -616,8 +622,8 @@ namespace ts.server {
616
622
617
623
private compilerOptionsForInferredProjects : CompilerOptions | undefined ;
618
624
private compilerOptionsForInferredProjectsPerProjectRoot = createMap < CompilerOptions > ( ) ;
619
- private watchOptionsForInferredProjects : WatchOptions | undefined ;
620
- private watchOptionsForInferredProjectsPerProjectRoot = createMap < WatchOptions | false > ( ) ;
625
+ private watchOptionsForInferredProjects : WatchOptionsAndErrors | undefined ;
626
+ private watchOptionsForInferredProjectsPerProjectRoot = createMap < WatchOptionsAndErrors | false > ( ) ;
621
627
/**
622
628
* Project size for configured or external projects
623
629
*/
@@ -949,7 +955,7 @@ namespace ts.server {
949
955
Debug . assert ( projectRootPath === undefined || this . useInferredProjectPerProjectRoot , "Setting compiler options per project root path is only supported when useInferredProjectPerProjectRoot is enabled" ) ;
950
956
951
957
const compilerOptions = convertCompilerOptions ( projectCompilerOptions ) ;
952
- const watchOptions = convertWatchOptions ( projectCompilerOptions ) ;
958
+ const watchOptions = convertWatchOptions ( projectCompilerOptions , projectRootPath ) ;
953
959
954
960
// always set 'allowNonTsExtensions' for inferred projects since user cannot configure it from the outside
955
961
// previously we did not expose a way for user to change these settings and this option was enabled by default
@@ -977,7 +983,8 @@ namespace ts.server {
977
983
project . projectRootPath === canonicalProjectRootPath :
978
984
! project . projectRootPath || ! this . compilerOptionsForInferredProjectsPerProjectRoot . has ( project . projectRootPath ) ) {
979
985
project . setCompilerOptions ( compilerOptions ) ;
980
- project . setWatchOptions ( watchOptions ) ;
986
+ project . setWatchOptions ( watchOptions ?. watchOptions ) ;
987
+ project . setProjectErrors ( watchOptions ?. errors ) ;
981
988
project . compileOnSaveEnabled = compilerOptions . compileOnSave ! ;
982
989
project . markAsDirty ( ) ;
983
990
this . delayUpdateProjectGraph ( project ) ;
@@ -1860,7 +1867,7 @@ namespace ts.server {
1860
1867
1861
1868
private createExternalProject ( projectFileName : string , files : protocol . ExternalFile [ ] , options : protocol . ExternalProjectCompilerOptions , typeAcquisition : TypeAcquisition , excludedFiles : NormalizedPath [ ] ) {
1862
1869
const compilerOptions = convertCompilerOptions ( options ) ;
1863
- const watchOptions = convertWatchOptions ( options ) ;
1870
+ const watchOptionsAndErrors = convertWatchOptions ( options , getDirectoryPath ( normalizeSlashes ( projectFileName ) ) ) ;
1864
1871
const project = new ExternalProject (
1865
1872
projectFileName ,
1866
1873
this ,
@@ -1870,8 +1877,9 @@ namespace ts.server {
1870
1877
options . compileOnSave === undefined ? true : options . compileOnSave ,
1871
1878
/*projectFilePath*/ undefined ,
1872
1879
this . currentPluginConfigOverrides ,
1873
- watchOptions
1880
+ watchOptionsAndErrors ?. watchOptions
1874
1881
) ;
1882
+ project . setProjectErrors ( watchOptionsAndErrors ?. errors ) ;
1875
1883
project . excludedFiles = excludedFiles ;
1876
1884
1877
1885
this . addFilesToNonInferredProject ( project , files , externalFilePropertyReader , typeAcquisition ) ;
@@ -2246,14 +2254,16 @@ namespace ts.server {
2246
2254
2247
2255
private createInferredProject ( currentDirectory : string | undefined , isSingleInferredProject ?: boolean , projectRootPath ?: NormalizedPath ) : InferredProject {
2248
2256
const compilerOptions = projectRootPath && this . compilerOptionsForInferredProjectsPerProjectRoot . get ( projectRootPath ) || this . compilerOptionsForInferredProjects ! ; // TODO: GH#18217
2249
- let watchOptions : WatchOptions | false | undefined ;
2257
+ let watchOptionsAndErrors : WatchOptionsAndErrors | false | undefined ;
2250
2258
if ( projectRootPath ) {
2251
- watchOptions = this . watchOptionsForInferredProjectsPerProjectRoot . get ( projectRootPath ) ;
2259
+ watchOptionsAndErrors = this . watchOptionsForInferredProjectsPerProjectRoot . get ( projectRootPath ) ;
2252
2260
}
2253
- if ( watchOptions === undefined ) {
2254
- watchOptions = this . watchOptionsForInferredProjects ;
2261
+ if ( watchOptionsAndErrors === undefined ) {
2262
+ watchOptionsAndErrors = this . watchOptionsForInferredProjects ;
2255
2263
}
2256
- const project = new InferredProject ( this , this . documentRegistry , compilerOptions , watchOptions || undefined , projectRootPath , currentDirectory , this . currentPluginConfigOverrides ) ;
2264
+ watchOptionsAndErrors = watchOptionsAndErrors || undefined ;
2265
+ const project = new InferredProject ( this , this . documentRegistry , compilerOptions , watchOptionsAndErrors ?. watchOptions , projectRootPath , currentDirectory , this . currentPluginConfigOverrides ) ;
2266
+ project . setProjectErrors ( watchOptionsAndErrors ?. errors ) ;
2257
2267
if ( isSingleInferredProject ) {
2258
2268
this . inferredProjects . unshift ( project ) ;
2259
2269
}
@@ -2705,7 +2715,7 @@ namespace ts.server {
2705
2715
}
2706
2716
2707
2717
if ( args . watchOptions ) {
2708
- this . hostConfiguration . watchOptions = convertWatchOptions ( args . watchOptions ) ;
2718
+ this . hostConfiguration . watchOptions = convertWatchOptions ( args . watchOptions ) ?. watchOptions ;
2709
2719
this . logger . info ( `Host watch options changed to ${ JSON . stringify ( this . hostConfiguration . watchOptions ) } , it will be take effect for next watches.` ) ;
2710
2720
}
2711
2721
}
@@ -3579,17 +3589,18 @@ namespace ts.server {
3579
3589
externalProject . excludedFiles = excludedFiles ;
3580
3590
if ( ! tsConfigFiles ) {
3581
3591
const compilerOptions = convertCompilerOptions ( proj . options ) ;
3582
- const watchOptions = convertWatchOptions ( proj . options ) ;
3592
+ const watchOptionsAndErrors = convertWatchOptions ( proj . options , externalProject . getCurrentDirectory ( ) ) ;
3583
3593
const lastFileExceededProgramSize = this . getFilenameForExceededTotalSizeLimitForNonTsFiles ( proj . projectFileName , compilerOptions , proj . rootFiles , externalFilePropertyReader ) ;
3584
3594
if ( lastFileExceededProgramSize ) {
3585
3595
externalProject . disableLanguageService ( lastFileExceededProgramSize ) ;
3586
3596
}
3587
3597
else {
3588
3598
externalProject . enableLanguageService ( ) ;
3589
3599
}
3600
+ externalProject . setProjectErrors ( watchOptionsAndErrors ?. errors ) ;
3590
3601
// external project already exists and not config files were added - update the project and return;
3591
3602
// The graph update here isnt postponed since any file open operation needs all updated external projects
3592
- this . updateRootAndOptionsOfNonInferredProject ( externalProject , proj . rootFiles , externalFilePropertyReader , compilerOptions , proj . typeAcquisition , proj . options . compileOnSave , watchOptions ) ;
3603
+ this . updateRootAndOptionsOfNonInferredProject ( externalProject , proj . rootFiles , externalFilePropertyReader , compilerOptions , proj . typeAcquisition , proj . options . compileOnSave , watchOptionsAndErrors ?. watchOptions ) ;
3593
3604
externalProject . updateGraph ( ) ;
3594
3605
return ;
3595
3606
}
0 commit comments