Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable "find references" for quoted qualified symbols #1804

Closed
lassemaatta opened this issue Apr 15, 2024 · 3 comments
Closed

Enable "find references" for quoted qualified symbols #1804

lassemaatta opened this issue Apr 15, 2024 · 3 comments
Labels
enhancement New feature or request
Projects

Comments

@lassemaatta
Copy link
Contributor

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.

@lassemaatta lassemaatta added the enhancement New feature or request label Apr 15, 2024
@ericdallo ericdallo added this to Low priority in clojure-lsp via automation Apr 15, 2024
clojure-lsp automation moved this from Low priority to Next release Apr 22, 2024
@lassemaatta
Copy link
Contributor Author

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)))  

@ericdallo
Copy link
Member

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

@lassemaatta
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
clojure-lsp
Next release
Development

No branches or pull requests

2 participants