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

Definition hover only shows definition of symbol at function call position #1098

Closed
bpringe opened this issue Jul 4, 2022 · 5 comments
Closed
Labels
bug Something isn't working editor Related to clojure-lsp on a text editor
Projects

Comments

@bpringe
Copy link
Contributor

bpringe commented Jul 4, 2022

Describe the bug

If I hover over a symbol in a form, the hover shows details for the symbol at the beginning of the form, not the symbol at the cursor.

To Reproduce

In Calva, with the following code, without being connected to repl, but with clojure-lsp running, hover over one in the comp form and see that it shows details for comp.

(defn one 
  "*hello world*"
  [x]
  (println "one"))

(defn two [x]
  (println "two"))

(defn three [x]
  (println "three"))

(comment
  ((comp one two three) 0))

image

Expected behavior

I expect the details for one to be shown in the hover.

Log - client <-> server
[Trace - 11:34:20 AM] Sending request 'textDocument/hover - (92)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/brandon/development/clojure-test/src/core.clj"
    },
    "position": {
        "line": 15,
        "character": 9
    }
}

[Trace - 11:34:20 AM] Received response 'textDocument/hover - (92)' in 139ms.
Result: {
"contents": {
"kind": "markdown",
"value": "clojure\nclojure.core/comp\n[]\n[f]\n[f g]\n[f g & fs]\n\n\nTakes a set of functions and returns a fn that is the composition\nof those fns. The returned fn takes a variable number of args,\napplies the rightmost of fns to the args, the next\nfn (right-to-left) to the result, etc.\n\n__Examples:\n\nclojure\n(def negative-quotient (comp - /))\n;; #'user/negative-quotient\n\n(negative-quotient 8 3) ;;=> -8/3\n\n(def concat-and-reverse (comp (partial apply str) reverse str)) \n;; #'user/concat-and-reverse\n\n(concat-and-reverse \"hello\" \"clojuredocs\")\n;;=> \"scoderujolcolleh\"\n\n\n---\nclojure\n((comp str +) 8 8 8) \n;;=> \"24\"\n\n\n---\nclojure\n(map\n (comp - (partial + 3) (partial * 2))\n [1 2 3 4])\n;;=> (-5 -7 -9 -11)\n\n---\nclojure\n(filter (comp not zero?) [0 1 0 2 0 3 0 4])\n;;=> (1 2 3 4)\n\n---\nclojure\n;; make a struct 'goods'. it assumes that every goods has\n;; its id number and price.\n(defstruct goods :id :price)\n\n;; generate data.\n(def data (map #(struct goods %1 %2)\n\t (shuffle (range 0 10)) \n (shuffle\n\t (into (range 100 500 100)\n\t\t\t(range 100 500 100)))))\n\n(defn comp-goods-price\n \"a compare function by :price of the struct 'goods.' the sort order \n is that the lower price is superior to the higher one and if the \n price is same, the lower id is superior to the higher one.\"\n [el1 el2]\n (if (or (< (:price el1) (:price el2))\n (and (= (:price el1) (:price el2)) (< (:id el1) (:id el2))))\n true\n false))\n\n;; The shuffle will cause your results to differ.\ndata \n;;=> ({:id 1, :price 300} {:id 6, :price 100} \n;; {:id 3, :price 100} {:id 4, :price 400}\n;; {:id 0, :price 300} {:id 2, :price 200} \n;; {:id 5, :price 200} {:id 8, :price 400})\n\n(sort (comp comp-goods-price) data)\n;;=> ({:id 3, :price 100} {:id 6, :price 100} \n;; {:id 2, :price 200} {:id 5, :price 200} \n;; {:id 0, :price 300} {:id 1, :price 300}\n;; {:id 4, :price 400} {:id 8, :price 400})\n\n(sort-by :price < data) ; compare this with the above.\n;;=> ({:id 6, :price 100} {:id 3, :price 100} \n;; {:id 2, :price 200} {:id 5, :price 200} \n;; {:id 1, :price 300} {:id 0, :price 300} \n;; {:id 4, :price 400} {:id 8, :price 400})\n\n;; Yet another example of 'comp' by PriorityBlockingQueue.\n\n(import [java.util.concurrent PriorityBlockingQueue])\n;; java.util.concurrent.PriorityBlockingQueue\n\n(def pqdata (new PriorityBlockingQueue 8\n\t\t (comp comp-goods-price)))\n;; #'user/pqdata\n\n(doseq [x data] (.add pqdata x))\n;;=> nil\n\n(dotimes [_ 8] (println (.poll pqdata)))\n;; {:id 3, :price 100}\n;; {:id 6, :price 100}\n;; {:id 2, :price 200}\n;; {:id 5, :price 200}\n;; {:id 0, :price 300}\n;; {:id 1, :price 300}\n;; {:id 4, :price 400}\n;; {:id 8, :price 400}\n;;=> nil\n\n\n---\nclojure\n(def countif (comp count filter))\n#'user/countif\n\n(countif even? [2 3 1 5 4])\n;;=> 2\n\n---\nclojure\n; Get 2nd to last element from a list\n( (comp second reverse) '(\"a\" 2 7 \"b\")) \n;;=> 7\n\n---\nclojure\n; We need an example that composes more than just two functions.\n; The following example is an overly complicated reimplementation of 'nth'\n; but it does show the composition of an arbitrary number of functions (rest).\n( #((apply comp first (repeat %2 rest)) %1) [1 2 3 4 5 6] 3 ) \n;;=> 4\n\n---\nclojure\n; `comp`-ing maps, filters with a little help from our friend `partial`\n; the following function filters numbers in a `coll` if it is divisible by 3\n; then on that filtered `coll`, multiplies all by 2\n\n; a little helper to find if a number is div by 3 \n; also comp-ed\n\n(def mod3nz? (comp not zero? #(mod % 3)))\n\n; now for that elusive function that muls by 2 after filter those not div by 3\n(def mul-2-nd-3\n \"Takes a seq of numbers, filters those not divisible by 3 and muls them by 2\"\n (comp (partial map #(* % 2))\n (partial filter mod3nz?)))\n\n(mul-2-nd-3 [16 15 30 43]) ;; => (32 86)\n\n\n---\nclojure\n; Split a number into sequence of it's digits\n((comp (partial map (comp read-string str)) str) 33)\n;;=> (3 3)\n\n---\nclojure\n;; Keywords are used as functions to access data in maps.\n\n(:foo {:foo \"bar\"})\n;;=> \"bar\"\n\n;; With a nested data structure, it is common to use\n;; several keywords in sequence to navigate the hierarchy.\n\n(def my-data {:this {:that {:the-other \"val\"}}})\n;;=> #'user/my-data\n\n(-> my-data :this :that :the-other)\n;;=> \"val\"\n\n;; Since keywords are functions,\n;; they can be 'comp'ed just like any other function.\n\n(def those (comp :the-other :that :this)) ; Note: reverse order\n;;=> #'user/those\n\n(those my-data)\n;;=> \"val\"\n\n;; The composed keyword-sequence can be used with other keywords: -\n\n(def my-data-2\n {:this {:that {:the-other {:a \"apple\" :b \"banana\"}}}})\n;;=> #'user/my-data-2\n\n(let [a (-> my-data-2 those :a)\n b (-> my-data-2 those :b)]\n (str \"These: \" a \", \" b))\n;;=> \"These: apple, banana\"\n\n---\nclojure\n;; ((comp func1 func2) data) mean ...\n;; (-> data func2 func1)\n;; so,\n((comp (partial * 3) inc) 1)\n;; means\n(* 3 (inc 1))\n\n;; advanced ...\n\n((comp seq re-seq) #\"(\\w+)=(\\S+)\" \"foo=bar\")\n;; ([\"foo=bar\" \"foo\" \"bar\"])\n(seq (re-seq #\"(\\w+)=(\\S+)\" \"foo=bar\"))\n\n;; * \"#(\\w+)...\" and \"foo=...\" are arguments for #re-seq\n\n---\nclojure\n;; comp is the transducer equivalent to thrush \n\n;; An example of using the \"thread-last\" macro to get\n;; the sum of the first 10 even squares.\n(->> (range)\n (map #(* % %))\n (filter even?)\n (take 10)\n (reduce +))\n;;=> 1140\n\n;; Many the seq functions now produce transducers.\n;; `reduce` does not but has been replaced with `transduce`.\n(transduce \n (comp\n (map #(* % %))\n (filter even?)\n (take 10))\n + 0 (range) )\n;;=> 1140\n\n---\nclojure\n;;trim will remove the white spaces and return a new string which will be passed ;;to the second function capitalize which will return a new string\n\n((comp clojure.string/capitalize clojure.string/trim) \" london \")\n;;\"London\"\n\n\n---\nclojure\n(def my-car\n {:name \"audi\"\n :data {:cc 2990\n :bhp 350}})\n\n((comp :bhp :data) my-car)\n;;350\n\n;;which is the equivalent of\n\n(:bhp (:data my-car))\n;;350\n\n---\nclojure\n(require '[reagent.core :as r])\n\n(def float-parsable? (comp not js/isNaN js/parseFloat))\n(def find-parsable-or-nil \n (comp first \n (partial re-find \n #\"(\\-?\\d+\\.)?\\d+([eE][-+]?\\d+)?\")))\n\n(defn number-input\n \"HTML input element for number only input\"\n [value]\n [:input\n {:value @value\n :type \"text\"\n :on-change (comp\n #(when-let [new-value %]\n (reset! value new-value))\n (fn [new-value]\n (cond\n (empty? new-value) \"\"\n (float-parsable? new-value) new-value\n :otherwise (find-parsable-or-nil new-value)))\n (fn [target]\n (.-value target))\n (fn [event]\n (.-target event)))}])\n\n(def value (r/atom \"\"))\n\n(defn demo []\n [:div\n ; Displays NaN when value is \"\", displays a number otherwise.\n (-> @value js/parseFloat str) [:br]\n [number-input value]])\n\n---\nclojure\n; Demonstrating the order of parameters vs. normal function application.\n\n(def x {:bar {:foo 42}})\n\n(:foo (:bar x))\n;;=> 42\n\n((comp :foo :bar) x)\n;;=> 42\n\n---\nclojure\n; Without arguments returns identity function\n\n(identical? (comp) identity)\n;;=> true\n\n((comp) :arg)\n;;=> :arg\n\n\n__See also:\n\nclojure.core/partial\n\nclojure.core/juxt\n\nclojure.core/every-pred\n\n----\n\n*/Users/brandon/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar:clojure/core.clj*"
},
"range": {
"start": {
"line": 15,
"character": 4
},
"end": {
"line": 15,
"character": 8
}
}
}

Log - clojure-lsp
2022-07-04T18:35:22.207Z  INFO [clojure-lsp.handlers:404] - :code-actions 23ms
2022-07-04T18:35:23.458Z  INFO [clojure-lsp.handlers:369] - :hover 46ms

User details (please complete the following information):

  • OS: MacOS
  • Editor VS Code (Calva)
  • Version: 2022.06.29-19.32.13
@bpringe bpringe added bug Something isn't working editor Related to clojure-lsp on a text editor labels Jul 4, 2022
@ericdallo
Copy link
Member

thanks, I was talking about this one with @mainej, this was introduced on latest release and it should not be hard to fix

@ericdallo ericdallo added this to Low priority in clojure-lsp via automation Jul 4, 2022
@ericdallo ericdallo moved this from Low priority to High priority (Probably next release) in clojure-lsp Jul 4, 2022
clojure-lsp automation moved this from High priority (Probably next release) to Next release Jul 5, 2022
@ericdallo
Copy link
Member

@bpringe it should be fixed on master, LMK if any more issues

@bpringe
Copy link
Contributor Author

bpringe commented Jul 5, 2022

Awesome. Thanks!

@ericdallo ericdallo moved this from Next release to Done in clojure-lsp Jul 24, 2022
@bpringe
Copy link
Contributor Author

bpringe commented Jul 28, 2022

@ericdallo This is happening for me again in 2022.07.24-18.25.43.

Edit: Actually, sorry, the originally reported issue in the screenshot is not happening, but if I hover over the symbol that defn defines, it shows the definition for defn in the hover.

image

@ericdallo
Copy link
Member

I think it's a new issue we didn't handle @bpringe, could you open a new issue please? I wonder if there is any more cases like this to handle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working editor Related to clojure-lsp on a text editor
Projects
Development

No branches or pull requests

2 participants