lsp

lassemaatta 2025-01-24T07:40:44.968919Z

might be an unrelated issue, but has anyone else had problems with completions overwriting text with the new clojure-lsp version + emacs + lsp-mode?

lassemaatta 2025-02-01T08:59:14.432709Z

I checked out Pauls fork, built the java version with bb debug-cli, removed references to :slow-but-accurate => seems to work fine after abusing it for a few minutes, at least in lsp-mode.

πŸŽ‰ 1
lassemaatta 2025-02-01T09:02:31.522999Z

But I'll test this a bit more just to be safe

πŸ‘ 1
lassemaatta 2025-02-01T09:08:22.772439Z

Yeah, seems to work fine. At first I was a bit confused as to why I couldn't repro this anymore with the latest nightly, but of course that's because the original PR was reverted.

lassemaatta 2025-02-01T09:09:40.259109Z

In any case, lots of gratitude for all of you for fixing this πŸ™‚

paulbutcher 2025-01-28T16:16:30.815389Z

@lasse.olavi.maatta @shem I've just installed Emacs and have been dredging up old muscle memory (I used to live in Emacs back in the 90s, but it's been a long time since then!). I have a theory about what might be going on: Do you see the problem when the buffer contains syntactically correct Clojure? Or only when it's syntactically incorrect (e.g. mismatched parentheses)?

lassemaatta 2025-01-28T16:32:37.532479Z

the issue occurs when the buffer contains valid clojure. when and if the issue occurs, the result is often syntactically incorrect as one or more parens might get overwritten

paulbutcher 2025-01-28T16:33:29.381169Z

Damn. So my theory doesn't work. Could you do me a favour and send me a video of the issue occurring with valid Clojure in the buffer?

lassemaatta 2025-01-28T16:34:37.014969Z

it feels like the selected completion candidate is not inserted where the completion occurs (iow. it should "push" any code after the completion point forwards to make room for the candidate). instead it overwrites the characters after the point

lassemaatta 2025-01-28T16:35:07.376689Z

sure, I can try to grab a video of it

paulbutcher 2025-01-28T16:35:31.015839Z

FWIW everything works perfectly for me, unless I have mismatched parentheses in the buffer. It would be good to know what's different between my (very vanilla, because I only installed Emacs a couple of hours ago πŸ™‚) setup and yours.

paulbutcher 2025-01-28T16:36:21.121259Z

This is my init.el in its entirety:

(require 'package)
(add-to-list 'package-archives '("melpa" . "") t)
(package-initialize)
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages
   '(smartparens parinfer-rust-mode clojure-mode-extra-font-locking cider lsp-treemacs company flycheck lsp-ui lsp-mode)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

(require 'smartparens-config)
(add-hook 'clojure-mode-hook 'smartparens-mode)
(add-hook 'clojurescript-mode-hook 'smartparens-mode)
(add-hook 'clojurec-mode-hook 'smartparens-mode)

(add-hook 'clojure-mode-hook 'lsp)
(add-hook 'clojurescript-mode-hook 'lsp)
(add-hook 'clojurec-mode-hook 'lsp)

(setq lsp-clojure-custom-server-command '("bash" "-c" "~/Downloads/clojure-lsp"))

(setq gc-cons-threshold (* 100 1024 1024)
      read-process-output-max (* 1024 1024)
      treemacs-space-between-root-nodes nil
      company-minimum-prefix-length 1
      ; lsp-enable-indentation nil ; uncomment to use cider indentation instead of lsp
      ; lsp-enable-completion-at-point nil ; uncomment to use cider completion instead of lsp
      )

paulbutcher 2025-01-28T16:39:03.453849Z

Prior to the change, clojure-lsp used to just return completions and leave it up to the editor to work out what to do with them. After the change, it tells the editor that it "knows what it's doing" and gives an explicit character range which should be replaced. My theory was that clojure-lsp's model of what's going on was getting out of sync with the editor's buffer when the Clojure is syntactically incorrect. But that can't explain what's going on if you're seeing it with syntactically correct Clojure.

lassemaatta 2025-01-28T16:40:30.509829Z

Example of the issue. The first two completion attemps work fine, but the third breaks the forms

paulbutcher 2025-01-28T16:42:36.563029Z

Ah! @ericdallo could this be another case of having to use process-after-changes like we did for linked editing ranges?

ericdallo 2025-01-28T16:44:26.162599Z

I think so, we can test that

ericdallo 2025-01-28T16:44:44.724599Z

I can't look at this right now, so any tests or PRs would help

paulbutcher 2025-01-28T16:46:11.565839Z

I will put something together. I think we also have a problem with syntactically incorrect files too (which I serendipitously discovered while trying to reproduce the issue @lasse.olavi.maatta noticed).

paulbutcher 2025-01-28T16:46:42.904429Z

(not yet sure what to do about that one).

ericdallo 2025-01-28T16:50:18.546869Z

there are some logic about invalid files in both clojure-lsp and clj-kondo, but it's basic, like missing ) and so on

lassemaatta 2025-01-28T16:53:37.983379Z

I'll volunteer as a test subject; feel free to ping me if you get a potential fix ready and I can test it out locally when I can.

πŸ‘ 1
ericdallo 2025-01-28T21:31:10.145679Z

This seems to be happening https://clojurians.slack.com/archives/CBE668G4R/p1738096901625779, I believe we will have to revert that if we don't find a quick fix @paulbutcher

ericdallo 2025-01-28T21:39:29.976099Z

I reverted https://github.com/clojure-lsp/clojure-lsp/commit/46d6fd16abb9a00fafce6fcf47ef173704288388 until we find the proper fix, nightly build should have the fix soon

πŸ™‡ 1
pez 2025-01-28T21:52:28.897439Z

Nightly fixes it. Thanks! πŸ™ ❀️

πŸŽ‰ 2
lassemaatta 2025-01-24T07:42:33.266909Z

(let [x (foo| quuz) y 5]\n : completing foo to foobar will result in something like (let [x (foofoobar 5]\n instead of (let [x (foobar quuz) y 5]\n

ericdallo 2025-01-30T12:27:04.900359Z

BTW let us know if you feel anything in performance with that setting, we never noticed for sure how much slow it's actually

paulbutcher 2025-01-30T14:12:00.153599Z

Feedback on performance would be great, but this isn’t the entire solution. @ericdallo I am approaching a proposal for how to address this properly and will let you know when I have everything straight.

paulbutcher 2025-01-30T14:12:40.674379Z

(I think there’s a chance we can have our cake and eat it too).

🍰 1
1
lassemaatta 2025-01-30T14:14:07.035999Z

my first impression was that completion is a bit slower now. But that might just be placebo due to naming; if the flag was called :alternative-super-fast-mode I would probably say it felt faster πŸ™‚

πŸ˜‚ 2
ericdallo 2025-02-03T13:06:43.052219Z

Cool, thanks for testing, @paulbutcher are we good to merge it so?

paulbutcher 2025-02-03T13:17:04.115699Z

I think so, @ericdallo πŸ‘

ericdallo 2025-02-03T13:24:52.530119Z

merged, thanks for the help

πŸ™ 1
πŸŽ‰ 1
paulbutcher 2025-01-29T09:34:06.927039Z

That makes sense @ericdallo. I'll keep looking at this and try to come to a full understanding of what's going on.

πŸ‘ 1
paulbutcher 2025-01-29T18:22:10.358099Z

@lasse.olavi.maatta it turns out that the process-after-changes code that @ericdallo and I were discussing is already implemented under a setting. Could you try setting :completion:analysis-type to :slow-but-accurate (documented https://clojure-lsp.io/settings/#all-settings) to see if it affects the behaviour you were seeing? (note, I'm not suggesting that this is the fix, but if it does modify the behaviour that will be informative). Thanks!

lassemaatta 2025-01-29T18:25:42.065329Z

Sure, I can test that tomorrow and report back my findings

paulbutcher 2025-01-29T18:25:49.518849Z

Thanks - much appreciated!

lassemaatta 2025-01-30T06:23:01.883809Z

I can confirm that :slow-but-accurate seems to fix the issue with 2025.01.22-23.28.23. I'll leave it on for now, just to see if I notice anything strange with completions later today.

πŸ™ 2
paulbutcher 2025-01-31T12:44:32.807009Z

@ericdallo @lasse.olavi.maatta I've just submitted another PR which, I believe, re-implements the textEdit functionality (fixing the problems in Zed which prompted this saga) while both avoiding the problems Lasse found and not requiring :slow-but-accurate to be enabled.

paulbutcher 2025-01-31T12:44:37.451629Z

https://github.com/clojure-lsp/clojure-lsp/pull/1960

ericdallo 2025-01-31T12:47:16.791829Z

I will take a look, but would be nice if @lasse.olavi.maatta could test that, there is a ci action that builds a binary

πŸ™ 1
🫑 1
lassemaatta 2025-01-31T12:48:07.119309Z

sure, I can take a look, if not today then at least during the weekend

πŸ™ 1
ericdallo 2025-01-31T13:33:22.939509Z

@shem would be nice if you could test that fixes for you as well

ericdallo 2025-01-24T12:13:52.390459Z

I can't repro that and we didn't have anything in latest clojure-lsp version that touched completion, you can double check with previous clojure-lsp version to make sure. Looks like more a lsp-mode issue or so

lassemaatta 2025-01-24T12:15:46.369409Z

yeah, sounds plausible

paulbutcher 2025-01-24T12:51:19.873769Z

Err, that's not entirely true @ericdallo: I submitted this PR which added textExit to completion items: https://github.com/clojure-lsp/clojure-lsp/pull/1934

paulbutcher 2025-01-24T12:52:24.075749Z

It shouldn't have broken anything because (I believe) it's consistent with the LSP spec. But it's possible that I got something wrong (or that Emacs has)?

shem 2025-01-24T13:02:12.976629Z

I see that as well, already before the newest update, this is with emacs 31.0.50, freshly compiled.

lassemaatta 2025-01-24T13:02:46.311399Z

I'll try to debug this over the weekend if I can. The issue doesn't happen 100% of the time, not sure if something is caching the completion results which might explain it.

lassemaatta 2025-01-24T13:04:13.239589Z

I'm running a relatively fresh install of emacs-30 from git, I think I compiled it last weekend. But as I said, I noticed the problem today, after upgrading clojure-lsp.

paulbutcher 2025-01-24T13:05:29.428529Z

I haven't been an Emacs user since the 90s (😱) so I'm unlikely to be much direct help, but let me know if there's anything I can do, or if there's anything in the PR linked above that is suspicious or unclear.

ericdallo 2025-01-24T13:08:11.168359Z

true @paulbutcher forgot about that PR, @lasse.olavi.maatta try disabling lsp-mode completion cache via lsp-completion-no-cache t

1
ericdallo 2025-01-24T13:09:26.767689Z

There is a chance that lsp-mode is not following something in the spec, but really unlikely

lassemaatta 2025-01-24T13:14:41.392119Z

not sure if disabling the cache had a huge impact; it still seems to occur maybe 80% of the time. But I also tested with eglot (... yes, I have a flag in my config to choose the lsp client...) and can observe the same issue, although it appears more like 100% of the time.

ericdallo 2025-01-24T13:15:35.802109Z

Interesting, I'll need to double check what clojure-lsp is doing to make sure it's following the spec or maybe it's a misinterpretation of the spec on editor or server side

lassemaatta 2025-01-24T16:13:23.371909Z

can't repro the problem with clojure-lsp 2024.11.08-17.49.29