This repository was archived by the owner on Nov 21, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +33
-16
lines changed Expand file tree Collapse file tree 3 files changed +33
-16
lines changed Original file line number Diff line number Diff line change @@ -134,12 +134,28 @@ export class AngularLanguageClient implements vscode.Disposable {
134134 }
135135
136136 private async isInAngularProject ( doc : vscode . TextDocument ) : Promise < boolean > {
137- // TODO(#1330): The logic below has been found to have some race conditions. It appears that
138- // when trying to do operations in an external while the language service is still initializing
139- // will result in this function determining that the file is not in an Angular project.
140- // We should disable this check (by always returning assuming the document is inside an Angular
141- // project) until a solution is found.
142- return true ;
137+ if ( this . client === null ) {
138+ return false ;
139+ }
140+ const uri = doc . uri . toString ( ) ;
141+ if ( this . fileToIsInAngularProjectMap . has ( uri ) ) {
142+ return this . fileToIsInAngularProjectMap . get ( uri ) ! ;
143+ }
144+
145+ try {
146+ const response = await this . client . sendRequest ( IsInAngularProject , {
147+ textDocument : this . client . code2ProtocolConverter . asTextDocumentIdentifier ( doc ) ,
148+ } ) ;
149+ if ( response === undefined ) {
150+ // If the response indicates the answer can't be determined at the moment, return `false`
151+ // but do not cache the result so we can try to get the real answer on follow-up requests.
152+ return false ;
153+ }
154+ this . fileToIsInAngularProjectMap . set ( uri , response ) ;
155+ return response ;
156+ } catch {
157+ return false ;
158+ }
143159 }
144160
145161 private createVirtualHtmlDoc ( document : vscode . TextDocument ) : vscode . Uri {
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ export interface GetTcbResponse {
3131}
3232
3333export const IsInAngularProject =
34- new lsp . RequestType < IsInAngularProjectParams , boolean , /* error */ void > (
34+ new lsp . RequestType < IsInAngularProjectParams , boolean | undefined , /* error */ void > (
3535 'angular/isAngularCoreInOwningProject' ) ;
3636
3737export interface IsInAngularProjectParams {
Original file line number Diff line number Diff line change @@ -175,21 +175,22 @@ export class Session {
175175 conn . onSignatureHelp ( p => this . onSignatureHelp ( p ) ) ;
176176 }
177177
178- private isInAngularProject ( params : IsInAngularProjectParams ) : boolean {
178+ private isInAngularProject ( params : IsInAngularProjectParams ) : boolean | undefined {
179179 const filePath = uriToFilePath ( params . textDocument . uri ) ;
180180 if ( ! filePath ) {
181181 return false ;
182182 }
183- const scriptInfo = this . projectService . getScriptInfo ( filePath ) ;
184- if ( ! scriptInfo ) {
185- return false ;
183+ const lsAndScriptInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
184+ if ( ! lsAndScriptInfo ) {
185+ // If we cannot get language service / script info, return undefined to indicate we don't know
186+ // the answer definitively.
187+ return undefined ;
186188 }
187- const project = this . projectService . getDefaultProjectForFile (
188- scriptInfo . fileName ,
189- false // ensureProject
190- ) ;
189+ const project = this . getDefaultProjectForScriptInfo ( lsAndScriptInfo . scriptInfo ) ;
191190 if ( ! project ) {
192- return false ;
191+ // If we cannot get project, return undefined to indicate we don't know
192+ // the answer definitively.
193+ return undefined ;
193194 }
194195 const angularCore = project . getFileNames ( ) . find ( isAngularCore ) ;
195196 return angularCore !== undefined ;
You can’t perform that action at this time.
0 commit comments