@@ -251,17 +251,18 @@ namespace ts.server {
251251 return < any > protocolOptions ;
252252 }
253253
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 ] ;
259259 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 = [ ] ) ) ;
263264 } ) ;
264- return result ;
265+ return watchOptions && { watchOptions , errors } ;
265266 }
266267
267268 export function tryConvertScriptKindName ( scriptKindName : protocol . ScriptKindName | ScriptKind ) : ScriptKind {
@@ -560,6 +561,11 @@ namespace ts.server {
560561 changes : Iterator < TextChange > ;
561562 }
562563
564+ export interface WatchOptionsAndErrors {
565+ watchOptions : WatchOptions ;
566+ errors : Diagnostic [ ] | undefined ;
567+ }
568+
563569 export class ProjectService {
564570
565571 /*@internal */
@@ -616,8 +622,8 @@ namespace ts.server {
616622
617623 private compilerOptionsForInferredProjects : CompilerOptions | undefined ;
618624 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 > ( ) ;
621627 /**
622628 * Project size for configured or external projects
623629 */
@@ -949,7 +955,7 @@ namespace ts.server {
949955 Debug . assert ( projectRootPath === undefined || this . useInferredProjectPerProjectRoot , "Setting compiler options per project root path is only supported when useInferredProjectPerProjectRoot is enabled" ) ;
950956
951957 const compilerOptions = convertCompilerOptions ( projectCompilerOptions ) ;
952- const watchOptions = convertWatchOptions ( projectCompilerOptions ) ;
958+ const watchOptions = convertWatchOptions ( projectCompilerOptions , projectRootPath ) ;
953959
954960 // always set 'allowNonTsExtensions' for inferred projects since user cannot configure it from the outside
955961 // 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 {
977983 project . projectRootPath === canonicalProjectRootPath :
978984 ! project . projectRootPath || ! this . compilerOptionsForInferredProjectsPerProjectRoot . has ( project . projectRootPath ) ) {
979985 project . setCompilerOptions ( compilerOptions ) ;
980- project . setWatchOptions ( watchOptions ) ;
986+ project . setWatchOptions ( watchOptions ?. watchOptions ) ;
987+ project . setProjectErrors ( watchOptions ?. errors ) ;
981988 project . compileOnSaveEnabled = compilerOptions . compileOnSave ! ;
982989 project . markAsDirty ( ) ;
983990 this . delayUpdateProjectGraph ( project ) ;
@@ -1860,7 +1867,7 @@ namespace ts.server {
18601867
18611868 private createExternalProject ( projectFileName : string , files : protocol . ExternalFile [ ] , options : protocol . ExternalProjectCompilerOptions , typeAcquisition : TypeAcquisition , excludedFiles : NormalizedPath [ ] ) {
18621869 const compilerOptions = convertCompilerOptions ( options ) ;
1863- const watchOptions = convertWatchOptions ( options ) ;
1870+ const watchOptionsAndErrors = convertWatchOptions ( options , getDirectoryPath ( normalizeSlashes ( projectFileName ) ) ) ;
18641871 const project = new ExternalProject (
18651872 projectFileName ,
18661873 this ,
@@ -1870,8 +1877,9 @@ namespace ts.server {
18701877 options . compileOnSave === undefined ? true : options . compileOnSave ,
18711878 /*projectFilePath*/ undefined ,
18721879 this . currentPluginConfigOverrides ,
1873- watchOptions
1880+ watchOptionsAndErrors ?. watchOptions
18741881 ) ;
1882+ project . setProjectErrors ( watchOptionsAndErrors ?. errors ) ;
18751883 project . excludedFiles = excludedFiles ;
18761884
18771885 this . addFilesToNonInferredProject ( project , files , externalFilePropertyReader , typeAcquisition ) ;
@@ -2246,14 +2254,16 @@ namespace ts.server {
22462254
22472255 private createInferredProject ( currentDirectory : string | undefined , isSingleInferredProject ?: boolean , projectRootPath ?: NormalizedPath ) : InferredProject {
22482256 const compilerOptions = projectRootPath && this . compilerOptionsForInferredProjectsPerProjectRoot . get ( projectRootPath ) || this . compilerOptionsForInferredProjects ! ; // TODO: GH#18217
2249- let watchOptions : WatchOptions | false | undefined ;
2257+ let watchOptionsAndErrors : WatchOptionsAndErrors | false | undefined ;
22502258 if ( projectRootPath ) {
2251- watchOptions = this . watchOptionsForInferredProjectsPerProjectRoot . get ( projectRootPath ) ;
2259+ watchOptionsAndErrors = this . watchOptionsForInferredProjectsPerProjectRoot . get ( projectRootPath ) ;
22522260 }
2253- if ( watchOptions === undefined ) {
2254- watchOptions = this . watchOptionsForInferredProjects ;
2261+ if ( watchOptionsAndErrors === undefined ) {
2262+ watchOptionsAndErrors = this . watchOptionsForInferredProjects ;
22552263 }
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 ) ;
22572267 if ( isSingleInferredProject ) {
22582268 this . inferredProjects . unshift ( project ) ;
22592269 }
@@ -2705,7 +2715,7 @@ namespace ts.server {
27052715 }
27062716
27072717 if ( args . watchOptions ) {
2708- this . hostConfiguration . watchOptions = convertWatchOptions ( args . watchOptions ) ;
2718+ this . hostConfiguration . watchOptions = convertWatchOptions ( args . watchOptions ) ?. watchOptions ;
27092719 this . logger . info ( `Host watch options changed to ${ JSON . stringify ( this . hostConfiguration . watchOptions ) } , it will be take effect for next watches.` ) ;
27102720 }
27112721 }
@@ -3579,17 +3589,18 @@ namespace ts.server {
35793589 externalProject . excludedFiles = excludedFiles ;
35803590 if ( ! tsConfigFiles ) {
35813591 const compilerOptions = convertCompilerOptions ( proj . options ) ;
3582- const watchOptions = convertWatchOptions ( proj . options ) ;
3592+ const watchOptionsAndErrors = convertWatchOptions ( proj . options , externalProject . getCurrentDirectory ( ) ) ;
35833593 const lastFileExceededProgramSize = this . getFilenameForExceededTotalSizeLimitForNonTsFiles ( proj . projectFileName , compilerOptions , proj . rootFiles , externalFilePropertyReader ) ;
35843594 if ( lastFileExceededProgramSize ) {
35853595 externalProject . disableLanguageService ( lastFileExceededProgramSize ) ;
35863596 }
35873597 else {
35883598 externalProject . enableLanguageService ( ) ;
35893599 }
3600+ externalProject . setProjectErrors ( watchOptionsAndErrors ?. errors ) ;
35903601 // external project already exists and not config files were added - update the project and return;
35913602 // 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 ) ;
35933604 externalProject . updateGraph ( ) ;
35943605 return ;
35953606 }
0 commit comments