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 {
134
134
}
135
135
136
136
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
+ }
143
159
}
144
160
145
161
private createVirtualHtmlDoc ( document : vscode . TextDocument ) : vscode . Uri {
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ export interface GetTcbResponse {
31
31
}
32
32
33
33
export const IsInAngularProject =
34
- new lsp . RequestType < IsInAngularProjectParams , boolean , /* error */ void > (
34
+ new lsp . RequestType < IsInAngularProjectParams , boolean | undefined , /* error */ void > (
35
35
'angular/isAngularCoreInOwningProject' ) ;
36
36
37
37
export interface IsInAngularProjectParams {
Original file line number Diff line number Diff line change @@ -175,21 +175,22 @@ export class Session {
175
175
conn . onSignatureHelp ( p => this . onSignatureHelp ( p ) ) ;
176
176
}
177
177
178
- private isInAngularProject ( params : IsInAngularProjectParams ) : boolean {
178
+ private isInAngularProject ( params : IsInAngularProjectParams ) : boolean | undefined {
179
179
const filePath = uriToFilePath ( params . textDocument . uri ) ;
180
180
if ( ! filePath ) {
181
181
return false ;
182
182
}
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 ;
186
188
}
187
- const project = this . projectService . getDefaultProjectForFile (
188
- scriptInfo . fileName ,
189
- false // ensureProject
190
- ) ;
189
+ const project = this . getDefaultProjectForScriptInfo ( lsAndScriptInfo . scriptInfo ) ;
191
190
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 ;
193
194
}
194
195
const angularCore = project . getFileNames ( ) . find ( isAngularCore ) ;
195
196
return angularCore !== undefined ;
You can’t perform that action at this time.
0 commit comments