Fork me on GitHub
#chlorine-clover
<
2021-04-15
>
seancorfield01:04:24

I’m updating my test-running code as local config.cljs functions and stuff mostly works the way I expect, but if I eval-and-render and the result is a long string that gets an ellipsis, it seems that (:result res) is some sort of JS object (where res is bound via p/let to the result of the eval).

seancorfield01:04:09

Is there an easy way to get the first chunk of the string (I don’t care about the rest of it)?

mauricio.szabo02:04:27

I believe that if you use str or pr-str, it'll return the string. If it doesn't, I can look at it tomorrow morning

seancorfield02:04:00

I have this code

(editor/run-callback
         :notify
         (if (:error res)
           {:type :warn
            :title "Failed to run tests for"
            :message test-name}
           {:type :info
            :title test-name
            :message (:result res)}))
and if it is an ellipsis string, I get [object Object] and I don’t seem to be able to perform any operations on it at all…

seancorfield03:04:26

Ah, looks like :warn isn’t valid and that’s hiding my notifications… Sorry for the noise.

seancorfield03:04:45

Has to be :warning… OK, making progress again… sorry 😐

seancorfield03:04:05

OK, confirmed that calling (str (:result res)) just produces [object Object] in the case of a long (ellipsis) string.

seancorfield04:04:22

Presumably I can call some JS methods on it, but I haven't figured what's valid (and I don't know what JS interop is available in sci for this anyway).

borkdude06:04:18

@seancorfield JS interop is supported in sci

borkdude06:04:47

At least it should be, if something doesn't work, you can bug me about it in #sci

seancorfield06:04:26

I found I could (catch js/Error e ..) so that helped. But my JS knowledge is pretty much non-existent so, given some arbitrary JS object, I’ve no idea how to debug what methods I could call on it…

borkdude07:04:13

@seancorfield (.log js/console x) sometimes gives some hint

seancorfield07:04:36

Inside VS Code? Where would I even find the “console” log?

seancorfield07:04:06

(and I already know it renders as [object Object] when I try to print it as a string)

seancorfield07:04:41

I tried adding (.log js/console res) to my config.cljs file and none of the tasks will run at all.

borkdude07:04:23

oh I don't know about VSCode and this tooling. It also depends on how sci is configured. I will wait for @mauricio.szabo's reply on this.

seancorfield07:04:04

Yeah, I’ve spent hours trying to debug this but none of the “standard” stuff seems to work.

pez08:04:15

js/JSON.stringify (or something like that) should print the object, unless you have circular references there. It takes a second argument where you can prettify the output. Not sure what the context is for this you are trying to do, but it sounds like you might find the js/console.log output in VS Code’s Developer console, which you find both in the Help menu and in the command palette.

mauricio.szabo11:04:00

Hi, just woke up :)

mauricio.szabo12:04:15

So, for some context - unrepl exposes long strings as these ellipsis. This converts to a deftype in Clover, that's being shown as [Object]

seancorfield14:04:41

Yup, figured that was it. Calling str doesn’t return all/part of it though. Is there some other instance method I can call?

mauricio.szabo14:04:56

I believe it's a bug. I'll fix it

mauricio.szabo14:04:50

In the meantime, see if calling (.only_str (:result....)) works

seancorfield14:04:25

Could not find instance method only_str

mauricio.szabo14:04:43

I'll push a fix real quick now

borkdude14:04:06

@mauricio.szabo if this is a bug with #sci somehow, let me know

mauricio.szabo14:04:17

No, it's on my side

seancorfield14:04:08

Once it is “fixed”, what should I expect to do in my code to get at the actual string (or even just the first segment of that string)?

mauricio.szabo14:04:27

Just (str ....) will do

mauricio.szabo14:04:33

I'll add a default conversion to string

seancorfield14:04:08

For background, I’m updating “run test at cursor” to a) work when the cursor is anywhere inside the whole form and b) inspect the result so it detects success/failure and pops up a notification about it.

seancorfield14:04:33

Where I tripped up on this was trying to display (the first part of) the failure message in the popup.

mauricio.szabo15:04:55

Oh, wow! I had a test for this issue, but I saw that it indeed works for some commands but not all 😞

mauricio.szabo19:04:01

@seancorfield just published a fix. MS says that it'll be on on some minutes 😄

seancorfield19:04:57

Appreciated! I will let you know how it goes 🙂

mauricio.szabo01:04:06

Nice! Glad to see it worked!

Mattias19:04:49

Hey, I haven’t kept up with everything - am I now supposed to run Atom or VS Code/VSCodium? Have them both installed, no real opinion myself 🙂

seancorfield19:04:29

@mattias504 You can run whichever you prefer — and have the “same” editing/evaluation experience in both.

Mattias19:04:52

Thanks! I had some vague notion that maybe VS Code was steamrolling everything. I’ve had only good experiences with Atom so... well. All good then, either way 😄

mauricio.szabo20:04:12

I keep using Atom. I don't really have any issues with it 🙂

👍 3
borkdude19:04:09

@mauricio.szabo How do you manage to provide the same editing experience for both editors? Do they offer a similar API or do you abstract their API? I'm not a heavy user of VSCode and don't use Atom but I'm always curious to learn

seancorfield19:04:23

@borkdude I’m not him but the core of the integration is in a common repl-tooling package and then he has both an Atom wrapper and a VS Code wrapper.

seancorfield20:04:04

When I switched from Atom to VS Code, my custom config (ClojureScript code, run via sci) was identical on both editors and I set up the exact same key bindings in both editors.

👍 3
seancorfield20:04:14

@pez BTW, I am still loving the fact that I can run Calva for everything-except-nREPL and continue using Clover for my favorite REPL setup via a Socket REPL! Thank you!

borkdude20:04:59

I have seen parts of it, but a REPL is not something you can run in an editor without doing some custom work for that editor, hence my question. It may have been discussed in the video and I might have missed that part.

seancorfield20:04:23

Just the other day, I connected VS Code directly to a Socket REPL running on our staging server to debug (and fix!) a problem an app that I couldn’t repro locally. No nREPL, no restart of the app, and no code needed in the app.

pez20:04:10

You are welcome, @seancorfield! I failed at teasing apart the monolith, and got stuck in that trail of thought. It was @ericdallo who saw what the workaround could be. Super easy to fix.

seancorfield20:04:38

Monoliths bad, polyliths good 😆

metal 9
polylith 9
borkdude20:04:43

I have seen the original polylith talk at ClojureD but all I remember is "it's like lego". Can you explain what polylith is other than creating libraries?

pez20:04:15

Calva is more of a polylith under the hood actually. But not enough, or I should have managed to tease the structural editing out.

pez20:04:55

Drew this the other day. For my presentation at Seajure in May:

seancorfield20:04:44

@borkdude It really isn’t about libraries. It’s an approach to working in a monorepo that takes a very structured approach to code organization and provides a clean separation between how you develop/test and how you actually build deployable “projects” from parts of your monorepo. It’s kinda hard to really “get” until you’ve used it — although recent changes to the website are helping, I think. The core thing that makes it “different” is the focus on small code “components” (bricks) that only interact via “interfaces” that are purely function definitions and that’s part of what allows for the “mix’n’match” approach to building stuff.

seancorfield20:04:27

Initially, I thought it was very similar to what we were already doing at work: we have 40 subprojects and we build just over a dozen artifacts from that in different combinations.

seancorfield20:04:53

But our deployable artifacts are very closely tied to the “main” subproject that contains their entry point — Polylith separates these — and our subprojects are very coarse-grained so you tend to get a huge “blob” of code (and dependencies) even when you just want one small portion of a subproject.

seancorfield20:04:31

Our subprojects have become complected over time. I think Polylith’s guiding principles will help guard against that.

mauricio.szabo20:04:08

@borkdude yes, it was like Sean said: there's a ClojureScript library called repl-tooling that handles everything. The library expects a bunch of callbacks, and if you register these callbacks (mostly) everything works 😄

🎉 3
pez20:04:10

@borkdude, it was more towards you being curious than the particular question.

🙏 3
mauricio.szabo20:04:30

In fact, there are a number of callbacks that are registered TWICE for vscode, because of its API limitations

mauricio.szabo20:04:00

In Atom, there's really only "one" API - the editor itself. On VS, there's the "editor" API and the "Webview" API

borkdude20:04:08

ok, but you essentially created a library that you can hook up to the specifics of the editors, this is what I expected

mauricio.szabo20:04:17

Yes, configurable by SCI so I can migrate the config between editors. In fact, I keep testing my code in Atom, and some bugs that appear on "Clover" are 100% reproducible/fixable from "Chlorine" 🎉

pez20:04:43

Bug compatibility is the seal of success. 😃

mauricio.szabo20:04:00

I'll put on the description of Clover: Bug compatibility with Chlorine 😄

😂 6