Fork me on GitHub
#lsp
<
2022-03-23
>
snoe19:03:32

Is there a reason move-coll-entry-up/down uses a the full range of the loc in show-document-after-edit ? I believe the intent is to keep the cursor position as you repeat, but in vim because the range is more than one char it selects the range and breaks repeatability. I think a change like (assoc cursor-position :end-row (:row cursor-position) :end-col (:col cursor-position)) would be ok if i have the intent correct.

ericdallo19:03:58

hum, I think that was intentional, looks like vim has a different behavior, @U07M2C8TT knows more about that feature

jacob.maine19:03:24

@U0BUV7XSA that’s an accident and your proposed fix looks good. Thanks for tracking that down

👍 1
jacob.maine19:03:31

And yes, the intent is to maintain position, not to select a range

snoe20:03:58

This is one of the features I've wanted since the beginning. Great job.

🚀 1
jacob.maine15:03:05

Thanks! It was a fun introduction to clojure-lsp development. Now I’m addicted. :)

apt19:03:26

Hi folks. Consider this situation, in which the point is just after the last s character and str is not required. If I ask for the code actions with the point in that position, I don’t get the require suggestion. If I mock back one char, I get it. Is this expected? (I’m not using evil mode)

ericdallo20:03:26

> If I ask for the code actions with the point in that position What position exactly?

ericdallo20:03:37

after the last s ?

ericdallo20:03:11

well, clojure-lsp should provide that in any place of that line, you should see the code action to add the require even not inside that paren, if in the same line

apt20:03:31

Yeap. After the last s

ericdallo20:03:10

what code actions are available for that line?

ericdallo20:03:36

what's your clojure-lsp --version?

apt20:03:56

Oh, okay, I remember this issue. Maybe it’s eglot’s fault?

apt20:03:14

If the point is not above the chars marked by flymake, I get those actions:

Move to let
Cycle privacy
Clean namespace
Thread last all
Extract function
Thread first all
Move coll entry up
Move coll entry down
Create test for 'clojure-service-request?'

apt20:03:54

> clojure-lsp should provide that in any place of that line out of curiosity, if there were two possible additions of requires, what would be the expected behaviour if I ask for code actions in a position that is not over any of them?

ericdallo20:03:57

> out of curiosity, if there were two possible additions of requires, what would be the expected behaviour if I ask for code actions in a position that is not over any of them? do you have a example? it's not clear to me

ericdallo20:03:37

(str/foo a b) (+ 1 2|) 
with the cursor as | , clojure-lsp should suggest add clojure.string require even if not on that form, but on same line

apt20:03:57

> do you have a example? it’s not clear to me example:

(str/foo) (set/baz) foo|
where the cursor is |, and neither str or set are required yet. If I ask for code actions with the point in |, should it suggest requires for both str and set?

ericdallo20:03:21

my guess: eglot is sending wrong range

apt20:03:13

When you have time, do you mind sending me lsp-mode logs please? For a sample namespace like

(ns foo)

(str/foo) bar
and with the point somewhere in bar, for example

apt20:03:42

Or, if you know the answer w/o looking at the logs, should the client send the whole line as range?

ericdallo20:03:17

yes, probably the issue is with the range sent on textDocument/codeAction request

apt20:03:44

Got it. By any chance, do you know if this range is Clojure-specific?

ericdallo20:03:45

lsp-mode send this range:

{
    "start": {
      "line": 2,
      "character": 12
    },
    "end": {
      "line": 2,
      "character": 12
    }
  }

ericdallo20:03:59

which is the cursor range

ericdallo20:03:08

but it's not what we seek on clojure-lsp

ericdallo20:03:14

we check the range of the diagnostics

ericdallo20:03:21

inside context

ericdallo20:03:32

this is the full request:

{
  "textDocument": {
    "uri": "file:///home/greg/dev/clojure-lsp/lib/src/clojure_lsp/foo.clj"
  },
  "range": {
    "start": {
      "line": 2,
      "character": 12
    },
    "end": {
      "line": 2,
      "character": 12
    }
  },
  "context": {
    "diagnostics": [
      {
        "range": {
          "start": {
            "line": 2,
            "character": 1
          },
          "end": {
            "line": 2,
            "character": 8
          }
        },
        "severity": 2,
        "code": "unresolved-namespace",
        "source": "clj-kondo",
        "message": "Unresolved namespace str. Are you missing a require?",
        "tags": []
      },
      {
        "range": {
          "start": {
            "line": 2,
            "character": 10
          },
          "end": {
            "line": 2,
            "character": 13
          }
        },
        "severity": 1,
        "code": "unresolved-symbol",
        "source": "clj-kondo",
        "message": "Unresolved symbol: bar",
        "tags": []
      }
    ]
  }
}

apt20:03:17

Thanks, this should be enough info for debugging it in eglot gratitude

apt02:03:55

I just checked that the range sent by eglot is correct:

:range
	   (:start
	    (:line 2 :character 13)
	    :end
	    (:line 2 :character 13))
for this file
(ns foo)

(str/foo) bar

apt02:03:26

On the other hand, if the point is over the highlighted error, it works:

(:jsonrpc "2.0" :id 2189 :method "textDocument/codeAction" :params
	  (:textDocument
	   (:uri "file:///Users/<redacted>/foo.clj")
	   :range
	   (:start
	    (:line 2 :character 7)
	    :end
	    (:line 2 :character 7))
	   :context
	   (:diagnostics
	    [(:range
	      (:start
	       (:line 2 :character 1)
	       :end
	       (:line 2 :character 8))
	      :severity 2 :code "unresolved-namespace" :source "clj-kondo" :message "Unresolved namespace str. Are you missing a require?" :tags
	      [])])))

apt02:03:40

Can you send me the client + server logs please?

apt03:03:59

Oh, I think I found the difference between eglot and lsp-mode requests (just installed it). In the textDocument/codeAction request, the range is indeed identical, but lsp-mode has an additional context key with the following contents:

"context": {
    "diagnostics": [
      {
        "range": {
          "start": {
            "line": 2,
            "character": 1
          },
          "end": {
            "line": 2,
            "character": 8
          }
        },
        "severity": 2,
        "code": "unresolved-namespace",
        "source": "clj-kondo",
        "message": "Unresolved namespace str. Are you missing a require?",
        "tags": []
      }
    ]
  }  

ericdallo11:03:56

Yes, that's the issue, clojure-lsp rely on that

ericdallo11:03:08

Eglot is not sending that probably

apt12:03:28

Yeah, it’s not sending it. I confirmed it with the logs. Thanks for the help, I just started a discussion in eglot repo

👍 1
apt16:03:58

Fixed by https://github.com/joaotavora/eglot/commit/03fc783c4b701fc8c19096b7167b73bd5d8f63a8 It’s not considering the whole line, but the thing at point. I think it makes sense as well.

👍 1