-
Notifications
You must be signed in to change notification settings - Fork 136
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
Highlight missing variables #489
Comments
Could you share all Java extensions you installed? |
Do you mean it works after you installed Java extensions? |
No, I meant I was able to fit the screenshot in. |
If there are more I should install, I'm trying to figure out which ones will do it. I thought the vscode-java-pack was supposed to pull everything else in. |
Okay, I now have new information. I created a new window, pasted the same code, but this time, I got an error popup telling me to check the output window for details. The error is:
I have various Java installs though, including Java 11: Is it possible there is an issue with how it's searching for a JDK? |
yes, this looks like duplicated with redhat-developer/vscode-java#1621. Click |
It can't detect the JDKs available on the system and pick the right one by itself? It doesn't seem that hard. |
Untitled file won't get the feature, you need save your file to a .java. |
Why should that make a difference? The editor has recognised it as Java code. See the screenshot. |
Since you just open a non-project Java file in VS Code, it will only show syntax errors by default. Regarding to the reason, there is a long story about the design, if you're interested, you could read here redhat-developer/vscode-java#1270. Currently you could turn on all compilation errors manually by yourself, see the screenshot below. |
You're showing a different class file to mine. Show me what it does for you when you paste in the sample I gave. |
For comparison, here's the experience in IntelliJ IDEA: |
I have been using VS Code for editing Java for the better part of a year now, across multiple Java projects, and I have never seen a red underline under a variable name. If you're telling me the feature is supported then it is very, very well hidden from the user. |
@trejkaz If you simply open a .java file outside current workspace, only syntax error will be reported. See my screenshot to understand current behaviors.
|
OK, so a lot of hoops to jump through to get basic behaviour working, but OK, it eventually does work. I think it could have been a lot simpler than it was, looking back at all the things I had to try to get it working, compared to the video of doing the same thing in IDEA, where it just works first try. I mean, I have been using the editor for almost a year, and have never seen it highlight a missing variable, even on all the projects I use it on. You can understand how I legitimately thought it was a missing feature, I'm sure. |
I think that really what this ticket is about is that the missing variable detection just doesn't work very well and should just be improved overall. |
Additionally there seem to be some warnings here which are incorrect. There's a warning saying the cast to |
It's more than an issue of "missing varible detection". The issue is about project recognition. The root cause is that your project was not correctly recognize by language server, thus it could not provide any further intellisense. Well, I have to say, this ticket could have been clearer if you provided the sample project instead of pasting screenshots with limited information 🤷. Anyway, from the last screenshot, I find your project is probably https://github.com/ephemeral-laboratories/dozenal-mod3 (correct me if wrong). This project is a Kotlin Gradle project. AFAIK, Kotlin is not supported in VS Code Java extension, see redhat-developer/vscode-java#632 . For the moment, to get it working, I suggest you to manage your project with |
I use Kotlin in my Gradle projects because I like type safety. So yeah, that's definitely the issue with dozenal-mod3, but also with red-rocket, and with a couple of other recent projects of mine, basically everything created since Kotlin became the recommended language for Gradle build scripts. For that I just have to wait for tools to catch up and support Kotlin, which might be a while by the look of things. :( Before Gradle got Kotlin support in build scripts, I was avoiding Gradle because I disliked Groovy, so I was using Buildr in preference. But Buildr has never seen widespread support in tools, so I can't really blame anyone for that. The project at work is still using Groovy for the Gradle build, and I've never seen syntax highlighting of errors in there either, but the build there is also too complicated to really share in its current form. I'd have to cut it down to a smaller reproducible sample, which is something I've not yet had time to do. But other devs at work have made the same comment, that they avoid using VSCode to some extent because it doesn't seem to understand the structure of Java projects. On the other hand, ever since the lockdowns started, IntelliJ IDEA has not been ideal for us either, because it lacks support for opening projects remotely. So we currently use a mix of the two depending on how much autorefactoring we plan to use on a given day. What about MinecraftForge? That's using |
Or here's Storage Drawers: |
Or here's Botania. https://github.com/Vazkii/Botania I think that's a bit of variety across three different developers' codebases. All Minecraft-related but that does happen to be what I've been working on a lot lately. |
Okay, I finally found one project where the feature does work as intended. https://github.com/redhat-developer/intellij-rsp I have to confess that I went searching through that repository only because I thought it would be hilarious if I also reproduced it first try on one of your own projects. But nope, the red underline works fine there, and so now I've seen it working as intended for the first time ever. So what's so different about that project, compared to say, Storage Drawers, which has the same Java version shown in the status bar and the same thumbs up icon? |
I did some investigation over on the work project which is also using Groovy, and reported that error in issue #497. |
@trejkaz I've investigated the Minecraft projects you linked, and found both StorageDrawers and Botania to work, given that you wait for the extension to import the project. Without importing the projects, the Java language server can't provide the full feature set such as intellisense or highlighting missing variables. One thing I noted was that it took a while (maybe a minute or so) after the thumbs up icon until the project was fully imported and I could get a warning about the missing variable. This is likely caused by the ForgeGradle tasks that run for projects using the Forge MDK, which may prevent the language server from fully importing the project even though you have a thumbs up. Minecraft Forge itself has a very complicated Gradle setup, which is why you won't be able to import it right away by opening the folder (in fact, this does not work in Eclipse or IntelliJ either). See their instructions on how to import the project, the Eclipse instructions roughly apply to VS Code. As you can see, not only do you need to run a Gradle task, but also import the Error message
Curiously, intellisense and semantic highlighting is working fine, but the error for missing variables do not. I'm guessing it has something to do with the error above. My guess is that the Java language server doesn't handle the special build setup of the Forge project very well, seeing as the source file for If you actually care about working on MinecraftForge specifically, I would submit an issue over at https://github.com/redhat-developer/vscode-java, with more log files and steps to reproduce. But this problem seems very specific to the Gradle setup of MinecraftForge, normal Gradle projects (such as the mods you linked) work fine after waiting for them to import. |
@Eskibear @testforstephen do we have a conclusion now? |
Yeah, I originally had filed this because I thought I was requesting a new feature, but now it's clear that the feature exists, so I might as well close the ticket. Some day I hope to actually see this on one of my projects, but that's being sorted out elsewhere. |
Suggestion
At a minimum, I would like to see missing variables highlighted with some kind of red underline to indicate the problem, as demonstrated by IntelliJ IDEA.
Use Cases
I'm writing Java code in VSCode, which does not yet have working code completion. I'm likely therefore to make mistakes in naming variables, which the editor could pick up on.
Examples
Current behaviour:
The text was updated successfully, but these errors were encountered: