Skip to content

Commit 8f8ccfe

Browse files
committed
Support Namespaces on search everywhere (Shift + shift).
Fixes #64
1 parent f8ff144 commit 8f8ccfe

File tree

5 files changed

+91
-19
lines changed

5 files changed

+91
-19
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
- Bump clj4intellij to 0.7.1
6+
- Support Namespaces on search everywhere (Shift + shift). #64
67

78
## 3.1.1
89

src/main/clojure/com/github/clojure_lsp/intellij/client.clj

+35-19
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,52 @@
1414
Position
1515
ReferenceContext
1616
ReferenceParams
17-
TextDocumentIdentifier]))
17+
TextDocumentIdentifier
18+
WorkspaceSymbolParams]
19+
[org.eclipse.lsp4j.jsonrpc.messages Either]))
1820

1921
(set! *warn-on-reflection* true)
2022

23+
(defn project->ls-server-item ^LanguageServerItem
24+
[^Project project]
25+
(when-let [manager (LanguageServerManager/getInstance project)]
26+
@(.getLanguageServer manager "clojure-lsp")))
27+
28+
(defn ^:private project->ls-server ^ClojureLanguageServer [project]
29+
(when-let [item (project->ls-server-item project)]
30+
(.getServer item)))
31+
2132
(defn server-status [^Project project]
2233
(when-let [manager (LanguageServerManager/getInstance project)]
2334
(keyword (.toString (.getServerStatus manager "clojure-lsp")))))
2435

2536
(defn server-info [^Project project]
2637
(when (identical? :started (lsp-client/server-status project))
27-
(when-let [manager (LanguageServerManager/getInstance project)]
28-
(when-let [server (.getServer ^LanguageServerItem @(.getLanguageServer manager "clojure-lsp"))]
29-
(some->> (.serverInfo ^ClojureLanguageServer server)
30-
deref
31-
(into {})
32-
walk/keywordize-keys)))))
38+
(when-let [server (project->ls-server project)]
39+
(some->> (.serverInfo ^ClojureLanguageServer server)
40+
deref
41+
(into {})
42+
walk/keywordize-keys))))
3343

3444
(defn dependency-contents [^String uri ^Project project]
35-
(when-let [manager (LanguageServerManager/getInstance project)]
36-
(when-let [server (.getServer ^LanguageServerItem @(.getLanguageServer manager "clojure-lsp"))]
37-
(some->> (.dependencyContents ^ClojureLanguageServer server {"uri" uri})
38-
deref))))
45+
(when-let [server (project->ls-server project)]
46+
(some->> (.dependencyContents ^ClojureLanguageServer server {"uri" uri})
47+
deref)))
3948

4049
(defn references [^String uri line character ^Project project]
41-
(when-let [manager (LanguageServerManager/getInstance project)]
42-
(when-let [server (.getServer ^LanguageServerItem @(.getLanguageServer manager "clojure-lsp"))]
43-
(some-> (.getTextDocumentService ^ClojureLanguageServer server)
44-
(.references (ReferenceParams. (TextDocumentIdentifier. uri)
45-
(Position. line character)
46-
(ReferenceContext. false)))
47-
deref))))
50+
(when-let [server (project->ls-server project)]
51+
(some-> (.getTextDocumentService ^ClojureLanguageServer server)
52+
(.references (ReferenceParams. (TextDocumentIdentifier. uri)
53+
(Position. line character)
54+
(ReferenceContext. false)))
55+
deref)))
56+
57+
(defn symbols [^String query ^Project project]
58+
(when-let [server (project->ls-server project)]
59+
(some-> (.getWorkspaceService ^ClojureLanguageServer server)
60+
(.symbol (WorkspaceSymbolParams. query))
61+
^Either deref
62+
.get)))
4863

4964
(defn execute-command [^String name ^String text ^List args ^Project project]
5065
(try
@@ -54,4 +69,5 @@
5469
(.response)
5570
deref)
5671
(catch Exception e
57-
(logger/error "Error appllying command" name (with-out-str (.printStackTrace e))))))
72+
(logger/error (format "Error applying command '%s' with args '%s' for text '%s'" name args text)
73+
(with-out-str (.printStackTrace e))))))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(ns com.github.clojure-lsp.intellij.extension.search-contributors
2+
(:require
3+
[com.github.clojure-lsp.intellij.client :as lsp-client]
4+
[com.github.clojure-lsp.intellij.project-lsp :as project]
5+
[com.github.ericdallo.clj4intellij.extension :refer [def-extension]]
6+
[com.rpl.proxy-plus :refer [proxy+]])
7+
(:import
8+
[com.github.clojure_lsp.intellij Icons]
9+
[com.intellij.ide.actions.searcheverywhere SearchEverywhereContributor SearchEverywhereContributorFactory]
10+
[com.intellij.ide.util NavigationItemListCellRenderer]
11+
[com.intellij.navigation ItemPresentation NavigationItem]
12+
[com.intellij.openapi.actionSystem AnActionEvent]
13+
[com.intellij.util Processor]
14+
[com.redhat.devtools.lsp4ij.features.workspaceSymbol WorkspaceSymbolData]
15+
[org.eclipse.lsp4j SymbolKind WorkspaceSymbol]))
16+
17+
(set! *warn-on-reflection* true)
18+
19+
(defn ^:private symbol->navigation-item ^NavigationItem
20+
[^WorkspaceSymbol sym project]
21+
(proxy+ [(.getName sym)
22+
(.getKind sym)
23+
(.getLeft (.getLocation sym))
24+
(.getClientFeatures (lsp-client/project->ls-server-item project))
25+
project]
26+
WorkspaceSymbolData
27+
(getPresentation [_]
28+
(proxy+ [] ItemPresentation
29+
(getPresentableText [_] (.getName sym))
30+
(getIcon [_ _] Icons/CLOJURE)))))
31+
32+
(def-extension NamespaceSearchContributorFactory []
33+
SearchEverywhereContributorFactory
34+
(isAvailable [_ project] (project/clojure-project? project))
35+
(createContributor [_ ^AnActionEvent event]
36+
(let [project (.getProject event)]
37+
(proxy+ NamespaceSearchContributor []
38+
SearchEverywhereContributor
39+
(getSearchProviderId [_] "clojure-lsp-namespace-search")
40+
(getGroupName [_] "Namespaces")
41+
(getSortWeight [_] 301)
42+
(showInFindResults [_] true)
43+
(isShownInSeparateTab [_] true)
44+
(isEmptyPatternSupported [_] true)
45+
(fetchElements [_ pattern _indicator ^Processor consumer]
46+
(let [syms (->> (lsp-client/symbols pattern project)
47+
(filter #(identical? SymbolKind/Namespace (.getKind ^WorkspaceSymbol %))))]
48+
(doseq [sym syms]
49+
(.process consumer (symbol->navigation-item sym project)))))
50+
(processSelectedItem [_ ^NavigationItem item _modifiers _search-text]
51+
(.navigate item true)
52+
true)
53+
(getElementsRenderer [_]
54+
(NavigationItemListCellRenderer.))))))

src/main/resources/META-INF/plugin.xml

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<lang.quoteHandler language="clojure" implementationClass="com.github.clojure_lsp.intellij.extension.QuoteHandler"/>
7070
<lang.braceMatcher language="clojure" implementationClass="com.github.clojure_lsp.intellij.extension.brace_matcher.BraceMatcher"/>
7171
<applicationService serviceImplementation="com.github.clojure_lsp.intellij.extension.SettingsState"/>
72+
<searchEverywhereContributor implementation="com.github.clojure_lsp.intellij.extension.search_contributors.NamespaceSearchContributorFactory"/>
7273
<applicationConfigurable
7374
parentId="tools"
7475
instance="com.github.clojure_lsp.intellij.extension.general_settings.ClojureGeneralSettingsConfigurable"

0 commit comments

Comments
 (0)