@@ -505,7 +505,7 @@ namespace ts.server {
505505 }
506506
507507 private getProjectInfoWorker ( uncheckedFileName : string , projectFileName : string , needFileNameList : boolean ) {
508- const { file, project } = this . getFileAndProjectWorker ( uncheckedFileName , projectFileName , /*errorOnMissingProject*/ true ) ;
508+ const { file, project } = this . getFileAndProjectWorker ( uncheckedFileName , projectFileName , /*refreshInferredProjects*/ true , /* errorOnMissingProject*/ true ) ;
509509 const projectInfo = {
510510 configFileName : project . getProjectName ( ) ,
511511 languageServiceDisabled : ! project . languageServiceEnabled ,
@@ -730,20 +730,24 @@ namespace ts.server {
730730 }
731731
732732 private getFileAndProject ( args : protocol . FileRequestArgs , errorOnMissingProject = true ) {
733- return this . getFileAndProjectWorker ( args . file , args . projectFileName , errorOnMissingProject ) ;
733+ return this . getFileAndProjectWorker ( args . file , args . projectFileName , /*refreshInferredProjects*/ true , errorOnMissingProject ) ;
734734 }
735735
736- private getFileAndProjectWorker ( uncheckedFileName : string , projectFileName : string , errorOnMissingProject : boolean ) {
736+ private getFileAndProjectWithoutRefreshingInferredProjects ( args : protocol . FileRequestArgs , errorOnMissingProject = true ) {
737+ return this . getFileAndProjectWorker ( args . file , args . projectFileName , /*refreshInferredProjects*/ false , errorOnMissingProject ) ;
738+ }
739+
740+ private getFileAndProjectWorker ( uncheckedFileName : string , projectFileName : string , refreshInferredProjects : boolean , errorOnMissingProject : boolean ) {
737741 const file = toNormalizedPath ( uncheckedFileName ) ;
738- const project : Project = this . getProject ( projectFileName ) || this . projectService . getDefaultProjectForFile ( file ) ;
742+ const project : Project = this . getProject ( projectFileName ) || this . projectService . getDefaultProjectForFile ( file , refreshInferredProjects ) ;
739743 if ( ! project && errorOnMissingProject ) {
740744 throw Errors . NoProject ;
741745 }
742746 return { file, project } ;
743747 }
744748
745749 private getOutliningSpans ( args : protocol . FileRequestArgs ) {
746- const { file, project } = this . getFileAndProject ( args ) ;
750+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
747751 return project . languageService . getOutliningSpans ( file ) ;
748752 }
749753
@@ -753,34 +757,34 @@ namespace ts.server {
753757 }
754758
755759 private getDocCommentTemplate ( args : protocol . FileLocationRequestArgs ) {
756- const { file, project } = this . getFileAndProject ( args ) ;
760+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
757761 const scriptInfo = project . getScriptInfoForNormalizedPath ( file ) ;
758762 const position = this . getPosition ( args , scriptInfo ) ;
759763 return project . languageService . getDocCommentTemplateAtPosition ( file , position ) ;
760764 }
761765
762766 private getIndentation ( args : protocol . IndentationRequestArgs ) {
763- const { file, project } = this . getFileAndProject ( args ) ;
767+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
764768 const position = this . getPosition ( args , project . getScriptInfoForNormalizedPath ( file ) ) ;
765769 const options = args . options || this . projectService . getFormatCodeOptions ( file ) ;
766770 const indentation = project . languageService . getIndentationAtPosition ( file , position , options ) ;
767771 return { position, indentation } ;
768772 }
769773
770774 private getBreakpointStatement ( args : protocol . FileLocationRequestArgs ) {
771- const { file, project } = this . getFileAndProject ( args ) ;
775+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
772776 const position = this . getPosition ( args , project . getScriptInfoForNormalizedPath ( file ) ) ;
773777 return project . languageService . getBreakpointStatementAtPosition ( file , position ) ;
774778 }
775779
776780 private getNameOrDottedNameSpan ( args : protocol . FileLocationRequestArgs ) {
777- const { file, project } = this . getFileAndProject ( args ) ;
781+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
778782 const position = this . getPosition ( args , project . getScriptInfoForNormalizedPath ( file ) ) ;
779783 return project . languageService . getNameOrDottedNameSpan ( file , position , position ) ;
780784 }
781785
782786 private isValidBraceCompletion ( args : protocol . BraceCompletionRequestArgs ) {
783- const { file, project } = this . getFileAndProject ( args ) ;
787+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
784788 const position = this . getPosition ( args , project . getScriptInfoForNormalizedPath ( file ) ) ;
785789 return project . languageService . isValidBraceCompletionAtPosition ( file , position , args . openingBrace . charCodeAt ( 0 ) ) ;
786790 }
@@ -811,7 +815,7 @@ namespace ts.server {
811815 }
812816
813817 private getFormattingEditsForRange ( args : protocol . FormatRequestArgs ) : protocol . CodeEdit [ ] {
814- const { file, project } = this . getFileAndProject ( args ) ;
818+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
815819 const scriptInfo = project . getScriptInfoForNormalizedPath ( file ) ;
816820
817821 const startPosition = scriptInfo . lineOffsetToPosition ( args . line , args . offset ) ;
@@ -834,25 +838,25 @@ namespace ts.server {
834838 }
835839
836840 private getFormattingEditsForRangeFull ( args : protocol . FormatRequestArgs ) {
837- const { file, project } = this . getFileAndProject ( args ) ;
841+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
838842 const options = args . options || this . projectService . getFormatCodeOptions ( file ) ;
839843 return project . languageService . getFormattingEditsForRange ( file , args . position , args . endPosition , options ) ;
840844 }
841845
842846 private getFormattingEditsForDocumentFull ( args : protocol . FormatRequestArgs ) {
843- const { file, project } = this . getFileAndProject ( args ) ;
847+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
844848 const options = args . options || this . projectService . getFormatCodeOptions ( file ) ;
845849 return project . languageService . getFormattingEditsForDocument ( file , options ) ;
846850 }
847851
848852 private getFormattingEditsAfterKeystrokeFull ( args : protocol . FormatOnKeyRequestArgs ) {
849- const { file, project } = this . getFileAndProject ( args ) ;
853+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
850854 const options = args . options || this . projectService . getFormatCodeOptions ( file ) ;
851855 return project . languageService . getFormattingEditsAfterKeystroke ( file , args . position , args . key , options ) ;
852856 }
853857
854858 private getFormattingEditsAfterKeystroke ( args : protocol . FormatOnKeyRequestArgs ) : protocol . CodeEdit [ ] {
855- const { file, project } = this . getFileAndProject ( args ) ;
859+ const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
856860 const scriptInfo = project . getScriptInfoForNormalizedPath ( file ) ;
857861 const position = scriptInfo . lineOffsetToPosition ( args . line , args . offset ) ;
858862 const formatOptions = this . projectService . getFormatCodeOptions ( file ) ;
@@ -976,7 +980,7 @@ namespace ts.server {
976980 private getDiagnostics ( delay : number , fileNames : string [ ] ) {
977981 const checkList = fileNames . reduce ( ( accum : PendingErrorCheck [ ] , uncheckedFileName : string ) => {
978982 const fileName = toNormalizedPath ( uncheckedFileName ) ;
979- const project = this . projectService . getDefaultProjectForFile ( fileName ) ;
983+ const project = this . projectService . getDefaultProjectForFile ( fileName , /*refreshInferredProjects*/ true ) ;
980984 if ( project ) {
981985 accum . push ( { fileName, project } ) ;
982986 }
@@ -1004,7 +1008,7 @@ namespace ts.server {
10041008
10051009 private reload ( args : protocol . ReloadRequestArgs , reqSeq : number ) {
10061010 const file = toNormalizedPath ( args . file ) ;
1007- const project = this . projectService . getDefaultProjectForFile ( file ) ;
1011+ const project = this . projectService . getDefaultProjectForFile ( file , /*refreshInferredProjects*/ true ) ;
10081012 if ( project ) {
10091013 this . changeSeq ++ ;
10101014 // make sure no changes happen before this one is finished
@@ -1177,7 +1181,7 @@ namespace ts.server {
11771181 const lowPriorityFiles : NormalizedPath [ ] = [ ] ;
11781182 const veryLowPriorityFiles : NormalizedPath [ ] = [ ] ;
11791183 const normalizedFileName = toNormalizedPath ( fileName ) ;
1180- const project = this . projectService . getDefaultProjectForFile ( normalizedFileName ) ;
1184+ const project = this . projectService . getDefaultProjectForFile ( normalizedFileName , /*refreshInferredProjects*/ true ) ;
11811185 for ( const fileNameInProject of fileNamesInProject ) {
11821186 if ( this . getCanonicalFileName ( fileNameInProject ) == this . getCanonicalFileName ( fileName ) )
11831187 highPriorityFiles . push ( fileNameInProject ) ;
0 commit comments