@@ -19,6 +19,12 @@ namespace ts.server {
1919 }
2020 }
2121
22+ const jsOrDts = [ ".js" , ".d.ts" ] ;
23+
24+ export function allFilesAreJsOrDts ( project : Project ) : boolean {
25+ return project . getFileNames ( ) . every ( f => fileExtensionIsAny ( f , jsOrDts ) ) ;
26+ }
27+
2228 export abstract class Project {
2329 private rootFiles : ScriptInfo [ ] = [ ] ;
2430 private rootFilesMap : FileMap < ScriptInfo > = createFileMap < ScriptInfo > ( ) ;
@@ -103,6 +109,7 @@ namespace ts.server {
103109 }
104110
105111 abstract getProjectName ( ) : string ;
112+ abstract getTypingOptions ( ) : TypingOptions ;
106113
107114 close ( ) {
108115 if ( this . program ) {
@@ -414,6 +421,14 @@ namespace ts.server {
414421 this . projectService . stopWatchingDirectory ( directory ) ;
415422 }
416423 }
424+
425+ getTypingOptions ( ) : TypingOptions {
426+ return {
427+ enableAutoDiscovery : allFilesAreJsOrDts ( this ) ,
428+ include : [ ] ,
429+ exclude : [ ]
430+ } ;
431+ }
417432 }
418433
419434 export class ConfiguredProject extends Project {
@@ -434,6 +449,10 @@ namespace ts.server {
434449 super ( ProjectKind . Configured , projectService , documentRegistry , hasExplicitListOfFiles , languageServiceEnabled , compilerOptions ) ;
435450 }
436451
452+ setTypingOptions ( newTypingOptions : TypingOptions ) : void {
453+ this . typingOptions = newTypingOptions ;
454+ }
455+
437456 getTypingOptions ( ) {
438457 return this . typingOptions ;
439458 }
@@ -508,12 +527,43 @@ namespace ts.server {
508527 }
509528
510529 export class ExternalProject extends Project {
530+ private typingOptions : TypingOptions ;
511531 constructor ( readonly externalProjectName : string ,
512532 projectService : ProjectService ,
513533 documentRegistry : ts . DocumentRegistry ,
514534 compilerOptions : CompilerOptions ,
535+ typingOptions : TypingOptions ,
515536 languageServiceEnabled : boolean ) {
516537 super ( ProjectKind . External , projectService , documentRegistry , /*hasExplicitListOfFiles*/ true , languageServiceEnabled , compilerOptions ) ;
538+ this . setTypingOptions ( typingOptions ) ;
539+ }
540+
541+ getTypingOptions ( ) {
542+ return this . typingOptions ;
543+ }
544+
545+ setTypingOptions ( newTypingOptions : TypingOptions ) : void {
546+ if ( ! newTypingOptions ) {
547+ // set default typings options
548+ newTypingOptions = {
549+ enableAutoDiscovery : allFilesAreJsOrDts ( this ) ,
550+ include : [ ] ,
551+ exclude : [ ]
552+ } ;
553+ }
554+ else {
555+ if ( newTypingOptions . enableAutoDiscovery === undefined ) {
556+ // if autoDiscovery was not specified by the caller - set it based on the content of the project
557+ newTypingOptions . enableAutoDiscovery = allFilesAreJsOrDts ( this ) ;
558+ }
559+ if ( ! newTypingOptions . include ) {
560+ newTypingOptions . include = [ ] ;
561+ }
562+ if ( ! newTypingOptions . exclude ) {
563+ newTypingOptions . exclude = [ ] ;
564+ }
565+ }
566+ this . typingOptions = newTypingOptions ;
517567 }
518568
519569 getProjectName ( ) {
0 commit comments