Fork me on GitHub
#lsp
<
2023-04-11
>
andrea.crotti13:04:26

I have been having a problem when indenting for a while, getting this sort of error

Debugger entered--Lisp error: (error "Internal error")
  error("Internal error")
  lsp-request("textDocument/rangeFormatting" #<hash-table equal 3/65 0x1572bdc0aa71>)
  lsp-format-region(91 821)
  apply(lsp-format-region (91 821))
  #f(advice-wrapper :override clojure-indent-region lsp-format-region)(91 821)
  indent-region(91 821)
  indent-for-tab-command(nil)
  funcall-interactively(indent-for-tab-command nil)
  #<subr command-execute>(indent-for-tab-command nil nil nil)
  ad-Advice-command-execute(#<subr command-execute> indent-for-tab-command)
  apply(ad-Advice-command-execute #<subr command-execute> indent-for-tab-command)
  command-execute(indent-for-tab-command)

andrea.crotti13:04:51

weirdly it doesn't always do that, just on some forms

andrea.crotti13:04:52

well actually interesting it doesn't even always happen on the same form 🤯

borkdude13:04:16

maybe throw away your elpa folder and re-install lsp-mode

andrea.crotti13:04:20

this works fine now

(defn hello []
  42)
But trying to indent
(def x 232)
fails

andrea.crotti13:04:49

yeah would do that after work, takes too long to reinstall everything

andrea.crotti13:04:00

even though I'm pretty sure I had it for a while and I've done that already

ericdallo13:04:03

You can check https://clojure-lsp.io/troubleshooting/#server-log to make sure it's not a server's fault before reinstalling everything

andrea.crotti13:04:32

2023-04-11T13:13:20.788Z  ERROR [clojure-lsp.server:55] - Error receiving message: Internal error (-32603)
{:id 1395, :method "textDocument/rangeFormatting"}
com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine  PosixPlatformThreads.java:  203
            com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine       PlatformThreads.java:  775
                            java.util.concurrent.ForkJoinWorkerThread.run  ForkJoinWorkerThread.java:  183
                              java.util.concurrent.ForkJoinPool.runWorker          ForkJoinPool.java: 1594
                                   java.util.concurrent.ForkJoinPool.scan          ForkJoinPool.java: 1656
                 java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec          ForkJoinPool.java: 1020
                                 java.util.concurrent.ForkJoinTask.doExec          ForkJoinTask.java:  290
                  java.util.concurrent.CompletableFuture$AsyncSupply.exec     CompletableFuture.java: 1692
                   java.util.concurrent.CompletableFuture$AsyncSupply.run     CompletableFuture.java: 1700
                                                promesa.util.Supplier/get                  util.cljc:   34
                                            promesa.exec/wrap-bindings/fn                  exec.cljc:  163
                                                 clojure-lsp.server/fn/fn                 server.clj:  291
                                    clojure-lsp.handlers/range-formatting               handlers.clj:  428
                              clojure-lsp.feature.format/range-formatting                 format.clj:  137
                                                     rewrite-clj.zip/node                   zip.cljc:  178
                                      rewrite-clj.custom-zipper.core/node                  core.cljc:   55
                                                         clojure.zip/node                    zip.clj:   67
java.lang.NullPointerException: 

borkdude13:04:29

feels like a classic zipper out of bounds NPE error

andrea.crotti13:04:56

I'm on

clojure-lsp 2023.02.27-13.12.12
clj-kondo 2023.02.17
which looks like the latest

borkdude13:04:02

Should this be repro-able using clojure-lsp format?

ericdallo13:04:11

yeah, weird I can't repro

ericdallo13:04:27

clojure-lsp format will call the format whole buffer, probably won't repro that

ericdallo13:04:36

that is only using range which is lsp-format-region

andrea.crotti13:04:39

yeah clojure-lsp format works fine

ericdallo13:04:09

@U0524T275 would help if you get client<->server logs and check what client is sending to server to range format

andrea.crotti13:04:38

actually one think I didn't mention is that I selected the form before pressing TAB for the formatting

andrea.crotti13:04:17

if I just do TAB before the form on (def x 3) without selecting anything it works

ericdallo13:04:29

yeah, that's one of the things I tried as well

andrea.crotti13:04:29

but well actually it's not even deterministic

andrea.crotti13:04:40

since sometimes it just works

ericdallo13:04:46

yeah, that make things harder to debug

andrea.crotti13:04:47

most of the times it works tbf

andrea.crotti13:04:01

I'll check that it's not my Emacs config somehow after work

andrea.crotti11:04:03

I just nuked my elpa directory, reinstall everything and it still does the same

andrea.crotti11:04:19

I'll see if it I can replicate it somehow with a minimal config

andrea.crotti11:04:51

I really can't find any pattern in when it happens or useful log

andrea.crotti11:04:58

I'll just disable the lsp indentation for now I guess until I find out

👍 2
borkdude17:04:36

@ericdallo Hmm, in clj-kondo when I have :cljc {:features [:clj]} in my .clj-kondo/config.edn, clj-kondo should only lint the #?(:clj branches, and this works with clj-kondo on the command line, but with clojure-lsp that doesn't seem to work. As an example project you can look at https://github.com/babashka/process

2
borkdude17:04:55

$ clj-kondo --lint src
linting took 57ms, errors: 0, warnings: 0

ericdallo17:04:17

I didn't know about that kondo config, could you elaborate what you would expect from clojure-lsp? is your problem with clojure-lsp CLI or editor?

borkdude17:04:20

Interestingly:

$ clojure-lsp-dev diagnostics
[100%] Project analyzed
Finding diagnostics...
Execution error (NullPointerException) at java.util.regex.Matcher/getTextLength (Matcher.java:1769).
Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null

Full report at:
/var/folders/j9/xmjlcym958b1fr0npsp9msvh0000gn/T/clojure-6415229798231618710.edn

borkdude17:04:25

My expectation is that clj-kondo config is not tampered with and it just lints the features that I describe in my config.edn

borkdude17:04:10

I'll update clojure-lsp from master, maybe it helps

borkdude17:04:19

no, same NPE

borkdude17:04:48

[[java.util.regex.Matcher getTextLength "Matcher.java" 1769]
   [java.util.regex.Matcher reset "Matcher.java" 415]
   [java.util.regex.Matcher <init> "Matcher.java" 252]
   [java.util.regex.Pattern matcher "Pattern.java" 1149]
   [java.util.regex.Pattern split "Pattern.java" 1277]
   [java.util.regex.Pattern split "Pattern.java" 1350]
   [clojure.string$split invokeStatic "string.clj" 225]
   [clojure.string$split invoke "string.clj" 219]
   [clojure_lsp.feature.diagnostics$kondo_findings__GT_diagnostics$fn__18370
    invoke
    "diagnostics.clj"
    123]
   [clojure.lang.Delay deref "Delay.java" 42]
   [clojure.core$deref invokeStatic "core.clj" 2337]
   [clojure.core$deref invoke "core.clj" 2323]
   [clojure_lsp.feature.diagnostics$diagnostics_start_char_coll_QMARK_
    invokeStatic
    "diagnostics.clj"

borkdude17:04:31

When I do:

(defn ^:private kondo-findings->diagnostics [uri linter db]
  (let [range-type (settings/get db [:diagnostics :range-type] :full)
        ;; we delay for performance
        lines* (delay (some-> (get-in db [:documents uri :text])
                              (string/split #"\r?\n")))]
    (when-not (exclude-ns? uri linter db)
      (->> (get-in db [:findings uri])
           (filter valid-finding?)
           (mapv (partial kondo-finding->diagnostic range-type lines*))))))
(change -> to some-> the NPE is solved)

borkdude17:04:37

and then the diagnostics are accurate

borkdude17:04:14

Ah I think it was the wrong project root for this project

borkdude17:04:19

now it works

borkdude17:04:29

but maybe it's good to keep the some->?

ericdallo17:04:20

ah yeah, that was a recent change related to the squiggles from your other issue, change to some-> makes sense

borkdude17:04:50

ok, please make the edit on master yourself, too small for a PR + test probably

ericdallo17:04:58

sure, thanks

borkdude17:04:21

do you want to practice your talk this week?

ericdallo17:04:13

I need to create it first 😂 I'm kind of late

😆 4