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
bug: Go to definition doesn't work on the second component in a single file #55223
bug: Go to definition doesn't work on the second component in a single file #55223
Comments
This appears to have been broken by angular/vscode-ng-language-service@bd6282e. @ivanwonder If you have and time, would you be able to take a look at this? I clearly don't understand the tokenizer and can't look into it more anytime soon. |
…terpolation (angular#1922)" This reverts commit bd6282e. fixes angular/angular#55223
…terpolation (#1922)" (#2023) This reverts commit bd6282e. fixes angular/angular#55223
…terpolation (#1922)" (#2023) This reverts commit bd6282e. fixes angular/angular#55223 (cherry picked from commit 51d907e)
OK, I'll take a look. |
@ivanwonder Thank you! We don't necessarily need the whole implementation that TypeScript has for this because we don't care about tokenizing all the parts correctly. All we really need to know is where the start and end is of the string. But maybe the easiest way to do that is just tokenizing the whole thing correctly by copying the TS code. |
Yes, the tokenizer is complex, and I also can't fully understand it, and make sure this will work for us.
The token is
We need to call the
This includes an object
I think this is what the I have an idea about the original problem, I guess which is the diagnostics can be quite expensive. In the typescript the type checker can be interrupted. // Cancellation that controls whether or not we can cancel in the middle of type checking.
// In general cancelling is *not* safe for the type checker. We might be in the middle of
// computing something, and we will leave our internals in an inconsistent state. Callers
// who set the cancellation token should catch if a cancellation exception occurs, and
// should throw away and create a new TypeChecker.
//
// Currently we only support setting the cancellation token when getting diagnostics. This
// is because diagnostics can be quite expensive, and we want to allow hosts to bail out if
// they no longer need the information (for example, if the user started editing again).
var cancellationToken: CancellationToken | undefined; function runWithCancellationToken<T>(func: () => T): T {
try {
return func();
}
catch (e) {
if (e instanceof OperationCanceledException) {
// We were canceled while performing the operation. Because our type checker
// might be a bad state, we need to throw it away.
typeChecker = undefined!;
}
throw e;
}
} This copy is from here. https://github.com/microsoft/TypeScript/blob/806d7340472082e5ff6d844ecdb70a4b5165e8c5/src/compiler/checker.ts#L1435 Maybe we can evaluate this option, and try to throw an error in the template type checker and catch the error in the |
Yea, this is probably the direction we should go at this point (creating a temporary source file). We can copy the same code used on the server side here: angular/packages/language-service/src/language_service.ts Lines 604 to 621 in 75a186e
|
I have opened an PR for this. You can take a look. I add more explanations in this PR. |
Which @angular/* package(s) are the source of the bug?
language-service
Is this a regression?
Yes
Description
Let's say we have two components in the same file:
Go to definition
forapp-navbar
works correctly (it sends you to the NavbarComponent)Go to definition
forapp-navbar
doesn't work (it says no definition found) (same thing forrouter-outlet
)Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
No response
The text was updated successfully, but these errors were encountered: