Treesitter-style LSP diagnostics

I am searching for either full treesitter support for LSP or LSP only being active on selected lines.
This is because I want to write a markdown file that contains code snippets.
My current way of how to solve this problem is way too complicated:
Use treesitter to get lines of code and copy them to a temp file.
Run the LSP in that temp file and return the diagnostics.
Is there a better way to do this?

I’ve actually searching for a solution to this for a long time. I’ve moved from doc on which there were an option like “only_current_line” which allowed to only show diagnostics on the current line.
I think that a solution may be to use vim.diagnostic.get() function which allows to get the diagnostic for the current buffer & current line. In your case it may be enough but in my case I still need to find a way to print it as virtual text.

1 Like

Can you try if this correctly output a table of informations about the diagnostic on the current line?

local current_line = function()

    local line = vim.fn.line('.') - 1
    local diags = vim.diagnostic.get(0, { lnum = line })

    print(vim.inspect(diags))

end