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

Unable to add external jar to work with LSP #3912

Open
keys-i opened this issue Jan 7, 2025 · 4 comments
Open

Unable to add external jar to work with LSP #3912

keys-i opened this issue Jan 7, 2025 · 4 comments

Comments

@keys-i
Copy link

keys-i commented Jan 7, 2025

I'm using Visual Studio Code for a Java project without build tools (e.g., Maven or Gradle). I've added JAR files using the java.project.referencedLibraries setting. While auto-completion and documentation pop-ups work, there is no proper syntax highlighting (LSP-based) for the referenced classes and methods within the JARs.

Steps to Reproduce:

  1. Open a Java project in VS Code.
  2. Add JAR files directly to the java.project.referencedLibraries setting.
  3. Use a class or method from the JAR in your code.

Expected Behavior:

LSP features should include syntax highlighting for classes and methods from the JARs, in addition to auto-completion and documentation pop-ups.

Actual Behavior:

While auto-completion and documentation pop-ups work, syntax highlighting does not apply for the JAR dependencies.

Screenshot:

  • Referencing the JAR:
    Screenshot1
  • Missing syntax highlighting:
    Screenshot2

Additional Context:

This issue occurs in a setup without Maven or Gradle. Are there additional configurations required to enable full syntax highlighting for JAR dependencies?

@fbricon
Copy link
Collaborator

fbricon commented Jan 7, 2025

can you provide a sample project reproducing the issue?

@keys-i
Copy link
Author

keys-i commented Jan 7, 2025

I attempted to reproduce the issue using the following code:

import edu.duke.*;

public class PerimeterRunner {
    public double getPerimeter(Shape s) {
        double totalPerimeter = 0.0;  // Initialize perimeter to 0
        Point prevPt = s.getLastPoint();  // Start with the last point
        return totalPerimeter;
    }
}

I used the courserajava.jar library from this link, but I am still encountering the same error. Any suggestions on how to resolve this?

@fbricon
Copy link
Collaborator

fbricon commented Jan 7, 2025

Your example works for me. Your 1st screenshot shows syntax highlighting is working correctly. I don't know what your 2nd screenshot is supposed to show, but certainly not syntax highlighting.
It seems your problem is a compilation issue.

Because hovering over Point shows you proper documentation, the courserajava.jar is properly accessed by the Java language server.
The "cannot find symbol" error you're seeing is a javac specific error message, the source of that message (errors(3): 6:3-6:8) leads me to believe you installed a conflicting Java extension (likely the Oracle/Netbeans one). Try disabling all other Java-based extensions (i.e not from Red Hat or Microsoft) and try again.

@keys-i
Copy link
Author

keys-i commented Jan 7, 2025

The error occurs when I have vscode-java enabled. I’ll try disabling each one to make sure if it’s a conflict issue.

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

No branches or pull requests

2 participants