clojure-lsp / clojure-lsp

Clojure & ClojureScript Language Server (LSP) implementation

Home Page:https://clojure-lsp.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable "find references" for quoted qualified symbols

lassemaatta opened this issue · comments

Is your feature request related to a problem? Please describe.

We sometimes use a combination of a datastructure + requiring-resolve to lazy-load and invoke functions/vars. The datastructures might look like

(def operations {"foo" 'some.namespace/foo-fn
                 "bar" 'some.other-namespace/bar-fn
                  ...})

With #1446 we can navigate from the datastructure to the var. But not the other way around:

  • cannot navigate from some.namespace/foo-fn back to the datastructure ("No references") and
  • clojure-lsp will report that some.namespace/foo-fn is an "Unused public var"

The latter can be quite problematic, as you might accidentally be tempted in removing the var as it's "unused code".

Describe the solution you'd like

Quoted qualified symbols should work like var-quote (#'some.namespace/foo-fn). Assuming of course the symbol points to an actual var somewhere.

Thanks a lot for implementing this!

FYI: I was testing with the latest release and the fix did not quite work the way I expected for our particular use case. After experimenting with this briefly, I think the feature works as expected when you require the corresponding namespace which contains the var when you want to refer to it with a symbol. For example, here in the test.

Our use case looks more like (pseudo-code, might not compile):

(ns some-ns.with-vars
  (:require [... a bunch of stuff ...])

(defn some-function []
  "I do something")

;; elsewhere..

(ns some-ns.program
 ;; No require for `some-ns.with-vars` here!
 (:gen-class))

(def operations {"foo" 'some-ns.with-vars/some-function})

(defn main- [& args]
  (when-let [s (get operations (first args))]
   ((requiring-resolve s)))  

Hum, indeed we will only consider if the symbol was required, I'll take a look but I think it's not trivial to support that

Thanks! And don’t worry about it, this is most likely a niche use case anyways :)