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

Add java.import.resourceFilter preference #1508

Closed
SreenivasVRao opened this issue Jul 14, 2020 · 14 comments · Fixed by #1521
Closed

Add java.import.resourceFilter preference #1508

SreenivasVRao opened this issue Jul 14, 2020 · 14 comments · Fixed by #1521
Assignees

Comments

@SreenivasVRao
Copy link

Hi, I see that this was supposed to be fixed by #560

But I see this issue still crop up when I try JDTLS in Emacs/LSP. I tried the most recent version from http://download.eclipse.org/jdtls/snapshots/?d

I have the following import exclusions set:

["**/node_modules/**",  "**/.metadata/**", "**/archetype-resources/**", "**/META-INF/maven/**", "**/env/**"]

But in the logs I see:

34% Starting Java Language Server - /Volumes/path/to/project/env/NodeJS-12.x/runtime/lib/node_modules/npm/node_modules/latest-version[Starting]
34% Starting Java Language Server - /Volumes/path/to/project/env/NodeJS-12.x/runtime/lib/node_modules/npm/node_modules/getpass/lib[Starting]
34% Starting Java Language Server - /Volumes/path/to/project/env/NodeJS-12.x/runtime/lib/node_modules/npm/node_modules/make-fetch-happen[Starting]
34% Starting Java Language Server - /Volumes/path/to/project/env/NodeJS-12.x/runtime/lib/node_modules/npm/node_modules/sshpk[Starting]
34% Starting Java Language Server - /Volumes/path/to/project/env/NodeJS-12.x/runtime/lib/node_modules/npm/node_modules/qrcode-terminal/bin[Starting]
34% Starting Java Language Server - /Volumes/path/to/project/env/NodeJS-12.x/runtime/lib/node_modules/npm/docs/public/cli-commands/npm-dist-tag[Starting]
@SreenivasVRao
Copy link
Author

@fbricon could you look at this..? I can give you logs from what I see during startup if that helps...

@thiscantbeserious
Copy link

thiscantbeserious commented Jul 24, 2020

From the logs of vscode-java -> Using 'Java: Open Java language server log file' I see that the exclusions are properly forwarded as it seems (old log, ignore the rest):

!MESSAGE >> New configuration: {java={home=C:\AdoptOpenJDK\jdk-11.0.8.10-hotspot, jdt={ls={vmargs=-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx1G -Xms100m}}, errors={incompleteClasspath={severity=warning}}, configuration={checkProjectSettingsExclusions=true, updateBuildConfiguration=interactive, maven={userSettings=null}, runtimes=[{default=true, name=JavaSE-1.8, path=C:\Java\openjdk8u181-b13}]}, trace={server=off}, import={maven={enabled=true}, gradle={enabled=true, wrapper={enabled=true}, version=null, home=null, java={home=null}, offline={enabled=false}, arguments=null, jvmArguments=null, user={home=null}}, exclusions=[.git, .git/**, .git/**/*, node_modules, node_modules/**, node_modules/**/*, watij, watij/**, watij/**/*, **/node_modules/**, **/.metadata/**, **/archetype-resources/**, **/META-INF/maven/**, **/templater-front/**]}, maven={downloadSources=false, updateSnapshots=false}, referencesCodeLens={enabled=false}, signatureHelp={enabled=false}, implementationsCodeLens={enabled=false}, format={enabled=true, settings={url=null, profile=null}, comments={enabled=true}, onType={enabled=true}}, saveActions={organizeImports=false}, project={referencedLibraries=[lib/build/*.jar, lib/*.jar, lib/**/*.jar], importOnFirstTimeStartup=interactive, importHint=true}, contentProvider={preferred=null}, autobuild={enabled=true}, maxConcurrentBuilds=1.0, completion={maxResults=0.0, enabled=true, overwrite=true, guessMethodArguments=false, favoriteStaticMembers=[org.junit.Assert.*, org.junit.Assume.*, org.junit.jupiter.api.Assertions.*, org.junit.jupiter.api.Assumptions.*, org.junit.jupiter.api.DynamicContainer.*, org.junit.jupiter.api.DynamicTest.*, org.mockito.Mockito.*, org.mockito.ArgumentMatchers.*, org.mockito.Answers.*], filteredTypes=[java.awt.*, com.sun.*], importOrder=[java, javax, com, org]}, foldingRange={enabled=true}, progressReports={enabled=true}, codeGeneration={hashCodeEquals={useJava7Objects=false, useInstanceof=false}, useBlocks=false, generateComments=false, toString={template=${object.className} [${member.name()}=${member.value}, ${otherMembers}], codeStyle=STRING_CONCATENATION, skipNullValues=false, listArrayContents=true, limitElements=0.0}}, selectionRange={enabled=true}, showBuildStatusOnStart={enabled=false}, server={launchMode=Hybrid}, sources={organizeImports={starThreshold=99.0, staticStarThreshold=99.0}}, semanticHighlighting={enabled=true}, refactor={renameFromFileExplorer=prompt}, imports={gradle={wrapper={checksums=[]}}}, code={generators={includeFluentWithSettersGetters=false, fluentMethodPrefix=, methodOpeningBraceOnNewLine=false, generateEvenIfExists=false, onlyIdForHashAndEquals=false, onlyPrimitiveForToString=false, copyJsonPropertyAnnotationsFromVariablesToSettersGetters=false, includeGeneratedAnnotation=false}}, debug={logLevel=warn, settings={showHex=false, showStaticVariables=false, showQualifiedNames=false, showLogicalStructure=true, showToString=true, maxStringLength=0.0, numericPrecision=0.0, hotCodeReplace=manual, enableRunDebugCodeLens=true, forceBuildBeforeLaunch=false, console=integratedTerminal, exceptionBreakpoint={skipClasses=[]}, stepping={skipClasses=[], skipSynthetics=false, skipStaticInitializers=false, skipConstructors=false}}}, dependency={showMembers=false, syncWithFolderExplorer=true, autoRefresh=true, refreshDelay=2000.0, packagePresentation=flat}, help={firstView=auto}, test={report={showAfterExecution=onFailure, position=sideView}, editor={enableShortcuts=true}, log={level=info}, message={hintForDeprecatedConfig=true, hintForSetingDefaultConfig=true}, defaultConfig=, config={}}, requirements={JDK11Warning=false}}}

I tried many combinations - not a single one of them work (even the very simple ones don't just specifying the foldername).

OS: Windows 10 - globs shouldn't be FS-specific in regards to backslashes no?

So I doubt that it has anything to do with it directly, maybe in the implementation?

@snjeza
Copy link
Contributor

snjeza commented Jul 24, 2020

@thiscantbeserious @SreenivasVRao java.import.exclusions is used when importing a directory for a first time.
You may want to take a look at redhat-developer/vscode-java#1362 (comment)

@SreenivasVRao
Copy link
Author

SreenivasVRao commented Jul 24, 2020 via email

@snjeza
Copy link
Contributor

snjeza commented Jul 24, 2020

java.import.exclusions is checked only when you delete your workspace. You probably should use filteredResources.
Could you try add

<filteredResources>
		<filter>
                       <id>1</id>
			<name></name>
			<type>30</type>
			<matcher>
				<id>org.eclipse.core.resources.regexFilterMatcher</id>
				<arguments>node_modules|env|.metadata|.git</arguments>
			</matcher>
		</filter>
	</filteredResources>

to your .project file.

@SreenivasVRao
Copy link
Author

I think it would be great if this could be exposed as a setting in the server. I have several java projects - and I'll have to manually modify each of these. Even if I miss it for any single project, the indexing of the workspace will happen and slow down the server.

@thiscantbeserious
Copy link

thiscantbeserious commented Jul 27, 2020

I think it would be great if this could be exposed as a setting in the server. I have several java projects - and I'll have to manually modify each of these. Even if I miss it for any single project, the indexing of the workspace will happen and slow down the server.

Totally agreed. I can understand that such a thing should be handled from the .project side rather then the workspace/userspace

It does help with a larger number of legacy projects (but then, those are already handled once imported). So maybe more or less adjusting the behaviour of java.import.exclusions to handle both cases rather then a new setting?

It's somewhat of a EDGE case, but then again, I'd say more people will run into this issue from time to time as it is - so either that or a better documentation in that regard would help. Can we contribute to the docs?

@snjeza snjeza self-assigned this Jul 27, 2020
@snjeza snjeza changed the title JDTLS ignoring import exclusions Add java.import.resourceFilter preference Jul 27, 2020
@fbricon fbricon added this to the End August 2020 milestone Aug 21, 2020
@SreenivasVRao
Copy link
Author

SreenivasVRao commented Oct 1, 2020

I'm still seeing this problem. Seems like the workspace refreshes before the configuration is loaded? Is this a setting I need to change on my end? For example, I see Starting Java Language Server - /path/to/node_modules before I see:

Oct 1, 2020, 12:43:24 PM >> initialization job finished
Oct 1, 2020, 12:43:24 PM >> workspace/didChangeConfiguration
Oct 1, 2020, 12:43:24 PM >> New configuration: {java={codeGeneration={toString={limitElements=0.0, listArrayContents=true, skipNullValues=false, codeStyle=STRING_CONCATENATION, template=${object.className} [${member.name()}=${member.value}, ${otherMembers}]}, generateComments=false, useBlocks=false, hashCodeEquals={useInstanceof=false, useJava7Objects=false}}, format={onType={enabled=true}, comments={enabled=true}, enabled=true}, progressReports={enabled=true}, foldingRange={enabled=true}, completion={importOrder=[java, javax, com, org], favoriteStaticMembers=[org.junit.Assert.*, org.junit.Assume.*, org.junit.jupiter.api.Assertions.*, org.junit.jupiter.api.Assumptions.*, org.junit.jupiter.api.DynamicContainer.*, org.junit.jupiter.api.DynamicTest.*, org.mockito.Mockito.*, org.mockito.ArgumentMatchers.*, org.mockito.Answers.*], guessMethodArguments=true, overwrite=true, enabled=true, filteredTypes=[java.awt.*, com.sun.*], maxResults=0.0}, maxConcurrentBuilds=1.0, autobuild={enabled=true}, selection={enabled=true}, import={exclusions=[**/node_modules/**, **/.metadata/**, **/archetype-resources/**, **/META-INF/maven/**], maven={enabled=true}, gradle={enabled=true, wrapper={enabled=true}, offline={enabled=false}}}, saveActions={organizeImports=false}, implementationsCodeLens={enabled=false}, signatureHelp={enabled=true}, referencesCodeLens={enabled=false}, maven={downloadSources=false, updateSnapshots=false}, trace={server=off}, configuration={updateBuildConfiguration=automatic, checkProjectSettingsExclusions=true}, errors={incompleteClasspath={severity=warning}}, dependency={packagePresentation=flat}, project={importHint=true, importOnFirstTimeStartup=automatic, referencedLibraries=[lib/**/*.jar], resourceFilters=[node_modules, .metadata, archetype-resources, META-INF/maven, runtime, env, build]}, imports={gradle={wrapper={checksums=[]}}}, sources={organizeImports={staticStarThreshold=99.0, starThreshold=99.0}}, server={launchMode=Hybrid}, showBuildStatusOnStart={enabled=false}, selectionRange={enabled=true}}}

Seems like the configuration for resource filters is not applied when the server is launching?

Would this be fixed if these two lines were swapped?
https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandler.java#L195
https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandler.java#L196

@snjeza
Copy link
Contributor

snjeza commented Oct 1, 2020

Would this be fixed if these two lines were swapped?

No, it wouldn't.
Could you send your settings.json?

@SreenivasVRao
Copy link
Author

Ah, I'm using emacs/lsp-java. I will try to retrieve a configuration, but it's a little tricky.

I have nearly the same settings as https://github.com/emacs-lsp/lsp-java/blob/master/lsp-java.el#L373

Is there any standard git repo I can use to test if this really works..?

@snjeza
Copy link
Contributor

snjeza commented Oct 1, 2020

@SreenivasVRao Could you send your .project?
There isn't the resourceFilters property in your configuration.

@SreenivasVRao
Copy link
Author


<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>ProjectName</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
<nature> company specific </nature>
	</natures>
	<filteredResources>
		<filter>
			<id>1601570560822</id>
			<name></name>
			<type>30</type>
			<matcher>
				<id>org.eclipse.core.resources.regexFilterMatcher</id>
				<arguments>node_modules|.metadata|archetype-resources|META-INF/maven|runtime|env|build|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
			</matcher>
		</filter>
	</filteredResources>
</projectDescription>

^this is only one project though. I haven't updated all my projects. Could that be the reason?

I do have resourceFilters (it's not readable since it's all on one line in my previous comment) -

resourceFilters=[node_modules, .metadata, archetype-resources, META-INF/maven, runtime, env, build]

@snjeza
Copy link
Contributor

snjeza commented Oct 1, 2020

It should work. JAVA LS will use the following:

<filteredResources>
		<filter>
			<id>1601570560822</id>
			<name></name>
			<type>30</type>
			<matcher>
				<id>org.eclipse.core.resources.regexFilterMatcher</id>
				<arguments>node_modules|.metadata|archetype-resources|META-INF/maven|runtime|env|build|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
			</matcher>
		</filter>
	</filteredResources>

and skip the node_modules|.metadata|archetype-resources|META-INF/maven|runtime|env|build directories
You can check your other .project files for the filteredResources property.

Seems like the workspace refreshes before the configuration is loaded?

It is not important. Java LS (eclipse) should use the filteredResources property from .project and skip the mentioned directories when refreshing the workspace.

For example, I see Starting Java Language Server - /path/to/node_modules

Could you send whole log?

@SreenivasVRao
Copy link
Author

I think this might be a config issue on my end with emacs. I was able to work around this by changing a different part of my config, but I will share a log file when I reproduce the error reliably.

To emacs users who might come across this in the future - I found that projectile was loading these files, and filtering out using (add-to-list 'projectile-globally-ignored-directories "*node_modules") or something similar works and prevents indexing from the server. (The * is necessary in my experience).

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

Successfully merging a pull request may close this issue.

4 participants