Skip to content

Commit 2bf2a01

Browse files
committed
fix dispatch-all-until
1 parent ca38644 commit 2bf2a01

File tree

1 file changed

+39
-13
lines changed
  • src/test/clojure/com/github/clojure_lsp/intellij

1 file changed

+39
-13
lines changed

src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj

+39-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@
1717

1818
(set! *warn-on-reflection* true)
1919

20+
(defn dispatch-all-until
21+
[{:keys [project millis timeout]
22+
:or {millis 1000
23+
timeout 10000}}]
24+
(let [start-time (System/currentTimeMillis)]
25+
(loop []
26+
(let [current-time (System/currentTimeMillis)
27+
elapsed-time (- current-time start-time)
28+
_ (println "Elapsed time >> "elapsed-time)
29+
status (lsp-client/server-status project)]
30+
(cond
31+
(>= elapsed-time timeout)
32+
(throw (ex-info "LSP server failed to start within timeout"
33+
{:elapsed-time elapsed-time
34+
:final-status status}))
35+
36+
(= status :started)
37+
true
38+
39+
:else
40+
(do
41+
(clj4intellij.test/dispatch-all)
42+
(Thread/sleep millis)
43+
(recur)))))))
44+
2045

2146
(defn get-status-bar-widget [project widget-id]
2247
(let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))]
@@ -25,8 +50,6 @@
2550
(defn run-editor-action [action-id project]
2651
(let [action (.getAction (ActionManager/getInstance) action-id)
2752
context (.getDataContext (DataManager/getInstance))]
28-
29-
3053
(println "Running action:" action-id)
3154
(println "Action:" action)
3255
(app-manager/write-command-action
@@ -53,20 +76,24 @@
5376

5477
;; Para configurações persistentes via ServiceManager
5578
(let [my-settings (ServiceManager/getService SettingsState)] ;; Substitua pela classe real
56-
(.setServerPath my-settings "/tmp/clojure-lsp") ;; Atualiza o caminho do servidor
79+
#_(.setServerPath my-settings "/tmp/clojure-lsp") ;; Atualiza o caminho do servidor
5780
(.loadState my-settings my-settings));; Atualiza estado
5881
(println "LSP exists? >> ")
59-
(println (.exists (io/as-file "/tmp/clojure-lsp")))
60-
(server/start! project)
82+
#_(println (.exists (io/as-file "/tmp/clojure-lsp")))
83+
#_(server/start! project)
6184

62-
#_(clj4intellij.test/dispatch-all)
85+
(clj4intellij.test/dispatch-all)
6386
(println "status LSP >> ")
6487
(println (lsp-client/server-status project))
6588
(println (db/get-in project [:status]))
66-
(Thread/sleep 10000)
67-
#_(clj4intellij.test/dispatch-all-until
68-
{:cond-fn (fn [] (= (db/get-in project [:status]) :started))
69-
:millis 3000})
89+
#_(Thread/sleep 10000)
90+
(dispatch-all-until {:project project})
91+
#_(dispatch-all-until
92+
{:cond-fn (fn []
93+
(let [status (lsp-client/server-status project)]
94+
(println "Current status:" status)
95+
(= status :started)))
96+
:millis 1000})
7097
(println "status LSP >> ")
7198
(println (lsp-client/server-status project))
7299
(println (db/get-in project [:status]))
@@ -94,14 +121,13 @@
94121
(clj4intellij.test/dispatch-all)
95122
(println (-> fixture .getEditor .getDocument .getText))
96123

97-
@(app-manager/invoke-later!
124+
#_@(app-manager/invoke-later!
98125
{:invoke-fn (fn []
99126
(let [widget (get-status-bar-widget project "ClojureLSPStatusBar")]
100127
(println "Widget:" widget)
101128
(is (some? widget))))})
102129

103130
(.checkResultByFile fixture "foo_expected.clj")
104-
105-
(is false)))
131+
(server/shutdown! project)))
106132

107133

0 commit comments

Comments
 (0)