cider

Jim Newton 2025-04-15T12:52:02.552559Z

is there a convention for what to do in a macro (while expanding the macro) to signal to the IDE to annotate the code in some way. For example I have a macro which sometimes detects unreachable code. It would be great if that could annotate the code if the user loads the file inside cider …

2025-04-19T14:49:01.627219Z

Normally it's done by throwing an exception. But I understand you want more of a "warn". I'd say that's normally done by printing. Since you'd be connected to a REPL, you would see something being printed. This is what the compiler does to notify you of warnings.

Kirill Chernyshov 2025-04-15T13:24:53.183399Z

throw exception?

Kirill Chernyshov 2025-04-15T13:25:36.421809Z

is unreachable code intentionally added by the macro?

Jim Newton 2025-04-15T13:26:00.871129Z

I don’t want to throw an exception. the code will still work.

Jim Newton 2025-04-15T13:26:09.473269Z

I just want to notify the ide to annotate something.

Kirill Chernyshov 2025-04-15T13:27:00.203939Z

I don't know if cider annotate anything. Maybe look at clojure-lsp and how it can unravel macroses

πŸ‘πŸ» 1
Jim Newton 2025-04-15T13:27:11.384979Z

imagine for a very very simple case that I have a my-if macro, and during the macro expansion, it realizes that the else part is unreachable. the code still works, but it would be nice to notify the user of this fact.

Jim Newton 2025-04-15T13:27:32.496719Z

in common lisp and slime, the macro expander is allowed to raise a warning condition.

Jim Newton 2025-04-15T13:28:16.755819Z

conditions being a generalization of exceptions used in CL

Kirill Chernyshov 2025-04-15T13:29:54.611449Z

I'm not aware if similar technic exist in clojure

Ed 2025-04-15T13:40:16.911959Z

I think the most used mechanism for this would be clj-kondo hooks. https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md

πŸ‘ 1