Skip to content

Commit 9ca675a

Browse files
committed
fix: unchanged files sometimes have no Angular information for string… (#1453)
* fix: unchanged files sometimes have no Angular information for strings when first opened The `TextStorage` in TS server calls `useScriptVersionCacheIfValidOrOpen` in many places when dealing with a `ScriptInfo`. One of the conditions in that function is to switch to version _if the script is open_. This change in version results in an identity change for the `SourceFile` which is problematic for the compiler because we store references to string literals for inline templates, template URLs, and style URLs. These references will not be valid if the `SourceFile` changed identity. To ensure that the compiler is aware of the change, we mark the project as dirty when a text document is opened. This will cause the project to call `updateGraph`, determine that the file changed versions, and create a new program. This is done so that the Angular compiler can reprocess the file. This also appears to be one of, if not the only issue, that's currently causing the e2e tests to be flaky. * test: Stabalize e2e tests * Fix test output so that it logs to console. * Disable hover tests because they are flaky. (cherry picked from commit a751e61)
1 parent ae6faba commit 9ca675a

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

integration/e2e/hover_spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import * as vscode from 'vscode';
22

33
import {activate, FOO_TEMPLATE_URI, HOVER_COMMAND} from './helper';
44

5-
describe('Angular Ivy LS quick info', () => {
5+
// This hover tests appear to be the only flaky ones in the suite. Disable until they can
6+
// consistently pass.
7+
xdescribe('Angular Ivy LS quick info', () => {
68
beforeAll(async () => {
79
await activate(FOO_TEMPLATE_URI);
810
});

integration/e2e/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ async function main() {
2424
}
2525
}
2626

27-
main()
27+
main();

integration/e2e/jasmine.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,36 @@ export async function run(): Promise<void> {
99
],
1010
});
1111

12+
// For whatever reason, the built-in jasmine reporter printin does not make it to the console
13+
// output when the tests are run. In addition, allowing the default implementation to call
14+
// `process.exit(1)` messes up the console reporting. The overrides below allow for both the
15+
// proper exit code and the proper console reporting.
16+
let failed = false;
17+
jasmine.configureDefaultReporter({
18+
// The `print` function passed the reporter will be called to print its results.
19+
print: function(message: string) {
20+
if (message.trim()) {
21+
console.log(message);
22+
}
23+
},
24+
});
25+
jasmine.completionReporter = {
26+
specDone: (result: jasmine.SpecResult): void | Promise<void> => {
27+
if (result.failedExpectations.length > 0) {
28+
failed = true;
29+
}
30+
console.log(result);
31+
},
32+
};
33+
1234
console.log(`Expecting to run ${jasmine.specFiles.length} specs.`);
1335

1436
if (jasmine.specFiles.length === 0) {
1537
throw new Error('No specs found');
1638
}
1739

1840
await jasmine.execute();
19-
}
41+
if (failed) {
42+
process.exit(1);
43+
}
44+
}

server/src/session.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,16 @@ export class Session {
638638
return;
639639
}
640640
if (project.languageServiceEnabled) {
641+
// The act of opening a file can cause the text storage to switchToScriptVersionCache for
642+
// version tracking, which results in an identity change for the source file. This isn't
643+
// typically an issue but the identity can change during an update operation for template
644+
// type-checking, when we _only_ expect the typecheck files to change. This _is_ an issue
645+
// because the because template type-checking should not modify the identity of any other
646+
// source files (other than the generated typecheck files). We need to ensure that the
647+
// compiler is aware of this change that shouldn't have happened and recompiles the file
648+
// because we store references to some string expressions (inline templates, style/template
649+
// urls).
650+
project.markAsDirty();
641651
// Show initial diagnostics
642652
this.requestDiagnosticsOnOpenOrChangeFile(filePath, `Opening ${filePath}`);
643653
}

0 commit comments

Comments
 (0)