Fork me on GitHub
#calva
<
2022-08-15
>
farshlufen06:08:46

Hi, I started using Calva a few weeks ago and really like it! There is just one issue I'm having ... Calva starts up every time I start VS Code. I usually write Scala, so I don't need Calva running most of the time. It also creates the files .clj-kondo/.cache/v1/lock and .lsp/.cache/db.transit.json that I have to keep deleting. How can I configure Calva to not start unasked?

1
blogscot11:08:03

If you open up your extensions in VSCode you should see a settings icon for Calva bottom right. You can use that to manage when an extension is enabled. For example, you can enable / disable an extension for all your workspaces or per workspace. I had the same issue so I now I enable Calva per workspace.

pez11:08:23

Hi! Happy you like Calva! In addition to what @U0D6971L3 says: Calva shouldn't start unless there are Clojure files in the folder opened. If that happens anyway, we might have a bug. Regarding the the files created, I add .cache/ to my .gitignore so that I don't have to keep removing those directories.

Pratik19:08:20

I also remember opening my golang project, and having these directories, could be a bug

bringe03:08:31

If anyone can provide a repro case and an issue, that would be appreciated.

farshlufen06:08:05

In my case it starts Calva even when I open VSCode in an empty directory. In case you have any pointers where I should start looking in the Calva code, I could try and see if I find the issue.

pez07:08:28

That definitely shouldn't happen. This behaviour is defined in the extension manifest (`package.json`) like so:

"activationEvents": [
    "onLanguage:clojure",
    "onCommand:calva.startStandaloneRepl",
    "onCommand:calva.startStandaloneHelloRepl",
    "onCommand:calva.startStandaloneCljsBrowserRepl",
    "onCommand:calva.startStandaloneCljsNodeRepl",
    "onCommand:calva.calva.startJoyrideReplAndConnect",
    "onCommand:calva.jackIn",
    "onCommand:calva.startOrConnectRepl",
    "onCommand:calva.connect",
    "onCommand:calva.connectNonProjectREPL",
    "onCommand:calva.convertJs2Cljs",
    "onCommand:calva.convertDart2Clj",
    "workspaceContains:**/project.clj",
    "workspaceContains:**/shadow-cljs.edn",
    "workspaceContains:**/deps.edn",
    "onDebugResolve:type"
  ],
Maybe it is some other extension doing something. I don't quite know what that onDegbugResolve:type is doing there. Maybe some other extension can trigger it.

farshlufen07:08:51

I found some https://github.com/microsoft/vscode/issues/37918 https://github.com/microsoft/vscode-java-debug/pull/196 that indicate that onDebugResolve:type could indeed have such an effect, but I don't yet understand it well. I also found out that Calva only starts up automatically when I also have the Joyride extension enabled. Once I disable it, Calva does not start automatically.

pez07:08:37

Thanks for researching, @U03M8C02BHS. Can you add an issue on Calva where we can track this?

farshlufen07:08:40

Yes, I will create an issue.

pez07:08:58

I actually suspected Joyride a bit, but I have it enabled myself and do not see this behaviour. Could be that a difference in our respective user_ctivate.cljs scripts can give us some more hints. I see this in my-main:

...
  #_ ; <- remove this to un-ignore
  (-> (vscode/extensions.getExtension "betterthantomorrow.calva")
      ;; Force the Calva extension to activate 
      (.activate)
  ...

farshlufen07:08:00

If I enable Joyride and disable Calva, Joyride will start automatically when VSCode is opened in an empty directory. Perhaps I should create the issue on Joyride then.

pez07:08:54

That's expected behaviour from Joyride.

farshlufen07:08:24

So Joyride should start unconditionally?

pez07:08:02

Yeah, it needs to start in order to be ready to script VS Code regardless of folder opened and such.

farshlufen07:08:51

However, I am now getting

ERROR: Run Failed: user_activate.cljs Cannot read properties of undefined (reading 'activate')
so it seems that it is trying to activate Calva, as in the snippet you posted above:
;; Force the Calva extension to activate 
      (.activate)

pez07:08:05

Maybe you have removed that ignore marker and are actually trying to force activate Calva?

pez07:08:26

Or, you happened to install Joyride when the user_activate script didn't default to commenting it out...

farshlufen07:08:11

This is with the standard installation of Joyride and Calva, I didn't edit anything. Here is the issue: https://github.com/BetterThanTomorrow/calva/issues/1830

farshlufen07:08:45

Aha ... my user_activate.cljs instead looks like this:

(-> (vscode/extensions.getExtension "betterthantomorrow.calva")
      ;; Force the Calva extension to activate 
      (.activate)
so this part
#_ ; <- remove this to un-ignore
is missing. This must be it.

pez08:08:11

Yeah. There we have it. This issue is fixed for new Joyride installs, but for existing installs it needs to be fixed manually. If you haven't edited the script at all, you can delete it and Joyride should install the updated script.

pez09:08:07

Ah, then an issue in Joyride is welcome.

farshlufen14:08:08

I created an https://github.com/BetterThanTomorrow/joyride/issues/84. For now I have changed the file locally.

pez15:08:07

Once the file exists Joyride won't update it. (In case that was not clear yet.)

Christian Maus08:08:48

Hi there, I’m a bit unsure about the autocompletion feature in calva. The autocompletion will give me a list of the available functions in a required namespace when using autocomplete for a prefix of the namespace name. But it is giving me a dot-separated suggestion instead of using / as a delimiter. See the attached screenshot. Furthermore, when using an alias for the required namespace, then auto-complete will not return any result, also when trying to autocomplete sth like java-time/form Are these known limitations or is there something wrong with my setup? :thinking_face:

pez12:08:51

Hello! Regarding dots vs slashes. java-time.format is a namespace, so it shouldn't be used as java-time/format, or am I misunderstanding your question?

Christian Maus14:08:11

Mhh, then I am seriously confused by this example straight from https://clojure.org/guides/deps_and_cli

(ns hello
  (:require [java-time :as t]))

(defn time-str
  "Returns a string representation of a datetime in the local time zone."
  [instant]
  (t/format
    (t/with-zone (t/formatter "hh:mm a") (t/zone-id))
    instant))

pez14:08:12

Yeah, maybe I am confusing things. Let me check it closer.

Christian Maus14:08:51

It seems that the module java-time.format defines a function format. That function is imported into java-time, if I’m not mistaken

Christian Maus15:08:10

So, it seems the use of the macro potemkin/import-varskind of makes it hard to inspect the namespace 😞

(ns-publics 'java-time) => {}

pez15:08:42

I'm sorry for adding to the confusion. There is both the namespace I mentioned and the function you mentioned. I just tried this a bit. Without potempkin I get the namespaces completed for something like java-, and reach the symbols in java-time using java-time/. And I can complete t/ using the alias in the example. However, import-vars seems to trip things up, as you've found. Maybe a structure like the one suggested by #polylith can be used instead? It adds some boilerplate, but is generally pretty nice.

Christian Maus15:08:45

@U0ETXRFEW Sorry, seems to be my mistake. If I evaluate the file so that the required namespaces are actually evaluated, then I also get the function completions like java-time/format. However, if I do not evaluate the file in the repl, then I will only get the completions for the namespaces. This is probably due to it being analyzable statically, I suppose. Thanks for looking into it

pez15:08:43

Makes sense. When a REPL is connected you get dynamic completions. Sounds like the static completions is lacking a bit here. Maybe something to bring up in #lsp.

vlad_poh18:08:25

Long edn on a single line. How do i get calva to format it nicely (pretty print)

bringe03:08:22

Where is the edn coming from? Is it a result of an evaluation or copied from somewhere into your editor?

bringe03:08:28

If it’s a result you can enable pprint to see it pretty printed (see the bottom status bar -> pprint button). If it’s some long edn you copied from somewhere, you could call clojure.pprint/pprint on it. You could also use the command to evaluate and replace the result in the editor with the call to the pprint function and then you’ll have it in the editor (if that’s what you want).

pez14:08:33

We probably should consider adding a command to Calva that can pretty print the current form without using the REPL. Calva's pretty print function does not evaluate stuff, and can thus be used for EDN/Clojure data which pprint via the REPL croaks on.

👍 2