Clojure-lsp: textDocument/references not returning declaration in results when includeDeclaration is true

Created on 14 Jan 2021  路  4Comments  路  Source: clojure-lsp/clojure-lsp

I'm not sure if this is a problem or I'm misunderstanding the protocol. It seems that with the textDocument/references request, if includeDeclaration is set to true it should return the declaration as a reference.

With the following code:

(ns windows
  (:require [hiccup.core :as h]))

(def hello "world")

(comment
  hello)

If I find references on the bottom reference of hello, the following request and response occur:

[Trace - 5:39:36 PM] Sending request 'textDocument/references - (67)'.
Params: {
    "textDocument": {
        "uri": "file:///home/brandon/development/clojure-test/src/windows.clj"
    },
    "position": {
        "line": 6,
        "character": 4
    },
    "context": {
        "includeDeclaration": true
    }
}


[Trace - 5:39:36 PM] Received response 'textDocument/references - (67)' in 3ms.
Result: [
    {
        "uri": "file:///home/brandon/development/clojure-test/src/windows.clj",
        "range": {
            "start": {
                "line": 6,
                "character": 2
            },
            "end": {
                "line": 6,
                "character": 7
            }
        }
    }
]

It seems the results should include the declaration as well as the bottom reference, but only the bottom reference is returned. This is true if I call find references on the declaration hello as well.

bug

Most helpful comment

@bpringe it should be fixed on latest release :)

All 4 comments

Yeah, I can confirm the server doesn't check that info from request params, is not hard to implement though, I can take a look at this soon

Thanks for the report ;)

@bpringe it should be fixed on latest release :)

I think there may be another issue with this. With the same code above, if I find references on the bottom hello now, I get duplicate Locations (both the bottom hello).

[Trace - 4:49:17 PM] Sending request 'textDocument/references - (57)'.
Params: {
    "textDocument": {
        "uri": "file:///home/brandon/development/clojure-test/src/windows.clj"
    },
    "position": {
        "line": 6,
        "character": 5
    },
    "context": {
        "includeDeclaration": true
    }
}


[Trace - 4:49:17 PM] Received response 'textDocument/references - (57)' in 4ms.
Result: [
    {
        "uri": "file:///home/brandon/development/clojure-test/src/windows.clj",
        "range": {
            "start": {
                "line": 6,
                "character": 2
            },
            "end": {
                "line": 6,
                "character": 7
            }
        }
    },
    {
        "uri": "file:///home/brandon/development/clojure-test/src/windows.clj",
        "range": {
            "start": {
                "line": 6,
                "character": 2
            },
            "end": {
                "line": 6,
                "character": 7
            }
        }
    }
]

And you can see duplicates in the references side bar in VS Code.

image

If I find references on the _top_ hello however, the declaration, I get the location for the declaration and the reference below, as expected.

Oh, it's a corner case I didn't catch, I'll try to fix it, thanks!

Was this page helpful?
0 / 5 - 0 ratings