-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Only report isDefinition when FAR is triggered on a definition #48566
Conversation
Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @amcasey, @mjbvz, @minestarks for you. Feel free to loop in other consumers/maintainers if necessary |
The new The baseline changes are in their own commit if you want to review around them. The protocol change probably warrants some discussion, since this PR makes a non-optional property optional. I believe that's okay since only a very rigidly coded client will have trouble treating an absent property as falsy. |
can you put some screen shots of how the search use to look and how it looks now in editor for better clarity. |
1 similar comment
can you put some screen shots of how the search use to look and how it looks now in editor for better clarity. |
@DanielRosenwasser huh? Your two gifs are running two different commands 😄 |
Not only are they running different commands, the second one was clearly not exhibiting any of the behaviors @amcasey described. I've posted a new GIF. |
I don’t have a strong opinion on the way |
I actually planned to make a PR to change this in VS Code, but discovered that it's actually in the core and applies to all languages. As I mentioned above, the code actually does extra work to not just jump to the other location, so I assumed it was intentional. We could file a bug, but I suspect there would be muscle memory issues. |
To me there's really 3 things to discuss:
|
Sorry, I've been offline. Thanks for sharing those screenshots, @DanielRosenwasser!
What did you mean by that? I wasn't expecting the CodeLens experience to change at all. |
Oh, I think @DanielRosenwasser might just have been asking where Sorry for not bringing it forward. |
Looks like |
Possibly I'm misunderstanding, but I believe it's the other way around - if you ask on the definition, you get a value for every reference (including the definition); if you ask on a reference, you get nothing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure if there's an issue with the delete
but otherwise this seems reasonable since the property used to be optional anyway. Maybe we can reach out to tide and typescript-language-server to give them a heads up since I see they leverage isDefinition
.
CC @ananthakumaran, @rchl |
I haven't looked at the changes in detail, but it might potentially break the feature introduced by ananthakumaran/tide#56 |
@ananthakumaran In the example in ananthakumaran/tide#56, the search from (1) will still include Also note that the behavior before this PR already had a lot of weird corner cases. For example, if you exported a function in one file and imported it in another, there would be exactly two usages, but each would return |
Thanks for the heads-up Daniel. One place in Neither of those places will have issues with the As far as the behavior change, the discussion here is a bit confusing because it explains in terms of VSCode behavior which then makes it unclear whether change is due to VSCode's logic itself or the protocol change. I wanted to know specifically how this change affects the results returned by the typescript server so checked with similar example as posted before: /*1*/function foo() {}
/*2*/foo();
[
{
"file": "/usr/local/workspace/github/typescript-language-server/src/test.ts",
"start": {
"line": 1,
"offset": 15
},
"end": {
"line": 1,
"offset": 18
},
"contextStart": {
"line": 1,
"offset": 6
},
"contextEnd": {
"line": 1,
"offset": 23
},
"lineText": "/*1*/function foo() {}",
"isWriteAccess": true,
"isDefinition": true
},
{
"file": "/usr/local/workspace/github/typescript-language-server/src/test.ts",
"start": {
"line": 2,
"offset": 6
},
"end": {
"line": 2,
"offset": 9
},
"lineText": "/*2*/foo();",
"isWriteAccess": false,
"isDefinition": false
}
] While on line (2) returns: [
{
"file": "/usr/local/workspace/github/typescript-language-server/src/test.ts",
"start": {
"line": 1,
"offset": 15
},
"end": {
"line": 1,
"offset": 18
},
"contextStart": {
"line": 1,
"offset": 6
},
"contextEnd": {
"line": 1,
"offset": 23
},
"lineText": "/*1*/function foo() {}",
"isWriteAccess": true
},
{
"file": "/usr/local/workspace/github/typescript-language-server/src/test.ts",
"start": {
"line": 2,
"offset": 6
},
"end": {
"line": 2,
"offset": 9
},
"lineText": "/*2*/foo();",
"isWriteAccess": false
}
] Since by default (in Sublime Text at least) the So in fact the same behavior as shown in the VSCode gifs earlier. If that's the intended new behavior then I'm fine with it too. |
@rchl Sorry for not being clearer. Yes, the expected change in the server response is that the invocation at (2) will no longer include In a perfect world, we'd probably have a separate |
I just tested it against master and the feature still works as earlier. references command from (2) showed all references earlier as well, the user would use goto definition if they want to jump to definition. LGTM |
In practice,
isDefinition
is used to exclude occurrences from the CodeLens references count in VS Code. Rather than try to generalize the meaning to everywhere FAR can be invoked, we stop reportingisDefinition
for any search not triggered from a declaration location.As a bonus, we get to skip a bunch of work.
Caveats:
isDefinition
is also used when there are exactly two references to a symbol to check whether exactly one is the definition (and jump to the other). After this change, no reference will be marked as a definition if the search is triggered from a non-declaration and, consequently, a list of references will be displayed (vs the current behavior of jumping to the beginning of the current token). Given that the editor behavior was specifically not coded as "just go to the other one", I claim that this asymmetry is actually more in line with the editor's intentions.Given that we didn't hear an outcry last time we completely changed the (undocumented) meaning of
isDefinition
, I don't believe other editors depend on the exact behavior.Edit: because an absent property won't "beat" a later, present property, the multi-project logic does need a small tweak.
Edit 2: "last time we completely changed" #45920