Feature proposal: Navigate to class declaration#2132
Feature proposal: Navigate to class declaration#2132testforstephen merged 18 commits intoredhat-developer:masterfrom
Conversation
|
Although vscode has BTW, tslint fails the build with : |
The LSP request Workspace Symbols Request supports returning SymbolInformation with a location to specify the range you want to reveal in the editor. In fact, when you use Also, when a user opens a file from File Explorer, you should never hack its original open behavior. |
I was looking at the requests that are sent when I open a file by using
I find it much easier to navigate a mixed codebase (e.g. Java/JS/HTML/XML) with
It aligns more closely with the way IntelliJ or Eclipse will open Java files. The current behavior is especially "annoying" if you browse a codebase by clicking on different Java files. You always have to scroll down. If this behavior is considered too intrusive or incompatible with the way vscode "should work" then I can just close this MR. To be honest, I was expecting something along those lines. |
|
@fbricon @testforstephen what is your position on navigation to the class declaration in Java files? Is there a better way to do it? If not, can we move forward with this or not? |
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
4236720 to
7d9ec70
Compare
|
@testforstephen I implemented all the changes. The regex provides a much better user experience than resolving the document symbols. Do we need a test for this? I played around with it a little and the following test works, but has some timing issues I need to wait three times:
I couldn't find a good indicator for the first and none for the second and third. This solution would probably require tweaking the values until it works in all environments (CI pipeline). |
testforstephen
left a comment
There was a problem hiding this comment.
The latest commit works well for "go to symbol" case, but conflicts with "go to definition". Usually "go to definition" will jump to a specific location, then this PR will redirect to type declaration. We need take care of it.
Regarding unit test, i'll let @jdneo to comment on it.
|
Hi @fvclaus, Just some suggestions for consideration. I think it's ok to wait until the LS is activated for the integrated test. How about this, we write two cases here, which:
Meanwhile, I think it worth adding some unit tests for the regexp itself - to check if it can match different kind of type declarations. (besides the current types, I guess |
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
The problem is the event architecture for the extension host. vscode triggers an "editor changed" followed by "selection changed" event during "Go to definition". vscode also uses an event architecture for the editor. The selection and open editor information are stored in seperate places and are exchanged via events. Although vscode knows that the file should open with a selection != (0,0), the services that actually sends the event to the extension host do not yet have this information (they will after the next tick, when the internal events are actually sent). Because this is spread all over the codebase, this is unlikely to change. I did some measurements and on my machine it seems the event reaches the extension 30ms after opening the editor. I "fixed" this using The above seemed like a bug to me so I opened a ticket on vscode: microsoft/vscode#136618 I tried it out and found an issue in the I placed this code in It also requires changing the language server to not return a selection, which I have done here: eclipse-jdtls/eclipse.jdt.ls#1956 @testforstephen, What do you think? |
|
@fvclaus thanks for your discussions on microsoft/vscode#136618, I really like those conversations. IMHO, using resolveWorkspaceSymbol is a clean way to go. Current languageclient we use is 7.x, and 8.x should be backward-compatibility, I can verify new client version in VS Code. I'll invite @rgrunber to verify if language-client@8.x works in theia as well. Update: |
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
|
@testforstephen How can this feature be implemented only on the client? I just checked this again and there have been some changes. It is no longer possible to sneak in the If I was curious to see whether this can already be implemented on the server. It does work, here is the PR: eclipse-jdtls/eclipse.jdt.ls#2008. Here is the register request: vscode-languageclient will send a I left @testforstephen Do we want to proceed with this? Is it possible to use a newer version of vscode-languageclient already? If not, I can close this PR. Can you also decide if the server code can be merged or if it can be merged with some modifications? The client just requires a new vscode-languageclient version (and some fixes for typings that changed). I also updated the vscode dependencies. Without them vscode-languageclient throws a few compile errors. After updating, there are only 2 left: |
|
@fvclaus Usually when LSP introduces some new capabilities, we wait for lsp4j to add these new bindings, and then update lsp4j version in eclipse.jdt.ls. After that, the server can support the new capabilities officially. Given that symbol/resolve is from upcoming LSP 3.17, which is not officially announced yet. We can implement it first via registering a See https://github.com/eclipse/eclipse.jdt.ls/pull/1408/files and https://github.com/redhat-developer/vscode-java/pull/1393/files for more info on the use of delegateCommand. |
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
a9b7da5 to
c9a2999
Compare
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
c9a2999 to
a5d4301
Compare
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
|
@testforstephen Thanks for the pointers. I implemented Can you take a look at the code? |
testforstephen
left a comment
There was a problem hiding this comment.
Have a try, it works well.
But it seems the registration for the new WorkspaceSymbolProvider is a little delay. For example, when I use "Go to Symbol" feature to search a binary class (e.g. String) at 1st time, resolveWorkspaceSymbol is not called. Try a second time, then it can jump to the class definition location.
Screen.Recording.2022-02-28.at.11.28.10.mov
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
I tried, but cannot reproduce this on my machine. Is there a timeout resolving the workspace symbol? Is there anything special about your project? |
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com>
|
I'm using extension host debug mode to launch the extension. The sample project is https://github.com/spring-projects/spring-petclinic. I can always reproduce it when using |
|
@testforstephen I tried it with the petclinic project and Java 1.8, but unfortunately was not able to reproduce the issue. From the video, it seems that the project has been completely openend and the custom If this cannot be a timing issue, what vscode version are you using? |
|
I tried it in macOS via both "Launch Extension" and "Launch Extension - JDTLS Client", it has delay with "serverStatus.onServerStatusChanged" approach. I didn't observe issue in the latest implementation, it works well now. @fvclaus Thank you for keeping patience in the long discussion and taking time to address all suggestions. |
|
@testforstephen, thanks for all the feedback along the way. It was interesting and fun to develop, but I am glad we got this wrapped up now. |
When you open a Java or Class file in IntelliJ or Eclipse, the IDE will always navigate to the main element. Currently, you are looking at a wall of imports:
I looked at the LSP spec, but didn't find anything that could help. I then added it to vscode-java:
