From 8c3e2d75576b8f734a981cfd9cbdb10c2a51d04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20F=C3=BCcher?= Date: Mon, 31 Mar 2025 16:54:21 -0300 Subject: [PATCH 01/18] add intellij integration test structure --- .github/workflows/test.yaml | 40 +++++++++++++++++++ bb.edn | 1 + build.gradle.kts | 38 +++++++++++++++++- src/scripts/scripts.clj | 3 ++ .../github/clojure_lsp/intellij/foo_test.clj | 9 +++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yaml create mode 100644 src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..c5eaab1 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,40 @@ +name: Tests +on: + pull_request: + +permissions: + contents: read + checks: write + pull-requests: write + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 + cache: 'gradle' + + - name: Install Clojure + uses: DeLaGuardo/setup-clojure@master + with: + bb: '1.12.196' + cli: 1.12.0.1530 + + - name: Run tests + run: ./gradlew test + + - name: Publish Test Report + uses: mikepenz/action-junit-report@v5 + if: success() || failure() # always run even if the previous step fails + with: + report_paths: '**/build/test-results/test/TEST-*.xml' + simplified_summary: true + comment: true diff --git a/bb.edn b/bb.edn index eb8be09..0026ff5 100644 --- a/bb.edn +++ b/bb.edn @@ -1,5 +1,6 @@ {:paths ["src/scripts"] :tasks {tag scripts/tag build-plugin scripts/build-plugin + test scripts/tests install-plugin scripts/install-plugin publish-plugin scripts/publish-plugin}} diff --git a/build.gradle.kts b/build.gradle.kts index 131a52b..380388c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,18 +35,24 @@ repositories { dependencies { implementation ("org.clojure:clojure:1.12.0") - implementation ("com.github.ericdallo:clj4intellij:0.7.1") + implementation ("com.github.ericdallo:clj4intellij:0.8.0") implementation ("seesaw:seesaw:1.5.0") implementation ("camel-snake-kebab:camel-snake-kebab:0.4.3") implementation ("com.rpl:proxy-plus:0.0.9") implementation ("dev.weavejester:cljfmt:0.13.0") implementation ("com.github.clojure-lsp:clojure-lsp:2025.01.22-23.28.23") + implementation ("nrepl:nrepl:1.3.1") + + testImplementation("junit:junit:latest.release") + testImplementation("org.junit.platform:junit-platform-launcher:latest.release") + testRuntimeOnly ("dev.clojurephant:jovial:0.4.2") } sourceSets { main { java.srcDirs("src/main", "src/gen") if (project.gradle.startParameter.taskNames.contains("buildPlugin") || + project.gradle.startParameter.taskNames.contains("clojureRepl") || project.gradle.startParameter.taskNames.contains("runIde")) { resources.srcDirs("src/main/dev-resources") } @@ -146,6 +152,10 @@ tasks { systemProperty("jb.consents.confirmation.enabled", "false") } + test { + systemProperty("idea.mimic.jar.url.connection", "true") + } + signPlugin { certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) privateKey.set(System.getenv("PRIVATE_KEY")) @@ -165,6 +175,26 @@ tasks { enabled = false } + clojureRepl { + dependsOn("compileClojure") + classpath.from(sourceSets.main.get().runtimeClasspath + + file("build/classes/kotlin/main") + + file("build/clojure/main") + ) + // doFirst { + // println(classpath.asPath) + // } + forkOptions.jvmArgs = listOf("--add-opens=java.desktop/java.awt=ALL-UNNAMED", + "--add-opens=java.desktop/java.awt.event=ALL-UNNAMED", + "--add-opens=java.desktop/sun.awt=ALL-UNNAMED", + "--add-opens=java.desktop/sun.font=ALL-UNNAMED", + "--add-opens=java.base/java.lang=ALL-UNNAMED", + "-Djava.system.class.loader=com.intellij.util.lang.PathClassLoader", + "-Didea.mimic.jar.url.connection=true", + "-Didea.force.use.core.classloader=true" + ) + } + generateParser { source.set("src/main/gramar/clojure.bnf") targetRoot.set("src/gen") @@ -180,6 +210,10 @@ tasks { } } +tasks.withType().configureEach { + useJUnitPlatform() +} + grammarKit { jflexRelease.set("1.7.0-1") grammarKitRelease.set("2021.1.2") @@ -187,7 +221,7 @@ grammarKit { } clojure.builds.named("main") { - classpath.from(sourceSets.main.get().runtimeClasspath.asPath) + classpath.from(sourceSets.main.get().runtimeClasspath.asPath + "build/classes/kotlin/main") checkAll() aotAll() reflection.set("fail") diff --git a/src/scripts/scripts.clj b/src/scripts/scripts.clj index be98fe9..b4ca30d 100644 --- a/src/scripts/scripts.clj +++ b/src/scripts/scripts.clj @@ -35,6 +35,9 @@ (shell "git push origin HEAD") (shell "git push origin --tags")) +(defn tests [] + (shell "./gradlew test")) + #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} (defn build-plugin [] (shell "./gradlew buildPlugin")) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj new file mode 100644 index 0000000..6348234 --- /dev/null +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -0,0 +1,9 @@ +(ns com.github.clojure-lsp.intellij.foo-test + (:require + [clojure.test :refer [deftest is testing]])) + +(set! *warn-on-reflection* true) + +(deftest foo + (testing "foo" + (is false))) From bfa026ca630a61cbb24bdf616a60daa6040e3ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20F=C3=BCcher?= Date: Tue, 1 Apr 2025 11:59:06 -0300 Subject: [PATCH 02/18] configure testdata and assert files --- .../github/clojure_lsp/intellij/foo_test.clj | 39 +++++++++++++++++-- testdata/foo.clj | 3 ++ testdata/foo_expected.clj | 3 ++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 testdata/foo.clj create mode 100644 testdata/foo_expected.clj diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index 6348234..c263a11 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -1,9 +1,42 @@ (ns com.github.clojure-lsp.intellij.foo-test (:require - [clojure.test :refer [deftest is testing]])) + [clojure.test :refer [deftest is]] + [com.github.ericdallo.clj4intellij.app-manager :as app-manager] + [com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) + (:import + [com.intellij.openapi.wm WindowManager])) (set! *warn-on-reflection* true) -(deftest foo - (testing "foo" + +(defn get-status-bar-widget [project widget-id] + (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] + (.getWidget status-bar widget-id))) + +(deftest foo-test + (let [project-name "clojure.core" + fixture (clj4intellij.test/setup project-name) + deps-file (.createFile fixture "deps.edn" "{}") + _ (.setTestDataPath fixture "testdata") + clj-file (.copyFileToProject fixture "foo.clj") + project (.getProject fixture)] + (is (= project-name (.getName project))) + (is deps-file) + + (app-manager/write-command-action + project + (fn [] (.openFileInEditor fixture clj-file))) + + (clj4intellij.test/dispatch-all) + + @(app-manager/invoke-later! + {:invoke-fn (fn [] + (let [widget (get-status-bar-widget project "ClojureLSPStatusBar")] + (println "Widget:" widget) + (is (some? widget))))}) + + (.checkResultByFile fixture "foo_expected.clj") + (is false))) + + diff --git a/testdata/foo.clj b/testdata/foo.clj new file mode 100644 index 0000000..6d8c33b --- /dev/null +++ b/testdata/foo.clj @@ -0,0 +1,3 @@ +(ns foo) + +(println "Oiii") diff --git a/testdata/foo_expected.clj b/testdata/foo_expected.clj new file mode 100644 index 0000000..8f915d5 --- /dev/null +++ b/testdata/foo_expected.clj @@ -0,0 +1,3 @@ +(ns foo) + +(println "Olaa") From 0c28fcd75c8af0f9b374035f155b9af354567882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20F=C3=BCcher?= Date: Tue, 1 Apr 2025 14:26:20 -0300 Subject: [PATCH 03/18] try to execute slurp action --- .../github/clojure_lsp/intellij/foo_test.clj | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index c263a11..04a51a1 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -4,7 +4,9 @@ [com.github.ericdallo.clj4intellij.app-manager :as app-manager] [com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) (:import - [com.intellij.openapi.wm WindowManager])) + [com.intellij.openapi.wm WindowManager] + [com.intellij.openapi.actionSystem ActionManager] + [com.intellij.ide DataManager])) (set! *warn-on-reflection* true) @@ -13,6 +15,22 @@ (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] (.getWidget status-bar widget-id))) + +(defn run-editor-action [action-id project] + (let [action (.getAction (ActionManager/getInstance) action-id) + context (.getDataContext (DataManager/getInstance))] + + + (println "Running action:" action-id) + (println "Action:" action) + (app-manager/write-command-action + project + (fn [] + (.actionPerformed + action + (com.intellij.openapi.actionSystem.AnActionEvent/createFromDataContext action-id nil context)))))) + + (deftest foo-test (let [project-name "clojure.core" fixture (clj4intellij.test/setup project-name) @@ -27,7 +45,11 @@ project (fn [] (.openFileInEditor fixture clj-file))) + + (clj4intellij.test/dispatch-all) + (println "OLAAAA >> ") + (run-editor-action "ClojureLSP.ForwardSlurp" project) @(app-manager/invoke-later! {:invoke-fn (fn [] From f67bb030f8c3117a3fa7bf576dc85578b52a2888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20F=C3=BCcher?= Date: Wed, 2 Apr 2025 13:41:03 -0300 Subject: [PATCH 04/18] set lsp server path --- .../github/clojure_lsp/intellij/foo_test.clj | 31 ++++++++++++++++--- testdata/foo.clj | 2 +- testdata/foo_expected.clj | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index 04a51a1..1bbc5f5 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -1,12 +1,18 @@ (ns com.github.clojure-lsp.intellij.foo-test (:require + [clojure.java.io :as io] [clojure.test :refer [deftest is]] + [com.github.clojure-lsp.intellij.client :as lsp-client] + [com.github.clojure-lsp.intellij.db :as db] + [com.github.clojure-lsp.intellij.server :as server] [com.github.ericdallo.clj4intellij.app-manager :as app-manager] [com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) (:import - [com.intellij.openapi.wm WindowManager] + [com.github.clojure_lsp.intellij.extension SettingsState] + [com.intellij.ide DataManager] [com.intellij.openapi.actionSystem ActionManager] - [com.intellij.ide DataManager])) + [com.intellij.openapi.components ServiceManager] + [com.intellij.openapi.wm WindowManager])) (set! *warn-on-reflection* true) @@ -45,10 +51,27 @@ project (fn [] (.openFileInEditor fixture clj-file))) + ;; Para configurações persistentes via ServiceManager + (let [my-settings (ServiceManager/getService SettingsState)] ;; Substitua pela classe real + (.setServerPath my-settings "/tmp/clojure-lsp") ;; Atualiza o caminho do servidor + (.loadState my-settings my-settings));; Atualiza estado + (println "LSP exists? >> ") + (println (.exists (io/as-file "/tmp/clojure-lsp"))) + (server/start! project) + + #_(clj4intellij.test/dispatch-all) + (println "status LSP >> ") + (println (lsp-client/server-status project)) + (println (db/get-in project [:status])) + (Thread/sleep 10000) + #_(clj4intellij.test/dispatch-all-until + {:cond-fn (fn [] (= (db/get-in project [:status]) :started)) + :millis 3000}) + (println "status LSP >> ") + (println (lsp-client/server-status project)) + (println (db/get-in project [:status])) - (clj4intellij.test/dispatch-all) - (println "OLAAAA >> ") (run-editor-action "ClojureLSP.ForwardSlurp" project) @(app-manager/invoke-later! diff --git a/testdata/foo.clj b/testdata/foo.clj index 6d8c33b..bc2f98f 100644 --- a/testdata/foo.clj +++ b/testdata/foo.clj @@ -1,3 +1,3 @@ (ns foo) -(println "Oiii") +(println) "Oiii" diff --git a/testdata/foo_expected.clj b/testdata/foo_expected.clj index 8f915d5..6d8c33b 100644 --- a/testdata/foo_expected.clj +++ b/testdata/foo_expected.clj @@ -1,3 +1,3 @@ (ns foo) -(println "Olaa") +(println "Oiii") From 6e9c6400cb2b0bf6c305ffb72cedd6cc5bcec88f Mon Sep 17 00:00:00 2001 From: Marlon Silva Date: Wed, 2 Apr 2025 14:39:05 -0300 Subject: [PATCH 05/18] interacting with editor - wip --- .../github/clojure_lsp/intellij/foo_test.clj | 17 ++++++++++++++--- testdata/foo.clj | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index 1bbc5f5..17a2f7d 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -12,7 +12,8 @@ [com.intellij.ide DataManager] [com.intellij.openapi.actionSystem ActionManager] [com.intellij.openapi.components ServiceManager] - [com.intellij.openapi.wm WindowManager])) + [com.intellij.openapi.wm WindowManager] + [com.intellij.testFramework EditorTestUtil])) (set! *warn-on-reflection* true) @@ -21,6 +22,14 @@ (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] (.getWidget status-bar widget-id))) +(defn ensure-editor + "Ensure the editor was created in the UI thread" + [project] + (let [repl-content (repl-content project)] + @(app-manager/invoke-later! + {:invoke-fn (fn [] + (.addNotify repl-content) + (.getEditor repl-content true))}))) (defn run-editor-action [action-id project] (let [action (.getAction (ActionManager/getInstance) action-id) @@ -43,7 +52,8 @@ deps-file (.createFile fixture "deps.edn" "{}") _ (.setTestDataPath fixture "testdata") clj-file (.copyFileToProject fixture "foo.clj") - project (.getProject fixture)] + project (.getProject fixture) + editor (.getEditor fixture)] (is (= project-name (.getName project))) (is deps-file) @@ -71,7 +81,8 @@ (println (lsp-client/server-status project)) (println (db/get-in project [:status])) - + (println "editor >> ") + (println editor) (run-editor-action "ClojureLSP.ForwardSlurp" project) @(app-manager/invoke-later! diff --git a/testdata/foo.clj b/testdata/foo.clj index bc2f98f..652f9b2 100644 --- a/testdata/foo.clj +++ b/testdata/foo.clj @@ -1,3 +1,3 @@ (ns foo) -(println) "Oiii" +(println) "Oiii" From ca386448d9bc02628893b70dda64f8c8f56cdc6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20F=C3=BCcher?= Date: Wed, 2 Apr 2025 15:16:52 -0300 Subject: [PATCH 06/18] executa slurp e valida arquivo --- .../github/clojure_lsp/intellij/foo_test.clj | 39 ++++++++++++------- testdata/foo.clj | 2 +- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index 17a2f7d..1c9972d 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -12,8 +12,8 @@ [com.intellij.ide DataManager] [com.intellij.openapi.actionSystem ActionManager] [com.intellij.openapi.components ServiceManager] - [com.intellij.openapi.wm WindowManager] - [com.intellij.testFramework EditorTestUtil])) + [com.intellij.openapi.editor LogicalPosition] + [com.intellij.openapi.wm WindowManager])) (set! *warn-on-reflection* true) @@ -22,15 +22,6 @@ (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] (.getWidget status-bar widget-id))) -(defn ensure-editor - "Ensure the editor was created in the UI thread" - [project] - (let [repl-content (repl-content project)] - @(app-manager/invoke-later! - {:invoke-fn (fn [] - (.addNotify repl-content) - (.getEditor repl-content true))}))) - (defn run-editor-action [action-id project] (let [action (.getAction (ActionManager/getInstance) action-id) context (.getDataContext (DataManager/getInstance))] @@ -52,8 +43,7 @@ deps-file (.createFile fixture "deps.edn" "{}") _ (.setTestDataPath fixture "testdata") clj-file (.copyFileToProject fixture "foo.clj") - project (.getProject fixture) - editor (.getEditor fixture)] + project (.getProject fixture)] (is (= project-name (.getName project))) (is deps-file) @@ -81,10 +71,29 @@ (println (lsp-client/server-status project)) (println (db/get-in project [:status])) - (println "editor >> ") - (println editor) + (let [editor (.getEditor fixture) + document (.getDocument editor) + offset (.getLineStartOffset document 2) + caret (.getCaretModel editor) + pos (.getLogicalPosition caret) + new-position (LogicalPosition. 2 8)] + (println "editor >> ") + (println editor) + (println caret) + (println pos) + (println (.getVisualPosition caret)) + (println (.getText document)) + @(app-manager/invoke-later! + {:invoke-fn (fn [] + #_(.moveToOffset caret (+ offset 9)) + (.moveToLogicalPosition caret new-position))}) + (println (.getLogicalPosition caret)) + (println (.getVisualPosition caret))) (run-editor-action "ClojureLSP.ForwardSlurp" project) + (clj4intellij.test/dispatch-all) + (println (-> fixture .getEditor .getDocument .getText)) + @(app-manager/invoke-later! {:invoke-fn (fn [] (let [widget (get-status-bar-widget project "ClojureLSPStatusBar")] diff --git a/testdata/foo.clj b/testdata/foo.clj index 652f9b2..bc2f98f 100644 --- a/testdata/foo.clj +++ b/testdata/foo.clj @@ -1,3 +1,3 @@ (ns foo) -(println) "Oiii" +(println) "Oiii" From 2bf2a0103b8dbf6f32841c366854d20be028ce78 Mon Sep 17 00:00:00 2001 From: Marlon Silva Date: Fri, 4 Apr 2025 16:24:27 -0300 Subject: [PATCH 07/18] fix dispatch-all-until --- .../github/clojure_lsp/intellij/foo_test.clj | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index 1c9972d..74c6c72 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -17,6 +17,31 @@ (set! *warn-on-reflection* true) +(defn dispatch-all-until + [{:keys [project millis timeout] + :or {millis 1000 + timeout 10000}}] + (let [start-time (System/currentTimeMillis)] + (loop [] + (let [current-time (System/currentTimeMillis) + elapsed-time (- current-time start-time) + _ (println "Elapsed time >> "elapsed-time) + status (lsp-client/server-status project)] + (cond + (>= elapsed-time timeout) + (throw (ex-info "LSP server failed to start within timeout" + {:elapsed-time elapsed-time + :final-status status})) + + (= status :started) + true + + :else + (do + (clj4intellij.test/dispatch-all) + (Thread/sleep millis) + (recur))))))) + (defn get-status-bar-widget [project widget-id] (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] @@ -25,8 +50,6 @@ (defn run-editor-action [action-id project] (let [action (.getAction (ActionManager/getInstance) action-id) context (.getDataContext (DataManager/getInstance))] - - (println "Running action:" action-id) (println "Action:" action) (app-manager/write-command-action @@ -53,20 +76,24 @@ ;; Para configurações persistentes via ServiceManager (let [my-settings (ServiceManager/getService SettingsState)] ;; Substitua pela classe real - (.setServerPath my-settings "/tmp/clojure-lsp") ;; Atualiza o caminho do servidor + #_(.setServerPath my-settings "/tmp/clojure-lsp") ;; Atualiza o caminho do servidor (.loadState my-settings my-settings));; Atualiza estado (println "LSP exists? >> ") - (println (.exists (io/as-file "/tmp/clojure-lsp"))) - (server/start! project) + #_(println (.exists (io/as-file "/tmp/clojure-lsp"))) + #_(server/start! project) - #_(clj4intellij.test/dispatch-all) + (clj4intellij.test/dispatch-all) (println "status LSP >> ") (println (lsp-client/server-status project)) (println (db/get-in project [:status])) - (Thread/sleep 10000) - #_(clj4intellij.test/dispatch-all-until - {:cond-fn (fn [] (= (db/get-in project [:status]) :started)) - :millis 3000}) + #_(Thread/sleep 10000) + (dispatch-all-until {:project project}) + #_(dispatch-all-until + {:cond-fn (fn [] + (let [status (lsp-client/server-status project)] + (println "Current status:" status) + (= status :started))) + :millis 1000}) (println "status LSP >> ") (println (lsp-client/server-status project)) (println (db/get-in project [:status])) @@ -94,14 +121,13 @@ (clj4intellij.test/dispatch-all) (println (-> fixture .getEditor .getDocument .getText)) - @(app-manager/invoke-later! + #_@(app-manager/invoke-later! {:invoke-fn (fn [] (let [widget (get-status-bar-widget project "ClojureLSPStatusBar")] (println "Widget:" widget) (is (some? widget))))}) (.checkResultByFile fixture "foo_expected.clj") - - (is false))) + (server/shutdown! project))) From 169b1ac71cae3ff0dcbe0e9ef966d778ca9e3d68 Mon Sep 17 00:00:00 2001 From: Marlon Silva Date: Fri, 4 Apr 2025 17:00:13 -0300 Subject: [PATCH 08/18] remove unnecessary lines --- .../github/clojure_lsp/intellij/foo_test.clj | 43 +++---------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index 74c6c72..0d2376b 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -51,7 +51,6 @@ (let [action (.getAction (ActionManager/getInstance) action-id) context (.getDataContext (DataManager/getInstance))] (println "Running action:" action-id) - (println "Action:" action) (app-manager/write-command-action project (fn [] @@ -76,57 +75,25 @@ ;; Para configurações persistentes via ServiceManager (let [my-settings (ServiceManager/getService SettingsState)] ;; Substitua pela classe real - #_(.setServerPath my-settings "/tmp/clojure-lsp") ;; Atualiza o caminho do servidor (.loadState my-settings my-settings));; Atualiza estado - (println "LSP exists? >> ") - #_(println (.exists (io/as-file "/tmp/clojure-lsp"))) - #_(server/start! project) - - (clj4intellij.test/dispatch-all) - (println "status LSP >> ") - (println (lsp-client/server-status project)) - (println (db/get-in project [:status])) - #_(Thread/sleep 10000) + + (clj4intellij.test/dispatch-all) (dispatch-all-until {:project project}) - #_(dispatch-all-until - {:cond-fn (fn [] - (let [status (lsp-client/server-status project)] - (println "Current status:" status) - (= status :started))) - :millis 1000}) - (println "status LSP >> ") - (println (lsp-client/server-status project)) - (println (db/get-in project [:status])) - + (println "status LSP >> " (db/get-in project [:status])) (let [editor (.getEditor fixture) document (.getDocument editor) offset (.getLineStartOffset document 2) caret (.getCaretModel editor) pos (.getLogicalPosition caret) new-position (LogicalPosition. 2 8)] - (println "editor >> ") - (println editor) - (println caret) - (println pos) - (println (.getVisualPosition caret)) (println (.getText document)) @(app-manager/invoke-later! {:invoke-fn (fn [] #_(.moveToOffset caret (+ offset 9)) - (.moveToLogicalPosition caret new-position))}) - (println (.getLogicalPosition caret)) - (println (.getVisualPosition caret))) + (.moveToLogicalPosition caret new-position))})) (run-editor-action "ClojureLSP.ForwardSlurp" project) - (clj4intellij.test/dispatch-all) - (println (-> fixture .getEditor .getDocument .getText)) - - #_@(app-manager/invoke-later! - {:invoke-fn (fn [] - (let [widget (get-status-bar-widget project "ClojureLSPStatusBar")] - (println "Widget:" widget) - (is (some? widget))))}) - + (println (-> fixture .getEditor .getDocument .getText)) (.checkResultByFile fixture "foo_expected.clj") (server/shutdown! project))) From 27f71ed0067a0451d9ad73bba253e7c981cd4684 Mon Sep 17 00:00:00 2001 From: Marlon Silva Date: Fri, 4 Apr 2025 18:07:24 -0300 Subject: [PATCH 09/18] refactoring tests - wip --- .../github/clojure_lsp/intellij/foo_test.clj | 54 +++---------------- .../clojure_lsp/intellij/test_utils.clj | 51 ++++++++++++++++++ 2 files changed, 59 insertions(+), 46 deletions(-) create mode 100644 src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index 0d2376b..a8ed0bd 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -1,62 +1,24 @@ (ns com.github.clojure-lsp.intellij.foo-test (:require - [clojure.java.io :as io] [clojure.test :refer [deftest is]] - [com.github.clojure-lsp.intellij.client :as lsp-client] [com.github.clojure-lsp.intellij.db :as db] [com.github.clojure-lsp.intellij.server :as server] + [com.github.clojure-lsp.intellij.test-utils :as test-utils] [com.github.ericdallo.clj4intellij.app-manager :as app-manager] [com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) (:import - [com.github.clojure_lsp.intellij.extension SettingsState] - [com.intellij.ide DataManager] - [com.intellij.openapi.actionSystem ActionManager] + [com.github.clojure_lsp.intellij.extension SettingsState] [com.intellij.openapi.components ServiceManager] - [com.intellij.openapi.editor LogicalPosition] - [com.intellij.openapi.wm WindowManager])) + [com.intellij.openapi.editor LogicalPosition])) (set! *warn-on-reflection* true) -(defn dispatch-all-until - [{:keys [project millis timeout] - :or {millis 1000 - timeout 10000}}] - (let [start-time (System/currentTimeMillis)] - (loop [] - (let [current-time (System/currentTimeMillis) - elapsed-time (- current-time start-time) - _ (println "Elapsed time >> "elapsed-time) - status (lsp-client/server-status project)] - (cond - (>= elapsed-time timeout) - (throw (ex-info "LSP server failed to start within timeout" - {:elapsed-time elapsed-time - :final-status status})) - - (= status :started) - true - - :else - (do - (clj4intellij.test/dispatch-all) - (Thread/sleep millis) - (recur))))))) -(defn get-status-bar-widget [project widget-id] - (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] - (.getWidget status-bar widget-id))) -(defn run-editor-action [action-id project] - (let [action (.getAction (ActionManager/getInstance) action-id) - context (.getDataContext (DataManager/getInstance))] - (println "Running action:" action-id) - (app-manager/write-command-action - project - (fn [] - (.actionPerformed - action - (com.intellij.openapi.actionSystem.AnActionEvent/createFromDataContext action-id nil context)))))) + + + (deftest foo-test @@ -78,7 +40,7 @@ (.loadState my-settings my-settings));; Atualiza estado (clj4intellij.test/dispatch-all) - (dispatch-all-until {:project project}) + (test-utils/dispatch-all-until {:project project}) (println "status LSP >> " (db/get-in project [:status])) (let [editor (.getEditor fixture) document (.getDocument editor) @@ -91,7 +53,7 @@ {:invoke-fn (fn [] #_(.moveToOffset caret (+ offset 9)) (.moveToLogicalPosition caret new-position))})) - (run-editor-action "ClojureLSP.ForwardSlurp" project) + (test-utils/run-editor-action "ClojureLSP.ForwardSlurp" project) (clj4intellij.test/dispatch-all) (println (-> fixture .getEditor .getDocument .getText)) (.checkResultByFile fixture "foo_expected.clj") diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj new file mode 100644 index 0000000..ac26bc6 --- /dev/null +++ b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj @@ -0,0 +1,51 @@ +(ns com.github.clojure-lsp.intellij.test-utils + (:require + [com.github.clojure-lsp.intellij.client :as lsp-client] + [com.github.ericdallo.clj4intellij.app-manager :as app-manager] + [com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) + (:import + [com.intellij.openapi.wm WindowManager] + [com.intellij.ide DataManager] + [com.intellij.openapi.actionSystem ActionManager])) + +(set! *warn-on-reflection* true) + +(defn get-status-bar-widget [project widget-id] + (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] + (.getWidget status-bar widget-id))) + +(defn run-editor-action [action-id project] + (let [action (.getAction (ActionManager/getInstance) action-id) + context (.getDataContext (DataManager/getInstance))] + (println "Running action:" action-id) + (app-manager/write-command-action + project + (fn [] + (.actionPerformed + action + (com.intellij.openapi.actionSystem.AnActionEvent/createFromDataContext action-id nil context)))))) + +(defn dispatch-all-until + [{:keys [project millis timeout] + :or {millis 1000 + timeout 10000}}] + (let [start-time (System/currentTimeMillis)] + (loop [] + (let [current-time (System/currentTimeMillis) + elapsed-time (- current-time start-time) + _ (println "Elapsed time >> " elapsed-time) + status (lsp-client/server-status project)] + (cond + (>= elapsed-time timeout) + (throw (ex-info "LSP server failed to start within timeout" + {:elapsed-time elapsed-time + :final-status status})) + + (= status :started) + true + + :else + (do + (clj4intellij.test/dispatch-all) + (Thread/sleep millis) + (recur))))))) \ No newline at end of file From c7a5da936d25038c7e21e635dc696a54b1345d30 Mon Sep 17 00:00:00 2001 From: Marlon Silva Date: Mon, 7 Apr 2025 16:25:28 -0300 Subject: [PATCH 10/18] adding --debug to test.yaml --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c5eaab1..14c2965 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,7 +29,7 @@ jobs: cli: 1.12.0.1530 - name: Run tests - run: ./gradlew test + run: ./gradlew test --debug - name: Publish Test Report uses: mikepenz/action-junit-report@v5 From e0fc2a7da4e2728c0274c250c8650dc1edf170d9 Mon Sep 17 00:00:00 2001 From: Marlon Silva Date: Mon, 7 Apr 2025 16:33:44 -0300 Subject: [PATCH 11/18] bump LSP4IJ version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 380388c..99937cc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -247,6 +247,6 @@ fun fetchLatestLsp4ijNightlyVersion(): String { println("Failed to fetch LSP4IJ nightly build version: ${e.message}") } - val minVersion = "0.0.1-20231213-012910" + val minVersion = "0.11.1-20250226-013217" return if (minVersion < onlineVersion) onlineVersion else minVersion } From dcfd8c6e1121b3d2d15f623207c3e72b6c1679cf Mon Sep 17 00:00:00 2001 From: Marlon Silva Date: Mon, 7 Apr 2025 16:56:05 -0300 Subject: [PATCH 12/18] bump LSP4IJ version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 99937cc..156888f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -247,6 +247,6 @@ fun fetchLatestLsp4ijNightlyVersion(): String { println("Failed to fetch LSP4IJ nightly build version: ${e.message}") } - val minVersion = "0.11.1-20250226-013217" + val minVersion = "0.12.1-20250404-161025" return if (minVersion < onlineVersion) onlineVersion else minVersion } From ed7e2ac0b01a7947a1adb4cdcbf28fa86a3355a6 Mon Sep 17 00:00:00 2001 From: Marlon Silva Date: Tue, 8 Apr 2025 10:19:02 -0300 Subject: [PATCH 13/18] improve tests --- .../github/clojure_lsp/intellij/foo_test.clj | 60 +++------------ .../clojure_lsp/intellij/test_utils.clj | 75 +++++++++++++++++-- 2 files changed, 80 insertions(+), 55 deletions(-) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index a8ed0bd..4897a41 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -1,62 +1,24 @@ (ns com.github.clojure-lsp.intellij.foo-test (:require [clojure.test :refer [deftest is]] - [com.github.clojure-lsp.intellij.db :as db] - [com.github.clojure-lsp.intellij.server :as server] [com.github.clojure-lsp.intellij.test-utils :as test-utils] [com.github.ericdallo.clj4intellij.app-manager :as app-manager] - [com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) - (:import - [com.github.clojure_lsp.intellij.extension SettingsState] - [com.intellij.openapi.components ServiceManager] - [com.intellij.openapi.editor LogicalPosition])) + [com.github.ericdallo.clj4intellij.test :as clj4intellij.test])) (set! *warn-on-reflection* true) - - - - - - - - (deftest foo-test (let [project-name "clojure.core" - fixture (clj4intellij.test/setup project-name) - deps-file (.createFile fixture "deps.edn" "{}") - _ (.setTestDataPath fixture "testdata") - clj-file (.copyFileToProject fixture "foo.clj") - project (.getProject fixture)] + {:keys [fixture project deps-file]} (test-utils/setup-test-project project-name) + clj-file (.copyFileToProject fixture "foo.clj")] (is (= project-name (.getName project))) (is deps-file) - (app-manager/write-command-action - project - (fn [] (.openFileInEditor fixture clj-file))) - - ;; Para configurações persistentes via ServiceManager - (let [my-settings (ServiceManager/getService SettingsState)] ;; Substitua pela classe real - (.loadState my-settings my-settings));; Atualiza estado - - (clj4intellij.test/dispatch-all) - (test-utils/dispatch-all-until {:project project}) - (println "status LSP >> " (db/get-in project [:status])) - (let [editor (.getEditor fixture) - document (.getDocument editor) - offset (.getLineStartOffset document 2) - caret (.getCaretModel editor) - pos (.getLogicalPosition caret) - new-position (LogicalPosition. 2 8)] - (println (.getText document)) - @(app-manager/invoke-later! - {:invoke-fn (fn [] - #_(.moveToOffset caret (+ offset 9)) - (.moveToLogicalPosition caret new-position))})) - (test-utils/run-editor-action "ClojureLSP.ForwardSlurp" project) - (clj4intellij.test/dispatch-all) - (println (-> fixture .getEditor .getDocument .getText)) - (.checkResultByFile fixture "foo_expected.clj") - (server/shutdown! project))) - - + (let [editor (test-utils/open-file-in-editor fixture clj-file)] + (test-utils/setup-lsp-server project) + (test-utils/move-caret-to-position editor 2 8) + (test-utils/run-editor-action "ClojureLSP.ForwardSlurp" project) + (clj4intellij.test/dispatch-all) + (println (test-utils/get-editor-text fixture)) + (test-utils/check-result-by-file fixture "foo_expected.clj") + (test-utils/teardown-test-project project)))) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj index ac26bc6..d2dfb31 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj @@ -1,12 +1,17 @@ (ns com.github.clojure-lsp.intellij.test-utils (:require [com.github.clojure-lsp.intellij.client :as lsp-client] + [com.github.clojure-lsp.intellij.server :as server] [com.github.ericdallo.clj4intellij.app-manager :as app-manager] - [com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) - (:import - [com.intellij.openapi.wm WindowManager] + [com.github.ericdallo.clj4intellij.test :as clj4intellij.test] + [com.github.clojure-lsp.intellij.db :as db]) + (:import + [com.github.clojure_lsp.intellij.extension SettingsState] [com.intellij.ide DataManager] - [com.intellij.openapi.actionSystem ActionManager])) + [com.intellij.openapi.actionSystem ActionManager] + [com.intellij.openapi.components ServiceManager] + [com.intellij.openapi.editor LogicalPosition] + [com.intellij.openapi.wm WindowManager])) (set! *warn-on-reflection* true) @@ -14,7 +19,9 @@ (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] (.getWidget status-bar widget-id))) -(defn run-editor-action [action-id project] +(defn run-editor-action + "Runs an editor action with the given ID for the specified project." + [action-id project] (let [action (.getAction (ActionManager/getInstance) action-id) context (.getDataContext (DataManager/getInstance))] (println "Running action:" action-id) @@ -26,6 +33,7 @@ (com.intellij.openapi.actionSystem.AnActionEvent/createFromDataContext action-id nil context)))))) (defn dispatch-all-until + "Dispatches all events until the LSP server is started or the timeout is reached." [{:keys [project millis timeout] :or {millis 1000 timeout 10000}}] @@ -48,4 +56,59 @@ (do (clj4intellij.test/dispatch-all) (Thread/sleep millis) - (recur))))))) \ No newline at end of file + (recur))))))) + +(defn teardown-test-project + "Shuts down all resources for the given project." + [project] + (server/shutdown! project)) + +(defn setup-test-project + "Sets up a test project with the given name and optional deps.edn content. + Returns a map with :fixture, :project, and :deps-file." + ([project-name] + (setup-test-project project-name "{}")) + ([project-name deps-content] + (let [fixture (clj4intellij.test/setup project-name) + deps-file (.createFile fixture "deps.edn" deps-content) + _ (.setTestDataPath fixture "testdata") + project (.getProject fixture)] + {:fixture fixture + :project project + :deps-file deps-file}))) + +(defn open-file-in-editor + "Opens a file in the editor and returns the editor instance." + [fixture file] + (let [project (.getProject fixture)] + (app-manager/write-command-action + project + (fn [] (.openFileInEditor fixture file))) + (.getEditor fixture))) + +(defn move-caret-to-position + "Moves the caret to the specified logical position in the editor." + [editor line column] + (let [caret (.getCaretModel editor) + new-position (LogicalPosition. line column)] + @(app-manager/invoke-later! + {:invoke-fn (fn [] (.moveToLogicalPosition caret new-position))}))) + +(defn get-editor-text + "Returns the text content of the editor's document." + [fixture] + (-> fixture .getEditor .getDocument .getText)) + +(defn check-result-by-file + "Checks if the current editor content matches the expected file." + [fixture expected-file] + (.checkResultByFile fixture expected-file)) + +(defn setup-lsp-server + "Sets up and waits for the LSP server to be ready." + [project] + (let [my-settings (ServiceManager/getService SettingsState)] + (.loadState my-settings my-settings) + (clj4intellij.test/dispatch-all) + (dispatch-all-until {:project project}) + (println "status LSP >> " (db/get-in project [:status])))) \ No newline at end of file From f8c7106705b8ce7af920961351812c2fd83bbfc0 Mon Sep 17 00:00:00 2001 From: Marlon Silva Date: Mon, 14 Apr 2025 14:28:34 -0300 Subject: [PATCH 14/18] refactor some functions --- .../github/clojure_lsp/intellij/editor.clj | 13 ++++- .../github/clojure_lsp/intellij/foo_test.clj | 17 +++++-- .../clojure_lsp/intellij/test_utils.clj | 47 ++++++------------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main/clojure/com/github/clojure_lsp/intellij/editor.clj b/src/main/clojure/com/github/clojure_lsp/intellij/editor.clj index 1ae12d6..e128142 100644 --- a/src/main/clojure/com/github/clojure_lsp/intellij/editor.clj +++ b/src/main/clojure/com/github/clojure_lsp/intellij/editor.clj @@ -1,9 +1,10 @@ (ns com.github.clojure-lsp.intellij.editor (:require [com.github.clojure-lsp.intellij.db :as db] - [com.github.clojure-lsp.intellij.editor :as editor]) + [com.github.clojure-lsp.intellij.editor :as editor] + [com.github.ericdallo.clj4intellij.app-manager :as app-manager]) (:import - [com.intellij.openapi.editor Editor] + [com.intellij.openapi.editor CaretModel Editor LogicalPosition] [com.intellij.openapi.fileEditor FileDocumentManager] [com.intellij.openapi.project ProjectLocator] [com.intellij.openapi.util.text StringUtil] @@ -23,3 +24,11 @@ (defn guess-project-for [^VirtualFile file] (or (.guessProjectForFile (ProjectLocator/getInstance) file) (first (db/all-projects)))) + +(defn move-caret-to-position + "Moves the caret to the specified logical position in the editor." + [^Editor editor line column] + (let [caret ^CaretModel (.getCaretModel editor) + new-position (LogicalPosition. line column)] + @(app-manager/invoke-later! + {:invoke-fn (fn [] (.moveToLogicalPosition caret new-position))}))) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj index 4897a41..517f816 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj @@ -1,13 +1,24 @@ (ns com.github.clojure-lsp.intellij.foo-test (:require [clojure.test :refer [deftest is]] + [com.github.clojure-lsp.intellij.editor :as editor] [com.github.clojure-lsp.intellij.test-utils :as test-utils] - [com.github.ericdallo.clj4intellij.app-manager :as app-manager] [com.github.ericdallo.clj4intellij.test :as clj4intellij.test])) (set! *warn-on-reflection* true) (deftest foo-test + "Tests the Forward Slurp editor action functionality in Clojure LSP. + This test: + 1. Sets up a test project with a Clojure file + 2. Opens the file in the editor + 3. Sets up the LSP server + 4. Moves the caret to a specific position + 5. Executes the Forward Slurp action + 6. Verifies the resulting text matches the expected output + + The test ensures that the Forward Slurp action correctly modifies the code structure + by moving the closing parenthesis forward." (let [project-name "clojure.core" {:keys [fixture project deps-file]} (test-utils/setup-test-project project-name) clj-file (.copyFileToProject fixture "foo.clj")] @@ -16,9 +27,9 @@ (let [editor (test-utils/open-file-in-editor fixture clj-file)] (test-utils/setup-lsp-server project) - (test-utils/move-caret-to-position editor 2 8) + (editor/move-caret-to-position editor 2 8) (test-utils/run-editor-action "ClojureLSP.ForwardSlurp" project) (clj4intellij.test/dispatch-all) (println (test-utils/get-editor-text fixture)) - (test-utils/check-result-by-file fixture "foo_expected.clj") + (.checkResultByFile fixture "foo_expected.clj") (test-utils/teardown-test-project project)))) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj index d2dfb31..3a1f58c 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj @@ -9,15 +9,23 @@ [com.github.clojure_lsp.intellij.extension SettingsState] [com.intellij.ide DataManager] [com.intellij.openapi.actionSystem ActionManager] - [com.intellij.openapi.components ServiceManager] - [com.intellij.openapi.editor LogicalPosition] - [com.intellij.openapi.wm WindowManager])) + [com.intellij.openapi.components ServiceManager])) (set! *warn-on-reflection* true) -(defn get-status-bar-widget [project widget-id] - (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] - (.getWidget status-bar widget-id))) +(defn get-editor-text + "Returns the text content of the editor's document." + [fixture] + (-> fixture .getEditor .getDocument .getText)) + +(defn open-file-in-editor + "Opens a file in the editor and returns the editor instance." + [fixture file] + (let [project (.getProject fixture)] + (app-manager/write-command-action + project + (fn [] (.openFileInEditor fixture file))) + (.getEditor fixture))) (defn run-editor-action "Runs an editor action with the given ID for the specified project." @@ -77,33 +85,6 @@ :project project :deps-file deps-file}))) -(defn open-file-in-editor - "Opens a file in the editor and returns the editor instance." - [fixture file] - (let [project (.getProject fixture)] - (app-manager/write-command-action - project - (fn [] (.openFileInEditor fixture file))) - (.getEditor fixture))) - -(defn move-caret-to-position - "Moves the caret to the specified logical position in the editor." - [editor line column] - (let [caret (.getCaretModel editor) - new-position (LogicalPosition. line column)] - @(app-manager/invoke-later! - {:invoke-fn (fn [] (.moveToLogicalPosition caret new-position))}))) - -(defn get-editor-text - "Returns the text content of the editor's document." - [fixture] - (-> fixture .getEditor .getDocument .getText)) - -(defn check-result-by-file - "Checks if the current editor content matches the expected file." - [fixture expected-file] - (.checkResultByFile fixture expected-file)) - (defn setup-lsp-server "Sets up and waits for the LSP server to be ready." [project] From d97d808c065bea5b282fbcfe080bdd95d3c0dffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20F=C3=BCcher?= Date: Tue, 22 Apr 2025 14:22:50 -0300 Subject: [PATCH 15/18] disable comment from test report --- .github/workflows/test.yaml | 2 +- .../{foo_test.clj => slurp_action_test.clj} | 15 +++++++++------ .../github/clojure_lsp/intellij/test_utils.clj | 18 ++++++++---------- 3 files changed, 18 insertions(+), 17 deletions(-) rename src/test/clojure/com/github/clojure_lsp/intellij/{foo_test.clj => slurp_action_test.clj} (75%) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 14c2965..ad055c3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,4 +37,4 @@ jobs: with: report_paths: '**/build/test-results/test/TEST-*.xml' simplified_summary: true - comment: true + comment: false diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj similarity index 75% rename from src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj rename to src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj index 517f816..85e1dcc 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj @@ -1,13 +1,16 @@ -(ns com.github.clojure-lsp.intellij.foo-test +(ns com.github.clojure-lsp.intellij.slurp-action-test (:require [clojure.test :refer [deftest is]] [com.github.clojure-lsp.intellij.editor :as editor] [com.github.clojure-lsp.intellij.test-utils :as test-utils] - [com.github.ericdallo.clj4intellij.test :as clj4intellij.test])) + [com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) + (:import + [com.intellij.openapi.project Project] + [com.intellij.testFramework.fixtures CodeInsightTestFixture])) (set! *warn-on-reflection* true) -(deftest foo-test +(deftest slurp-action-test "Tests the Forward Slurp editor action functionality in Clojure LSP. This test: 1. Sets up a test project with a Clojure file @@ -21,8 +24,8 @@ by moving the closing parenthesis forward." (let [project-name "clojure.core" {:keys [fixture project deps-file]} (test-utils/setup-test-project project-name) - clj-file (.copyFileToProject fixture "foo.clj")] - (is (= project-name (.getName project))) + clj-file (.copyFileToProject ^CodeInsightTestFixture fixture "foo.clj")] + (is (= project-name (.getName ^Project project))) (is deps-file) (let [editor (test-utils/open-file-in-editor fixture clj-file)] @@ -31,5 +34,5 @@ (test-utils/run-editor-action "ClojureLSP.ForwardSlurp" project) (clj4intellij.test/dispatch-all) (println (test-utils/get-editor-text fixture)) - (.checkResultByFile fixture "foo_expected.clj") + (.checkResultByFile ^CodeInsightTestFixture fixture "foo_expected.clj") (test-utils/teardown-test-project project)))) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj index 3a1f58c..f04d0c1 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj @@ -1,26 +1,26 @@ -(ns com.github.clojure-lsp.intellij.test-utils +(ns com.github.clojure-lsp.intellij.test-utils (:require [com.github.clojure-lsp.intellij.client :as lsp-client] [com.github.clojure-lsp.intellij.server :as server] [com.github.ericdallo.clj4intellij.app-manager :as app-manager] - [com.github.ericdallo.clj4intellij.test :as clj4intellij.test] - [com.github.clojure-lsp.intellij.db :as db]) + [com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) (:import [com.github.clojure_lsp.intellij.extension SettingsState] [com.intellij.ide DataManager] [com.intellij.openapi.actionSystem ActionManager] - [com.intellij.openapi.components ServiceManager])) + [com.intellij.openapi.components ServiceManager] + [com.intellij.testFramework.fixtures CodeInsightTestFixture])) (set! *warn-on-reflection* true) (defn get-editor-text "Returns the text content of the editor's document." - [fixture] + [^CodeInsightTestFixture fixture] (-> fixture .getEditor .getDocument .getText)) (defn open-file-in-editor "Opens a file in the editor and returns the editor instance." - [fixture file] + [^CodeInsightTestFixture fixture file] (let [project (.getProject fixture)] (app-manager/write-command-action project @@ -40,7 +40,7 @@ action (com.intellij.openapi.actionSystem.AnActionEvent/createFromDataContext action-id nil context)))))) -(defn dispatch-all-until +(defn wait-lsp-start "Dispatches all events until the LSP server is started or the timeout is reached." [{:keys [project millis timeout] :or {millis 1000 @@ -49,7 +49,6 @@ (loop [] (let [current-time (System/currentTimeMillis) elapsed-time (- current-time start-time) - _ (println "Elapsed time >> " elapsed-time) status (lsp-client/server-status project)] (cond (>= elapsed-time timeout) @@ -91,5 +90,4 @@ (let [my-settings (ServiceManager/getService SettingsState)] (.loadState my-settings my-settings) (clj4intellij.test/dispatch-all) - (dispatch-all-until {:project project}) - (println "status LSP >> " (db/get-in project [:status])))) \ No newline at end of file + (wait-lsp-start {:project project}))) From f6597fb3c4dd123241ed8e7e88dc46eb772386ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20F=C3=BCcher?= Date: Tue, 22 Apr 2025 14:26:30 -0300 Subject: [PATCH 16/18] remove debug flag from test --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ad055c3..4b8de7d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,7 +29,7 @@ jobs: cli: 1.12.0.1530 - name: Run tests - run: ./gradlew test --debug + run: ./gradlew test - name: Publish Test Report uses: mikepenz/action-junit-report@v5 From 3064671db682199a16c200f80fd7f412eb5ecd7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20F=C3=BCcher?= Date: Tue, 22 Apr 2025 15:42:06 -0300 Subject: [PATCH 17/18] apply code review --- .../clojure_lsp/intellij/slurp_action_test.clj | 11 ++++++----- .../com/github/clojure_lsp/intellij/test_utils.clj | 13 ++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj index 85e1dcc..326102a 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj @@ -23,16 +23,17 @@ The test ensures that the Forward Slurp action correctly modifies the code structure by moving the closing parenthesis forward." (let [project-name "clojure.core" - {:keys [fixture project deps-file]} (test-utils/setup-test-project project-name) - clj-file (.copyFileToProject ^CodeInsightTestFixture fixture "foo.clj")] + {:keys [fixtures project deps-file]} (test-utils/setup-test-project project-name) + clj-file (.copyFileToProject ^CodeInsightTestFixture fixtures "foo.clj")] (is (= project-name (.getName ^Project project))) (is deps-file) - (let [editor (test-utils/open-file-in-editor fixture clj-file)] + (let [editor (test-utils/open-file-in-editor fixtures clj-file)] (test-utils/setup-lsp-server project) (editor/move-caret-to-position editor 2 8) (test-utils/run-editor-action "ClojureLSP.ForwardSlurp" project) (clj4intellij.test/dispatch-all) - (println (test-utils/get-editor-text fixture)) - (.checkResultByFile ^CodeInsightTestFixture fixture "foo_expected.clj") + + (.checkResultByFile ^CodeInsightTestFixture fixtures "foo_expected.clj") + (test-utils/teardown-test-project project)))) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj index f04d0c1..ef1d1a2 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj @@ -32,7 +32,6 @@ [action-id project] (let [action (.getAction (ActionManager/getInstance) action-id) context (.getDataContext (DataManager/getInstance))] - (println "Running action:" action-id) (app-manager/write-command-action project (fn [] @@ -76,18 +75,18 @@ ([project-name] (setup-test-project project-name "{}")) ([project-name deps-content] - (let [fixture (clj4intellij.test/setup project-name) - deps-file (.createFile fixture "deps.edn" deps-content) - _ (.setTestDataPath fixture "testdata") - project (.getProject fixture)] - {:fixture fixture + (let [fixtures (clj4intellij.test/setup project-name) + deps-file (.createFile fixtures "deps.edn" deps-content) + _ (.setTestDataPath fixtures "testdata") + project (.getProject fixtures)] + {:fixtures fixtures :project project :deps-file deps-file}))) (defn setup-lsp-server "Sets up and waits for the LSP server to be ready." [project] - (let [my-settings (ServiceManager/getService SettingsState)] + (let [my-settings ^SettingsState (ServiceManager/getService SettingsState)] (.loadState my-settings my-settings) (clj4intellij.test/dispatch-all) (wait-lsp-start {:project project}))) From 317502c9c7c53773be5ac2800f8af8f40acae799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20F=C3=BCcher?= Date: Tue, 22 Apr 2025 15:46:03 -0300 Subject: [PATCH 18/18] change test project name to be more explicit --- .../com/github/clojure_lsp/intellij/slurp_action_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj b/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj index 326102a..c96846c 100644 --- a/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj +++ b/src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj @@ -22,7 +22,7 @@ The test ensures that the Forward Slurp action correctly modifies the code structure by moving the closing parenthesis forward." - (let [project-name "clojure.core" + (let [project-name "clojure.sample-project" {:keys [fixtures project deps-file]} (test-utils/setup-test-project project-name) clj-file (.copyFileToProject ^CodeInsightTestFixture fixtures "foo.clj")] (is (= project-name (.getName ^Project project)))