Skip to content

Commit fabab0e

Browse files
committed
Fix usage of java.import.generatesMetadataFilesAtProjectRoot
lsp-java used to treat this as a configuration property of jdtls. However it is not a standard lsp configuration property. Instead it must be passed as a Java System Property on the command line invoking jdtls. See [JLFsUtils.java](https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFsUtils.java#L192-L197) for how this property is read. Also see [eclipse-jdtls/eclipse.jdt.ls#1900](eclipse-jdtls/eclipse.jdt.ls#1900 (comment)) for an explanation of why this is a system property and not a regular LSP configuration property. Use a regular `defcustom` instead of using `lsp-defcustom` for declaring lsp-java-import-generates-metadata-files-at-project-root. Use this defcustom variable in `lsp-java--ls-command` to pass an appropriate value for `java.import.generatesMetadataFilesAtProjectRoot`. With this change importing a Gradle-based java project into LSP will nolonger create `.classpath`, `.settings`, and `.project` entries at the root of the project.
1 parent 4909c14 commit fabab0e

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

lsp-java.el

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ deduplication with the G1 Garbage collector"
128128
:risky t
129129
:type '(repeat string))
130130

131+
(defcustom lsp-java-import-generates-metadata-files-at-project-root nil
132+
"Specify whether the project metadata files(.project, .classpath,
133+
.factorypath, .settings/) will be generated at the project root."
134+
:risky t
135+
:type 'boolean)
136+
131137
(lsp-defcustom lsp-java-errors-incomplete-classpath-severity "warning"
132138
"Specifies the severity of the message when the classpath is
133139
incomplete for a Java file"
@@ -688,7 +694,11 @@ FULL specify whether full or incremental build will be performed."
688694
lsp-java-server-config-dir
689695
(lsp-file-local-name (lsp-java--locate-server-config))))
690696
(java-9-args (when (lsp-java--java-9-plus-p)
691-
lsp-java-9-args)))
697+
lsp-java-9-args))
698+
(generate-metadata-property (if lsp-java-import-generates-metadata-files-at-project-root
699+
"-Djava.import.generatesMetadataFilesAtProjectRoot=true"
700+
"-Djava.import.generatesMetadataFilesAtProjectRoot=false"
701+
)))
692702
(lsp-java--ensure-dir lsp-java-workspace-dir)
693703
`(,lsp-java-java-path
694704
"-Declipse.application=org.eclipse.jdt.ls.core.id1"
@@ -697,6 +707,7 @@ FULL specify whether full or incremental build will be performed."
697707
"-Dlog.protocol=true"
698708
"-Dlog.level=ALL"
699709
,@lsp-java-vmargs
710+
,generate-metadata-property
700711
"-jar"
701712
,server-jar
702713
"-configuration"
@@ -1582,14 +1593,6 @@ data. Beyond this limit, cached workspace data may be removed."
15821593
:type '(repeat nil)
15831594
:lsp-path "java.configuration.workspaceCacheLimit")
15841595

1585-
(lsp-defcustom lsp-java-import-generates-metadata-files-at-project-root nil
1586-
"Specify whether the project metadata files(.project, .classpath,
1587-
.factorypath, .settings/) will be generated at the project root.
1588-
Click [HERE](command:_java.metadataFilesGeneration) to learn how
1589-
to change the setting to make it take effect."
1590-
:type 'boolean
1591-
:lsp-path "java.import.generatesMetadataFilesAtProjectRoot")
1592-
15931596
(lsp-defcustom lsp-java-project-output-path ""
15941597
"A relative path to the workspace where stores the compiled
15951598
output. `Only` effective in the `WORKSPACE` scope. The setting
@@ -1841,14 +1844,6 @@ Beyond this limit, cached workspace data may be removed."
18411844
:type '(repeat nil)
18421845
:lsp-path "java.configuration.workspaceCacheLimit")
18431846

1844-
(lsp-defcustom lsp-java-import-generates-metadata-files-at-project-root nil
1845-
"Specify whether the project metadata files(.project, .classpath,
1846-
.factorypath, .settings/) will be generated at the project root.
1847-
Click [HERE](command:_java.metadataFilesGeneration) to learn how to change the
1848-
setting to make it take effect."
1849-
:type 'boolean
1850-
:lsp-path "java.import.generatesMetadataFilesAtProjectRoot")
1851-
18521847
(lsp-defcustom lsp-java-project-output-path ""
18531848
"A relative path to the workspace where stores the compiled output.
18541849
`Only` effective in the `WORKSPACE` scope. The setting will `NOT` affect

0 commit comments

Comments
 (0)