|
1 | 1 | (ns com.github.clojure-lsp.intellij.foo-test
|
2 | 2 | (:require
|
3 |
| - [clojure.java.io :as io] |
4 | 3 | [clojure.test :refer [deftest is]]
|
5 |
| - [com.github.clojure-lsp.intellij.client :as lsp-client] |
6 | 4 | [com.github.clojure-lsp.intellij.db :as db]
|
7 | 5 | [com.github.clojure-lsp.intellij.server :as server]
|
| 6 | + [com.github.clojure-lsp.intellij.test-utils :as test-utils] |
8 | 7 | [com.github.ericdallo.clj4intellij.app-manager :as app-manager]
|
9 | 8 | [com.github.ericdallo.clj4intellij.test :as clj4intellij.test])
|
10 | 9 | (:import
|
11 |
| - [com.github.clojure_lsp.intellij.extension SettingsState] |
12 |
| - [com.intellij.ide DataManager] |
13 |
| - [com.intellij.openapi.actionSystem ActionManager] |
| 10 | + [com.github.clojure_lsp.intellij.extension SettingsState] |
14 | 11 | [com.intellij.openapi.components ServiceManager]
|
15 |
| - [com.intellij.openapi.editor LogicalPosition] |
16 |
| - [com.intellij.openapi.wm WindowManager])) |
| 12 | + [com.intellij.openapi.editor LogicalPosition])) |
17 | 13 |
|
18 | 14 | (set! *warn-on-reflection* true)
|
19 | 15 |
|
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 | 16 |
|
45 | 17 |
|
46 |
| -(defn get-status-bar-widget [project widget-id] |
47 |
| - (let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))] |
48 |
| - (.getWidget status-bar widget-id))) |
49 | 18 |
|
50 |
| -(defn run-editor-action [action-id project] |
51 |
| - (let [action (.getAction (ActionManager/getInstance) action-id) |
52 |
| - context (.getDataContext (DataManager/getInstance))] |
53 |
| - (println "Running action:" action-id) |
54 |
| - (app-manager/write-command-action |
55 |
| - project |
56 |
| - (fn [] |
57 |
| - (.actionPerformed |
58 |
| - action |
59 |
| - (com.intellij.openapi.actionSystem.AnActionEvent/createFromDataContext action-id nil context)))))) |
| 19 | + |
| 20 | + |
| 21 | + |
60 | 22 |
|
61 | 23 |
|
62 | 24 | (deftest foo-test
|
|
78 | 40 | (.loadState my-settings my-settings));; Atualiza estado
|
79 | 41 |
|
80 | 42 | (clj4intellij.test/dispatch-all)
|
81 |
| - (dispatch-all-until {:project project}) |
| 43 | + (test-utils/dispatch-all-until {:project project}) |
82 | 44 | (println "status LSP >> " (db/get-in project [:status]))
|
83 | 45 | (let [editor (.getEditor fixture)
|
84 | 46 | document (.getDocument editor)
|
|
91 | 53 | {:invoke-fn (fn []
|
92 | 54 | #_(.moveToOffset caret (+ offset 9))
|
93 | 55 | (.moveToLogicalPosition caret new-position))}))
|
94 |
| - (run-editor-action "ClojureLSP.ForwardSlurp" project) |
| 56 | + (test-utils/run-editor-action "ClojureLSP.ForwardSlurp" project) |
95 | 57 | (clj4intellij.test/dispatch-all)
|
96 | 58 | (println (-> fixture .getEditor .getDocument .getText))
|
97 | 59 | (.checkResultByFile fixture "foo_expected.clj")
|
|
0 commit comments