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

[Feature] Browsing jar dependencies contents #3160

Open
asmodeus812 opened this issue May 17, 2024 · 5 comments
Open

[Feature] Browsing jar dependencies contents #3160

asmodeus812 opened this issue May 17, 2024 · 5 comments

Comments

@asmodeus812
Copy link

asmodeus812 commented May 17, 2024

Similarly to Eclipse or intellij, it would be great if jdt uris supported directories or jars. The application of this being the aplity for a user to be browsing the contents of a jar dependency as if it were a filetree. There is probably more to this, but this ticket can serve as a starter / idea.

@asmodeus812 asmodeus812 changed the title [Feature] browsing jar contents [Feature] Browsing jar dependencies contents May 17, 2024
@rgrunber
Copy link
Contributor

rgrunber commented May 22, 2024

JDT-LS is simply a language server, so we'd have no control over how this would look visually. We just send the data, and it's up to clients to render it. However, it seems to me like textDocument/documentSymbol, which takes a URI, should be able to provide this. This method is what clients call when rendering the "structure" of a source/class file, often referred to as an "Outline" view :

eg. VS Code's behaviour
image

Maybe this could nicely display the contents of a JAR file as well.

@asmodeus812
Copy link
Author

asmodeus812 commented May 22, 2024

Yeah, indeed, i am not looking for the view. Rather, the data model, which will be used to construct the view, and it will be handled by client specific implementation. A jar can contain either other sub dirs or some resources which are not only class files. However, I am not sure if jdtls supports uris to such resources.

In addition to that, it would be nice to have a complimentary way to fetch the jar dependencies for the current project, coming from either the user config or build systems like maven, gradle, etc.

@fbricon
Copy link
Contributor

fbricon commented May 22, 2024

The Project Manager for Java in VS Code supports it:

Screenshot 2024-05-22 at 16 37 04

I don't know whether this involves special requests to a Microsoft extension or if jdt.ls provides those OOTB. @testforstephen @jdneo ?

@rgrunber
Copy link
Contributor

I think it's coming from https://github.com/microsoft/vscode-java-dependency/blob/6aaf68428f0abac4e224d698ab98c83897c52285/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/CommandHandler.java#L30-L31 , which appears to be based on the Java model. So if we wanted to do this through document symbols, we could possibly move the code into JDT-LS and then just call it for https://github.com/microsoft/vscode-java-dependency/blob/main/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java#L366-L382

It appears to be computed on-demand. So you expand an entry and it sends the request for elements.

[Trace - 12:48:47] Sending request 'workspace/executeCommand - (7)'.
Params: {
    "command": "java.getPackageData",
    "arguments": [
        {
            "kind": 2,
            "projectUri": "file:/home/rgrunber/sample-projects/maven-my-app/"
        }
    ]
}


[Trace - 12:48:47] Received response 'workspace/executeCommand - (7)' in 25ms.
Result: [
    {
        "entryKind": 1,
        "name": "src/main/java",
        "path": "/my-app/src/main/java",
        "handlerIdentifier": "=my-app/src\\/main\\/java=/optional=/true=/=/maven.pomderived=/true=/",
        "uri": "file:/home/rgrunber/sample-projects/maven-my-app/src/main/java",
        "kind": 3,
        "metaData": {
            "maven.pomderived": "true",
            "optional": "true"
        }
    },
    {
        "entryKind": 1,
        "name": "src/main/resources",
        "path": "/my-app/src/main/resources",
        "handlerIdentifier": "=my-app/src\\/main\\/resources=/maven.pomderived=/true=/=/optional=/true=/",
        "uri": "file:/home/rgrunber/sample-projects/maven-my-app/src/main/resources",
        "kind": 3,
        "metaData": {
            "maven.pomderived": "true",
            "optional": "true"
        }
    },
    {
        "entryKind": 1,
        "name": "src/test/java",
        "path": "/my-app/src/test/java",
        "handlerIdentifier": "=my-app/src\\/test\\/java=/optional=/true=/=/maven.pomderived=/true=/=/test=/true=/",
        "uri": "file:/home/rgrunber/sample-projects/maven-my-app/src/test/java",
        "kind": 3,
        "metaData": {
            "maven.pomderived": "true",
            "test": "true",
            "optional": "true"
        }
    },
    {
        "entryKind": 5,
        "name": "JRE System Library [JavaSE-1.8]",
        "path": "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8",
        "uri": "file:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.412.b06-1.fc39.x86_64/",
        "kind": 8
    },
    {
        "entryKind": 5,
        "name": "Maven Dependencies",
        "path": "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER",
        "kind": 8
    },
    {
        "name": ".classpath",
        "path": "/my-app/.classpath",
        "uri": "file:///home/rgrunber/sample-projects/maven-my-app/.classpath",
        "kind": 10
    },
    {
        "name": ".gitignore",
        "path": "/my-app/.gitignore",
        "uri": "file:///home/rgrunber/sample-projects/maven-my-app/.gitignore",
        "kind": 10
    },
    {
        "name": ".project",
        "path": "/my-app/.project",
        "uri": "file:///home/rgrunber/sample-projects/maven-my-app/.project",
        "kind": 10
    },
    {
        "name": ".settings",
        "path": "/my-app/.settings",
        "uri": "file:///home/rgrunber/sample-projects/maven-my-app/.settings",
        "kind": 9
    },
    {
        "name": ".vscode",
        "path": "/my-app/.vscode",
        "uri": "file:///home/rgrunber/sample-projects/maven-my-app/.vscode",
        "kind": 9
    },
    {
        "name": "bin",
        "path": "/my-app/bin",
        "uri": "file:///home/rgrunber/sample-projects/maven-my-app/bin",
        "kind": 9
    },
    {
        "name": "pom.xml",
        "path": "/my-app/pom.xml",
        "uri": "file:///home/rgrunber/sample-projects/maven-my-app/pom.xml",
        "kind": 10
    },
    {
        "name": "src",
        "path": "/my-app/src",
        "uri": "file:///home/rgrunber/sample-projects/maven-my-app/src",
        "kind": 9
    },
    {
        "name": "target",
        "path": "/my-app/target",
        "uri": "file:///home/rgrunber/sample-projects/maven-my-app/target",
        "kind": 9
    }
]
Trace - 12:57:07] Sending request 'workspace/executeCommand - (9)'.
Params: {
    "command": "java.getPackageData",
    "arguments": [
        {
            "kind": 3,
            "projectUri": "file:/home/rgrunber/sample-projects/maven-my-app/",
            "rootPath": "/home/rgrunber/.m2/repository/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar",
            "handlerIdentifier": "=my-app/\\/home\\/rgrunber\\/.m2\\/repository\\/com\\/google\\/guava\\/guava\\/30.1.1-jre\\/guava-30.1.1-jre.jar=/maven.pomderived=/true=/=/maven.groupId=/com.google.guava=/=/maven.artifactId=/guava=/=/maven.version=/30.1.1-jre=/=/maven.scope=/compile=/=/maven.pomderived=/true=/",
            "isHierarchicalView": false
        }
    ]
}


[Trace - 12:57:07] Received response 'workspace/executeCommand - (9)' in 55ms.
Result: [
    {
        "name": "com.google.common.escape",
        "path": "/home/rgrunber/.m2/repository/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar",
        "handlerIdentifier": "=my-app/\\/home\\/rgrunber\\/.m2\\/repository\\/com\\/google\\/guava\\/guava\\/30.1.1-jre\\/guava-30.1.1-jre.jar=/maven.pomderived=/true=/=/maven.groupId=/com.google.guava=/=/maven.artifactId=/guava=/=/maven.version=/30.1.1-jre=/=/maven.scope=/compile=/=/maven.pomderived=/true=/<com.google.common.escape",
        "uri": "file:/home/rgrunber/.m2/repository/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar",
        "kind": 4
    },
    {
        "name": "com.google.common.hash",
        "path": "/home/rgrunber/.m2/repository/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar",
        "handlerIdentifier": "=my-app/\\/home\\/rgrunber\\/.m2\\/repository\\/com\\/google\\/guava\\/guava\\/30.1.1-jre\\/guava-30.1.1-jre.jar=/maven.pomderived=/true=/=/maven.groupId=/com.google.guava=/=/maven.artifactId=/guava=/=/maven.version=/30.1.1-jre=/=/maven.scope=/compile=/=/maven.pomderived=/true=/<com.google.common.hash",
        "uri": "file:/home/rgrunber/.m2/repository/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar",
        "kind": 4
    },
   ...
   ...

@jdneo
Copy link
Contributor

jdneo commented May 23, 2024

It appears to be computed on-demand. So you expand an entry and it sends the request for elements.

Yes, it is. I'm ok to put the logic handling into JDT.LS and let the project manager act as a UI presenter. I'm not quite sure is if we want to make it kind of public API in JDT.LS, can we put it as it is now, or we need to redesign the request and response properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants