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

WIP monitor gradle projects with kotlin build scripts #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions features/ImportProject.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,19 @@ Feature: Importing projects
And I add project "m" folder "tmp" to the list of workspace folders
And I start lsp-java
Then The server status must become "LSP::Started"

Scenario: Gradle Groovy DSL projects
Given I have gradle groovy DSL project "m" in "tmp"
And I have a java file "tmp/m/src/main/java/temp/App.java"
And I clear the buffer
And I add project "m" folder "tmp" to the list of workspace folders
And I start lsp-java
Then The server status must become "LSP::Started"

Scenario: Gradle Kotlin DSL projects
Given I have gradle kotlin DSL project "m" in "tmp"
And I have a java file "tmp/m/src/main/java/temp/App.java"
And I clear the buffer
And I add project "m" folder "tmp" to the list of workspace folders
And I start lsp-java
Then The server status must become "LSP::Started"
39 changes: 34 additions & 5 deletions features/step-definitions/lsp-java-steps.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
(setq retry-count (1+ retry-count))
(message "The function failed, attempt %s" retry-count)))))))

(Given "^I have maven project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$"
(lambda (project-name dir-name)
(defun lsp-java-steps-project (project-name dir-name config-name config)
(setq default-directory lsp-java-test-root)

;; delete old directory
Expand All @@ -52,8 +51,12 @@
(f-join dir-name project-name "src" "main" "java" "temp")) t)

;; add pom.xml
(with-temp-file (expand-file-name "pom.xml" (f-join dir-name project-name))
(insert "
(with-temp-file (expand-file-name config-name (f-join dir-name project-name))
(insert config)))

(Given "^I have maven project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$"
(lambda (project-name dir-name)
(lsp-java-steps-project project-name dir-name "pom.xml" "
<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
<modelVersion>4.0.0</modelVersion>
Expand All @@ -68,7 +71,33 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>"))))
</project>")))

(Given "^I have gradle groovy DSL project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$"
(lambda (project-name dir-name)
(lsp-java-steps-project project-name dir-name "build.gradle" "
plugins {
id 'java'
}
repositories {
jcenter()
}
dependencies {
implementation 'com.google.guava:guava:27.0.1-jre'
}")))

(Given "^I have gradle kotlin DSL project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$"
(lambda (project-name dir-name)
(lsp-java-steps-project project-name dir-name "build.gradle.kts" "
plugins {
java
}
repositories {
jcenter()
}
dependencies {
implementation(\"com.google.guava:guava:27.0.1-jre\")
}")))

(And "^I have a java file \"\\([^\"]+\\)\"$"
(lambda (file-name)
Expand Down
12 changes: 8 additions & 4 deletions lsp-java.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ Use http://download.eclipse.org/che/che-ls-jdt/snapshots/che-jdt-language-server
"face for activity message"
:group 'lsp-java)

(defcustom lsp-java-project-types '("pom.xml" "build.gradle" "build.gradle.kts" ".project")
"File names of possible project configuration files found at project root."
:group 'lsp-java
:type '(repeat file))

(defcustom lsp-java-workspace-dir (expand-file-name (locate-user-emacs-file "workspace/"))
"LSP java workspace directory."
:group 'lsp-java
Expand Down Expand Up @@ -472,9 +477,8 @@ The current directory is assumed to be the java project’s root otherwise."
((string= default-directory lsp-java-workspace-cache-dir) default-directory)
((and (featurep 'projectile) (projectile-project-p)) (projectile-project-root))
((vc-backend default-directory) (expand-file-name (vc-root-dir)))
(t (let ((project-types '("pom.xml" "build.gradle" ".project")))
(or (seq-some (lambda (file) (locate-dominating-file default-directory file)) project-types)
default-directory)))))
(t (or (seq-some (lambda (file) (locate-dominating-file default-directory file)) lsp-java-project-types)
default-directory))))

(defun lsp-java--language-status-callback (workspace params)
"Callback for client initialized.
Expand Down Expand Up @@ -1122,7 +1126,7 @@ PROJECT-URI uri of the item."
("registerOptions" (ht ("watchers"
(vector (ht ("globPattern" "**/*.java"))
(ht ("globPattern" "**/pom.xml"))
(ht ("globPattern" "**/*.gradle"))
(ht ("globPattern" "**/*.gradle{,.kts}"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more about the testing - you may keep this line(although I am not sure whether this pattern works) and then modify the kts file(e. g. add new dependency) and then:

  1. Verify that lsp-java is sending update to the server
  2. Verify that jdt-ls is updating the workspace(you will start to receive notifications).

If 2) is not happening we have to file jdtls bug.

Copy link
Author

@lmmarsano lmmarsano May 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing happens with the line as written.
Should we consider this a bug?

As separate lines, however, client works, and server fails to update:

  • *lsp-log* shows workspace/didChangeWatchedFiles notifications
  • ~/.emacs.d/workspace/.metadata/.log shows !MESSAGE >> workspace/didChangeWatchedFiles but no message like !MESSAGE Updated java-test in 382 ms that shows with modification to groovy build files.
    When commenting out a dependency, imports continue to show as resolved in kotlin build file projects, though groovy build file projects get 'import cannot be resolved' updates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is a bug. Can you check whether the change is applied if you restart the jdt ls server? If it works, that means the problem is in jdt-ls which does not process the file notification.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change: commented out dependency still resolves after lsp-restart-workspace.
eclipse-jdtls/eclipse.jdt.ls#449 seems to indicate Kotlin build file support is missing.

(ht ("globPattern" "**/.project"))
(ht ("globPattern" "**/.classpath"))
(ht ("globPattern" "**/settings/*.prefs"))))))))))
Expand Down