Fork me on GitHub
#calva
<
2022-09-22
>
skylize16:09:18

(/foo :bar)
Here /foo is an invalid symbol, as indicated by the linter Invalid symbol: /foo. Okay. But after command Barf Forward
(/foo :bar)    -->    (/foo) :bar
and again after Slurp Forward on that result,
(/foo) :bar    -->    (/foo :bar)
the error emits as a popup. (Same for Slurp/Barf Backward if the invalid expression is on the right).

pez16:09:25

It seems to me like that pop-up originates from clojure-lsp. Can you check the log?

skylize17:09:20

Here's the log. • File contents`(/foo :bar)` • Cursor position (/foo| :bar)Barf Forward Dev Console shows

[ExtensionHost] `_formatIndex`: Invalid symbol: /foo.
thrown by internal console.tsfile, with only Code internals in the stack trace. Clojure LSP log: Lines 1-38 are before barf, and 39+ is after. (Tailed log in an external terminal to avoid editor focus changes triggering additional calls to clojure-lsp.)

pez19:09:50

Thanks. Now the question is if clojure-lsp is doing something wrong to cause those pop-ups or if it is something we should be configuring in Calva to avoid. Please file an issue, @U90R0EPHA.

skylize20:09:12

Happens before lsp starts. Thrown by _formatIndex in src/calva/calva-fmt/src/format.ts. It calls out to formatTextAtIdx which is really format-text-at-idx-bridge in src/cljs-lib/src/calva/fmt/formatter.cljs, and that farms out to format-text-at-idx. So far I've got it pinned to format-text-at-idx, as it goes in there with no indication of error, but comes out with a map that includes :error "Invalid symbol: /foo.". When it gets back up to _formatIndex, it throws because the error key exists. I presume this is intended to bubble up unexpected errors that prevent formatting with cljfmt? But in this case, it's throwing a what amounts to a lint error.

skylize20:09:06

btw. Very annoying to wait for lsp to download everytime I reload a window. Would be nice if we compared versions instead of downloading blindy.

pez20:09:29

We only download blindly with nightly, I think. Hopefully most people are not reloading the window all that often. But you are welcome to file an issue, of course.

skylize22:09:57

Call to cljfmt/reformat-string throws this exception

#error {:message "Invalid symbol: /foo.", :data {:type :reader-exception, :ex-kind :reader-error}}
Caught in format-text at line 61 of src/cljs-lib/src/calva/fmt and transformed to an {:error message}map key. Then _formatIndex both logs it to the console and rethrows at lines 224-225 of src/calva/calva-fmt/src/format.ts. So I guess this is upstream. Would it be considered a bug upstream? Should we selectively ignore exceptions?

pez04:09:51

It's probably rewrite-clj. See if you get a similar error with the new pretty-print-replace command.

skylize04:09:16

Yes. Same error.

pez04:09:41

@UE21H2HHD do you think this should be reported as an issue in rewrite-clj?

pez05:09:34

@U90R0EPHA unless it isn't as obvious to you as it is to me. 😃 The pretty-print-replace command is not using cljfmt, but instead using z-print. Both are using rewrite-clj. As is clojure-lsp (or, rather clj-kondo), which caused some confusion about what was making Calva pop that message open.

lread12:09:59

I'll take a peek later. I did make a change to https://github.com/clj-commons/rewrite-clj/blob/main/doc/design/01-merging-rewrite-clj-and-rewrite-cljs.adoc#questionable-decisions... the thinking was maybe just don't use invalid symbols? Not fully awake yet... we are looking at an invalid symbol yeah?

skylize13:09:44

Yes. And in the case of Calva, it's good that clj-kondo sees it as such, but bad that it's bubbling it's way up as an exception through cljfmt.

lread13:09:28

clj-kondo also uses an internal version of rewrite-clj. Rewrite-clj all around!

😎 1
pez07:09:54

I think “just don’t use invalid symbols” doesn't work in editor tooling. The text, while being edited, will often be in an invalid state. The editor still needs to be able to help the user with formatting and structural editing.

skylize23:09:29

Looks like a match. What are your thoughts after having almost 2 years to sleep on it?

lread23:09:12

Oh I’ve not been sleeping @U90R0EPHA! But not been thinking about this for 2 years either.

lread23:09:22

I’d have to ramp up on the issue again and invest time in it. If I remember correctly symbols were easier, other invalid source like unmatched parentheses harder.

skylize23:09:43

Haha. No. I meant like "let me sleep on this" (to make a decision about something).

lread23:09:30

Oh I thought you were being a bit of a 😈! My apologies.

skylize23:09:47

Assuming the worst for a moment, that might be too difficult to meet the needs of the use-case in that issue; is it generally useful to consumers to throw an exception here? In the case of Calva, such broken code is definitively not "exceptional", even if it prevents offering useful results.

lread23:09:05

Yeah rewrite-clj has a long history. It’s original author wrote it to update the version in his project.clj! It has been adopted for uses beyond his wildest dreams. Drop by #rewrite-clj if you wanna discuss. I’m a bit distracted with another project at this moment, but will try to respond… also I have a very talented co-maintainer who might chime in!

skylize20:09:38

Which build script should I be starting for development? Instructions at https://github.com/BetterThanTomorrow/calva/wiki/How-to-Hack-on-Calva are not clear on this. A couple days ago, I struggled because using Ctrl-Shift-B was bringing up a menu of many npm scripts. Then I tried using Command Palette instead, and somehow it just worked, loading up all the different watchers each in a tiled terminal. But today, using the Command Pallete is also giving me the menu. None of the scripts in the menu look to me like a catch-all. (Right now I'm just starting the npm watch-ts and then npm watch-cljs)

1
pez20:09:53

It's supposed to be THE build script. Not sure what's going on when ctrl+shift+b is not doing that…

skylize20:09:57

It's showing me all the entries in package.json.scripts, and a tsc build and tsc watch for each of tsconfig.jsonand tsconfig.eslint.json. Is THE build script any one of those? Or is it supposed to be some other file?

skylize20:09:18

Hmmm. Seems like I'm somehow missing .vscode folder, which I can see from Github is supposed to be included. I bet that's the problem.

skylize20:09:58

Yep. That was the problem. No idea how that folder got deleted.

metal 1
pez05:09:00

Do you think we need to clarify something on the wiki, or is it clear enough, given that you haven't mysteriously deleted the tasks?

skylize12:09:15

My initial difficulty could not have been caused by missing VS Code Task files, because it worked fine running the build script command from the Command Palette. But now I cannot replicate the problem of calling it with a hotkey. So I can't really suggest any changes at the moment.

pez12:09:59

Could that have been some stateful behavior of VS Code? It remembered what had been in the deleted file.

skylize12:09:41

How would it remember something I had never used before?

pez08:09:43

It depends on when it was deleted. The file contains the instruction’s for starting all those tasks as you described it did. It seems VS Code could only have been informed from that file.