vscode-java
vscode-java copied to clipboard
java.project.resourceFilters seems to be ignored when initializing workspace
java.project.resourceFilters
seems to be ignored when opening a workspace.
I have the vague feeling that I'm doing something wrong rather than this being a bug with the extension, but I tried a few things now, nothing works.
The only other idea I have is the following: vscode-java.log The log seems to show, line 72, that the resource filters are only loaded once the workspace is already initialized. But, as seen in line 63, atm. it takes ~2 minutes to initialize. Unfortunately I have to integrate another project as a subfolder, so a lot more files. #1460 seems to suggest (to me, at least) that exactly this problem is solved in there.
If I can help you with any more information than the provided, I'd be happy to. Thanks you all for helping and developing this nice extension!
Environment
- Operating System: WSL2, so Linux Docker from Windows 10
- JDK version: openjdk:11.0.7
- Visual Studio Code version: 1.50.0
- Java extension version: 0.68.0
Steps To Reproduce
- Open Workspace in container
- Watch Java Build Status chewing through the mounted .git folder.
Current Result
Folders listed in java.project.resourceFilters
are used.
Expected Result
No folders listed in java.project.resourceFilters
should be used. One interesting part of this, is that even if I do not set my custom folders (so no "java.project.resourceFilters" in the settings.json), the .git folder is used. The Readme states, that the default value is ["node_modules",".git"]. I'd expect therefore, that even then, the .git-folder shouldn't be parsed.
Additional Informations
A few additional infos, but I'm not sure if they are related to the issue: The .git folder is mounted from the underlying filesystem into the container.
I tried with another folder, too, no difference: the folder is used weather it is in java.project.resourceFilters
or not.
My workspace settings file:
{
"files.watcherExclude": {
"**/bin/**": true,
"**/lib/**": true
},
"java.project.resourceFilters": [
".git",
]
}
Here is the project I'm working on: https://gitlab.com/Girstenbrei/cpachecker/-/tree/2a6f9bfe77a33fc9a5b6963d6f0da5bde3bcedda . The settings from above are not yet in this commit, so I included it separately. If you check it out to start with docker, here a folder outside the workspace is mounted into it, just so you are aware.
java.project.resourceFilters seems to be ignored when opening a workspace.
@girstenbrei We can't add any filters if a project doesn't exist.
You can try to add
<projectDescription>
...
<filteredResources>
<filter>
<id>1602772612883</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
to your .project file - https://gitlab.com/Girstenbrei/cpachecker/-/blob/2a6f9bfe77a33fc9a5b6963d6f0da5bde3bcedda/.project
@snjeza I had a look at that file before and as far as I can see, the extension auto-generates this entry. Starting without setting java.project.resourceFilters
, the file contains the following (without me adding anything):
<projectDescription>
...
<filteredResources>
<filter>
<id>1602828376803</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
This matches the expected behavior (= default of ["node_modules",".git"]) but still results in initializing with files within the .git-folder. Even when I insert your proposed block manually, behavior stays the same.
Unfortunately I'm not aware how the API works, so I'm not aware when filters can be added, but from my naive point of view I'd like to be able to prevent the language server from combing through (in my case a huge amount of) unnecessary files and folders. Both this comment from #1460 and this SO question seem to reference initialization of the project. Is there a way to tell the language server to exclude folders and their contents completely?
Thanks for your input @snjeza , appreciate it!
Is this configuration used at all? I just searched for uses in the repository and I don't see any references to it. This behavior is pretty important for projects that use local maven repositories (for example, we end up with over 8000 errors from third-party code).
I'd like to create a pull request to fix this issue - could any maintainer point me to a good starting point please?
I'm facing the same problem. Any update on this?
This definitely seems to work when you've got a .project
file - that file gets updated live when you've got it
Note that this live-updating of the .project
file happens even if java.import.generatesMetadataFilesAtProjectRoot
is false - but since it does default to false it won't be created and maybe the lack of it is causing issues for some people?
cc: @testforstephen
This definitely seems to work when you've got a
.project
file - that file gets updated live when you've got itNote that this live-updating of the
.project
file happens even ifjava.import.generatesMetadataFilesAtProjectRoot
is false - but since it does default to false it won't be created and maybe the lack of it is causing issues for some people?
@jcrben .project
is a necessary config file for Java extension, it can be provided by yourself or created by Java extension. If your workspace already contains a .project
file, then Java extension prefers to use it regardless of the value of java.import.generatesMetadataFilesAtProjectRoot
. Otherwise, Java extension will create one for you.
if java.import.generatesMetadataFilesAtProjectRoot
is false, it just tells Java extension not to generate .project
in your workspace but somewhere in cache (see screenshot if you're interested).
I'm pretty sure it does not work. I think I filed bug in wrong project, but for more info : https://github.com/microsoft/vscode-java-dependency/issues/717
I can't get java.project.resourceFilters
to work either. Very frustrating.
I managed to find a workaround that might work for others. Here is my situation and workaround:
- I have a Workspace with several Folders, some of which are Java projects (gradle based) and others are not (either "not Java at all", or Java but "not Gradle or Maven based")
- The "non Java" or "non Gradle based" folders were reported as having errors by VSCode java
- For some reason, this also caused issues for some of the Folders with Gradle based Java projects
I wanted to use java.project.resourceFilters
to make sure that VSCode Java wouldn't "touch" the non-Gradle projects. Which I haven't managed to get working.
The workaround:
- Split these projects into separate Workspaces
- Use the "Native Tabs" trick to keep these different Workspaces in the same VSCode window ("window.nativeTabs", cf https://x.com/localhost_5173/status/1720121413921833190?s=20)
- Problem "solved"
But it's very frustrating not to be able to tell VSCode Java to not look at some Folders. It seems something like https://github.com/microsoft/vscode/issues/81153 should be used to do so. But it's been marked as "wont-fix" ...