cmd icon indicating copy to clipboard operation
cmd copied to clipboard

(macro) unknown method :on-string invoked on nil

Open 0xmycf opened this issue 7 months ago • 2 comments

when testing a project with judge like this:

(declare-project
  :name "judge / cmd test"
  :version "0.1.0"
  :dependencies [{:url "https://github.com/ianthehenry/judge.git"
                  :tag "v2.9.0"}])

(declare-executable
  :name "ttt"
  :entry "src/init.janet")

and

(use judge)

(defn foo [x] (+ 1 x))

(test (foo 1))

I can do run judge and it will execute the tests, though the lsp shows me this error: (macro) unknown method :on-string invoked on nil.

I am not sure if this is an lsp problem or an cmd problem. Though I suspect this has something to do with the lsp, since the judge executable works...

  • janet --version: 1.38.0-release.

0xmycf avatar Jun 14 '25 20:06 0xmycf

Hi! That's weird. The only part of Judge that references cmd at all is the runner script, which is not imported or referenced when you just use judge. I'm not sure what you mean by "I can do run judge" though; I have never used janet-lsp so I can't say how it's invoking it. That error does seem like a bug in cmd, but having read over the code I really can't think of how to get the state to be nil at a time when we're calling on-string. Is there some way to see what it's invoking?

ianthehenry avatar Jun 16 '25 03:06 ianthehenry

Hi there, Janet LSP author here. cmd has always caused the LSP to throw errors. I tried my darndest to track it down a while back, and as close as I can tell it's something to do with the interaction between the LSP's custom flychecker and the fact that cmd shadows def and defn—the error is coming about because some module code is not fully executed when the LSP loads it up, so when it comes to a point where :on-string is invoked the object is not actually initialized as having that method yet.

But the good news is, this is only happening in the runtime of the LSP. It shouldn't affect actual usage of cmd or judge in any other context.

CFiggers avatar Jun 16 '25 05:06 CFiggers