Closed dradtke closed 5 months ago
I used an autocmd in the AstroNvim Community Clojure pack to disable diagnostics in any buffer matching clojure-log-*
I assume something similar to disable Treesitter may be effective (but just a guess). I didnt notice an issue with Treesitter though (not a heavy user of the REPL log)
NOTE: I'll remove the autocmd in favour of the Conjure approach
On LSP, the lspconfig plugin sets autocommands on FileType
to autostart servers. There is a catch for the buffer option buftype=nofile
, but for log buffers this looks like it's set after the autocmd fires.
I quickly hacked this together to demonstrate. nvim.fn.bufload
was setting the filetype, and I had to explicitly set the filetype after.
https://github.com/PaterJason/conjure/commit/768580b5a639429a782576c1c6699c3b505798ad#diff-e0903b23fec5b0ccc884fe0be027056d0a7bb5c55bb73ecc58a0d56377353811
Oh interesting! So maybe if I just change the order of the buftype setting it'd help some people out. I kind of like the LSP / linting in the log buffer because it helps me autocomplete, doc lookup and edit the contents in the same way as I would a normal buffer.
I get that some people wouldn't want that but this is why I opted (in the past) to say "disable it yourself" rather than disabling it by default in such a way that people couldn't turn it back on.
If I change the order and set buftype before the autocmd fires, I guess it turns off LSP for the log buffer? (in theory)
In doing so, do I remove the ability for anyone to use LSP in the log without some hacking? Is there an easy way to then selectively turn it on for the users that do want the log to have LSP?
Maybe if nofile
doesn't really do much for us (I feel like it does?) we could move it so it's set at the right time and then make it optional so people can ignore the nofile option, thus kinda making an LSP toggle, although an indirect one.
Of course this behaviour will change / break if the plugins we're trying to toggle change their behaviour. Which is another reason I never wanted to do this from Conjure's side. Conjure makes a Clojure buffer, your plugins hook into that buffer, I mostly feel like it's the duty of those plugins to be easily configurable to NOT fire for some buffers or patterns and I shouldn't try to actively block plugins from hooking into the log buffer since there could be infinitely many plugins and they may change behaviour from under me.
So I'm not 100% settled on the way forward yet, but this is really interesting information and I'd like to find a solution that keeps both camps happier for the long term (people who want linting in the log and people who don't).
One thing to note here is that there are really two different kinds of Clojure: one that you might see in a source file, and one that you see in a REPL (or the log buffer). As a quick example, here's what I see when I evaluate a simple source file:
clojure-lsp
understands the source file, but it doesn't seem to really understand the log buffer. This is the type of diagnostic warning that I was looking to avoid, since evaluating larger files results in the log buffer filling up with errors.
So, one possible solution for me would be to somehow tell clojure-lsp
that the log buffer should be evaluated within the context of the project, rather than as a standalone file. I'm not sure if that's possible, but it would be nice to keep LSP and diagnostics enabled if they can actually be useful.
Having a look, lspconfig doesn't want to attach at all to nofile
buffers, using either :LspStart
or the autostart. Stopping and starting wouldn't attach to an open log buffer for example. Which makes sense, a nofile
is not really part of the workspace. You can force it by starting the server using the builtin lua, which is relatively simple nowadays.
vim.lsp.start({
name = "clojure_lsp",
cmd = { "clojure-lsp" },
root_dir = vim.fs.root(
0,
{ "project.clj", "deps.edn", "build.boot", "shadow-cljs.edn", ".git", "bb.edn" }
),
})
And trigger that by autocmd. But if you wanted to do that for each filetype I can see it being a pain.
Personally I'd set the buffer options before FileType
autocmds, cos setting it after would potentially circumvent the intent in the lspconfig or other plugin/config.
I've pushed a change to develop that turns off diagnostics in the log by default. There is a config option to turn them back on. This way we only remove diagnostics but can still use doc lookup and go to definition on various symbols in the log.
Also added a flag for treesitter although this one is NOT off by default because I think it's mostly useful and people will want it on. It's worth turning off if you end up doing lots of work in one project that causes your editor to slow down. This varies by machine too. So diagnostics: Off by default. TS: On by default.
I also am not sure if I'm fully disabling treesitter or not, I'll need someone to check that for me with something that used to be too slow with it enabled.
I tried https://github.com/Olical/conjure/commit/f6e4eecc35588e5b9f11eebeb042b74e53ec3f7c and it helped with displaying large output to log buffer, making it no longer crash neovim. Thanks for this work!
Nice! I do think the LSP disabling call needs to be called more often though, looks like as I open and close the log the diagnostics come back.
The log buffer is great for scrolling through output, but there are a few annoyances with it when using LSP and Treesitter:
My solution to these problems currently looks like this (unrelated sections of my config omitted for brevity):
It would be nice if Conjure were able to handle these scenarios on its own, or at the very least recommend a solution like this in the README.
The Treesitter solution was inspired by this post, so it appears others have run into this as well and built their own solutions for it.