Background
So I’ve been hacking away at a simple styled component library for Phoenix (source here if you’re curious - not done!) which uses a custom Mix compiler to compile the stylesheet.
I’d been dealing with a weird issue where the stylesheet gets recompiled multiple times (triggering multiple live reloads in the console), and I hadn’t been able to track down the root cause. I figured I would get around to making a post about it eventually.
Fast-forward to today, I was testing some config changes when I noticed that the compiler was writing a stylesheet even though it was disabled (via config). Obviously something strange was going on, so I investigated further, but after thoroughly instrumenting the code with IO.inspects (as one does) I was unable to figure out what was invoking the compiler - it wasn’t printing anything, but it was still writing the output!
At this point fully convinced my compiler was haunted, I tried killing the Phoenix server and inspecting the output stylesheet to see if it was still compiling. Which it was. Obviously I had a phantom process somewhere, so I checked the process list and, sure enough, there were a couple extra beam processes floating around.
I stared at the process list for about 10 seconds before it hit me. The LSP!
Question
Is there a canonical way to stop the LSP (elixir-ls in this case) from invoking my Mix compiler?
One way to do this which I think would work is to fingerprint the LSP calls via the args
that they pass into the compiler’s run/1
function. In particular, a bit of logging reveals that the LSP calls the compiler with the --return-errors
flag (and a couple other unusual flags), which I presume is uncommon in normal usage. But this feels like a hack.
Also, does anyone know if and how Surface solves this problem with their compiler? A quick look through their code/issues didn’t reveal anything pertaining to the LSP.