Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-cli): report non-template diagnostics #40331

Closed
wants to merge 1 commit into from

Conversation

zarend
Copy link
Contributor

@zarend zarend commented Jan 6, 2021

Report non-template diagnostics when calling getDiagnostics function of
the language service we only returned template diagnostics. This change
causes it to return all diagnostics, not just diagnostics from the
template type checker.

Why does this split getDiagnostics into two functions?

A. I split getDiagnostics into two functions. getDiagnostics for getting all diagnostics in the program, and getDiagnosticsForFile, which only gets diagnostics for the argument file. this is because it makes the implementation less complicated, and it aligns with our style guide – better to have two functions that do different things than one function that can do both things.

@google-cla google-cla bot added the cla: yes label Jan 6, 2021
@zarend zarend force-pushed the non-template-diagnostics branch 4 times, most recently from 8531795 to 03e2894 Compare January 7, 2021 19:32
@atscott atscott added the area: compiler Issues related to `ngc`, Angular's template compiler label Jan 7, 2021
@ngbot ngbot bot added this to the Backlog milestone Jan 7, 2021
@zarend zarend force-pushed the non-template-diagnostics branch 2 times, most recently from 0fc956b to 697504c Compare January 7, 2021 22:26
@zarend zarend marked this pull request as ready for review January 7, 2021 22:52
@zarend zarend added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jan 7, 2021
@zarend zarend force-pushed the non-template-diagnostics branch 2 times, most recently from 9999842 to 0d22a3c Compare January 12, 2021 17:07
Copy link
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

if (file === undefined) {
return this.compiler.getDiagnostics();
}
return this.compiler.getDiagnosticsForFile(file, OptimizeFor.WholeProgram);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alxhub , I made this use WholeProgram optimization for two reasons.

  1. the previous behavior used WholeProgram, so it's better not to change it unless we have a good reason to
  2. I not sure how this will be used. If someone calls this in a loop one file at a time, we definitely want to use WholeProgram mode

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is absolutely correct :)

@@ -51,7 +51,7 @@ export class LanguageService {
const program = compiler.getNextProgram();
const sourceFile = program.getSourceFile(fileName);
if (sourceFile) {
diagnostics.push(...ttc.getDiagnosticsForFile(sourceFile, OptimizeFor.SingleFile));
diagnostics.push(...compiler.getDiagnosticsForFile(sourceFile, OptimizeFor.SingleFile));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alxhub , I made this use SingleFile optimization because that's what the previous behavior was, and I don't want to give up single file optimization and cause a performance regression.

If we wanted to call this with WholeProgram optimization, we have two options.

  1. manually ensure all shims are built before calling this, that way we use the memoized shims
  2. expose an optimizeFor parameter on this function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct here too :)

Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: language-service

@kyliau kyliau added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 13, 2021
@kyliau kyliau added the area: language-service Issues related to Angular's VS Code language service label Jan 13, 2021
Report non-template diagnotics when calling `getDiagnotics` function of
the language service we only returned template diagnotics. This change
causes it to return all diagnotics, not just diagnostics from the
template type checker.
@zarend zarend added action: presubmit The PR is in need of a google3 presubmit and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Jan 13, 2021
@atscott atscott added the target: minor This PR is targeted for the next minor release label Jan 13, 2021
@zarend
Copy link
Contributor Author

zarend commented Jan 13, 2021

@atscott atscott added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit labels Jan 13, 2021
@atscott atscott closed this in 4db89f4 Jan 13, 2021
clydin pushed a commit to angular/angular-cli that referenced this pull request Jan 14, 2021
…gnostics`

With this change we replace `getDiagnostics` with `getDiagnosticsForFile`. `getDiagnostics` no longer accept a parameter and is intended to be used instead of `getDiagnostics`.

I used `OptimizeFor.WholeProgram` based on the comments in angular/angular#40331 (comment) which suggests that if you iterate through files one at a time the `WholeProgram` flag should be used.

For more context see: angular/angular#40331

(cherry picked from commit 5fdc0a6)
clydin pushed a commit to angular/angular-cli that referenced this pull request Jan 14, 2021
…gnostics`

With this change we replace `getDiagnostics` with `getDiagnosticsForFile`. `getDiagnostics` no longer accept a parameter and is intended to be used instead of `getDiagnostics`.

I used `OptimizeFor.WholeProgram` based on the comments in angular/angular#40331 (comment) which suggests that if you iterate through files one at a time the `WholeProgram` flag should be used.

For more context see: angular/angular#40331
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: language-service Issues related to Angular's VS Code language service cla: yes target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants