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).
Is there an easy way to get the first chunk of the string (I don’t care about the rest of it)?
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
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…Ah, looks like :warn
isn’t valid and that’s hiding my notifications… Sorry for the noise.
Has to be :warning
… OK, making progress again… sorry 😐
OK, confirmed that calling (str (:result res))
just produces [object Object]
in the case of a long (ellipsis) string.
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).
@seancorfield JS interop is supported in sci
At least it should be, if something doesn't work, you can bug me about it in #sci
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…
@seancorfield (.log js/console x)
sometimes gives some hint
Inside VS Code? Where would I even find the “console” log?
(and I already know it renders as [object Object]
when I try to print it as a string)
I tried adding (.log js/console res)
to my config.cljs
file and none of the tasks will run at all.
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.
Yeah, I’ve spent hours trying to debug this but none of the “standard” stuff seems to work.
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.
Hi, just woke up :)
So, for some context - unrepl exposes long strings as these ellipsis. This converts to a deftype in Clover, that's being shown as [Object]
Yup, figured that was it. Calling str
doesn’t return all/part of it though. Is there some other instance method I can call?
I believe it's a bug. I'll fix it
In the meantime, see if calling (.only_str (:result....))
works
Will try…
Could not find instance method only_str
😢
I'll push a fix real quick now
@mauricio.szabo if this is a bug with #sci somehow, let me know
No, it's on my side
Thanks @mauricio.szabo
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)?
Just (str ....)
will do
I'll add a default conversion to string
Nice.
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.
Where I tripped up on this was trying to display (the first part of) the failure message in the popup.
Oh, wow! I had a test for this issue, but I saw that it indeed works for some commands but not all 😞
@seancorfield just published a fix. MS says that it'll be on on some minutes 😄
Appreciated! I will let you know how it goes 🙂
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 🙂
@mattias504 You can run whichever you prefer — and have the “same” editing/evaluation experience in both.
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.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
@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.
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.
If you haven’t seen @borkdude: https://www.youtube.com/watch?v=LNo-j-pD6co
@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!
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.
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.
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.
Monoliths bad, polyliths good 😆
Thanks
@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 😄
@borkdude, it was more towards you being curious than the particular question.
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?
Calva is more of a polylith under the hood actually. But not enough, or I should have managed to tease the structural editing out.
In fact, there are a number of callbacks that are registered TWICE for vscode, because of its API limitations
Drew this the other day. For my presentation at Seajure in May:
In Atom, there's really only "one" API - the editor itself. On VS, there's the "editor" API and the "Webview" API
ok, but you essentially created a library that you can hook up to the specifics of the editors, this is what I expected
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" 🎉
Bug compatibility is the seal of success. 😃
I keep using Atom. I don't really have any issues with it 🙂
I'll put on the description of Clover: Bug compatibility with Chlorine 😄
@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.
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.
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.
Our subprojects have become complected over time. I think Polylith’s guiding principles will help guard against that.