Closed clankill3r closed 6 years ago
Do you have a sample project reproducing the error?
I figured out what it is (still seems like a bug). I wanted to make a sample project so made a copy of the directory. While opening this in VSCode the error was gone.
If I rename the original directory the error is gone as well. If I rename it back to what it was the error comes back again. So I assume there is a bug in the cache validation?
Yeah kinda, probably. If you could provide a sample project, that'd help us figure out exactly what the issue is.
Well here it is: www.doekewartena.nl/temp/Remake2.zip
But it won't help. I only have the bug when the path is /Volumes/DATA/lemmings_walker/Remake2
. If I rename Remake2
or if I move the folder the problem is solved.
Ok so it seems whenever you create a new java file, it's linked to the default package initially. Once you add the package declaration to that java file, the linked resource behind the scene should be updated to the proper package.
@snjeza: can you see if we could link the parent folder to the default project instead of creating a linked resource to the file. That'd make all files in the folder/package automatically available to the classpath, instead of having to open each one of them manually (i.e the current fake compilation unit hack)
@fbricon I will try
@snjeza can we close this one?
@gorkem I don't have a permission to do it.
@snjeza oops. Fixed you should be able to do it now.
When you open a standalone java file in a random directory (i.e, that doesn't belong to a project), if the class has a foo.bar
package, that package name will be used by default. Now if you rename the package name and save, then the same error shows up (The declared package "foo.bar.toto" does not match the expected package "foo.bar"
)
@fbricon The issue hasn't been caused by this PR. See https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java#L195 I am not sure how to fix this issue except to recreate a link for such a file whenever resolving a compilation unit.
@fbricon Unfortunately it seems like this is still very much an issue, exactly like @clankill3r my package declaration is returning an error of The declared package "aprogrammerisneverlate.xtrex" does not match the expected package ""
despite having a correct file tree to support it.
@Vanir112 given you have class files mixed with your source code, that tells me you're not using Maven or Gradle to build your code. As a consequence your source folders are not recognized and vscode-java gives you incorrect diagnostics. Can you try to use either Maven or Gradle (which is a good thing to do either way)
I did use maven. If I remember correct I fixed the problem with reinstalling vscode.
2018-02-14 15:59 GMT+01:00 Fred Bricon notifications@github.com:
@Vanir112 https://github.com/vanir112 given you have class files mixed with your source code, that tells me you're not using Maven or Gradle to build your code. As a consequence your source folders are not recognized and vscode-java gives you incorrect diagnostics. Can you try to use either Maven or Gradle (which is a good thing to do either way)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/redhat-developer/vscode-java/issues/274#issuecomment-365633022, or mute the thread https://github.com/notifications/unsubscribe-auth/AAtFWhh6cdfSq0bAr07_gE7hv3xsazLEks5tUvTKgaJpZM4OxNF7 .
I'm having a similar problem. Seemingly at random it just stops recognizing the packages. I tried reinstalling VS Code and the extensions, but it is still a problem
Can you close vscode, remove the workspace storage and then open vscode, tell me if that fixed it.
I have been encountering this issue recently as well. My solution was to add
{
"java.project.sourcePaths": [""]
}
to .vscode/settings.json
.
This was a problem for me too. I navigated to the configure class path tab through the "java projects" tab at the bottom left of the screen. From there, i removed all other paths apart from the default. this solved my problem. The "java.project.sourcePaths": [""]" solution does this.
This is still a problem regardless of what I set my sourcePaths
setting to in Gradle projects. It seems the setting is completely ignored in my case.
Just in case anyone has made the same (stupid) mistake that I did and cost me around 1 hour fumbling around. Make sure your folder structure is src/some/random/package
and not src/some.random.package
which I wrote mechanically. I was convinced it was a cache issue because of the expected package ""
in the error message.
I try to make a library for the first time in VSCode (I have done this before in IntelliJ and Eclipse). My workspace looks like this:
In LemmingsWalker.java I have:
package com.github.lemmingswalker;
. Which gives me the following error:Environment