piersolenski / wtf.nvim

Delicious diagnostic debugging in Neovim 🤤
400 stars 9 forks source link

Feature idea: A way to edit the diagnostic before sending to browser #11

Closed nihancj closed 1 year ago

nihancj commented 1 year ago

I've been using your plugin for a couple of weeks and it's been really useful. Would you be intrested to implement some way for the user to edit the error/diagnostic message given by the lsp before it is sent to the searched. I usually find myself editing the search query in the web browser to get the result I want. It's not very common that I want to search for the exact error word for word. (For example: If I'm coding in c and get a type error with a struct. Searching for that custom named struct name won't get any result).

piersolenski commented 1 year ago

Sounds interesting!

Ideally I was hoping to make WtfSearch as automated as possible. For example, the WtfSearch command already attempts to strip out things like file paths idiosyncratic to the user's setup that would convolute the search query - although I've not spent that much time on it, I'd like to add more functionality there.

Personally I find the first search usually gives me what I need, but I totally agree I'll often tend to refine it if it doesn't. However, I usually do this in the browser, rather than wanting to jump back and forth between Vim each time. If you're not using it already, I'd highly recommend https://github.com/brookhong/Surfingkeys which would allow you to edit the term in the search form using Vim bindings (there's also solutions such as https://github.com/glacambre/firenvim out there).

We could potentially add something that sends the current line diagnostic to a separate buffer or popup, where you can edit it, then open it in the browser - I will give it some thought, as I know it could also be useful for those using Vim on the server. Personally I still think the editing in the browser is more frictionless, as it it's extra overhead switching back and forth between that and Vim, and the core philosophy behind wtf.nvim should be about automating away grunt work rather than adding steps.

If you want to trial your idea, the genesis ofwtf.nvim started with this snippet I had in my config for a long time - you can use this as a starting point. I'd be keen to hear back about what you come up with and how it fits into your workflow!

_G.search_diagnostic = function()
    -- Get current buffer
    local bufnr = vim.api.nvim_win_get_buf(0) -- 0 = current buffer
    -- Get current line
    local line = vim.fn.line(".") - 1
    -- Get diagnostic
    local diags = vim.diagnostic.get(bufnr, { lnum = line, severity = { min = vim.diagnostic.severity.HINT } })
    -- Get first diagnostic message
    local diag = diags[1]
    local lines = vim.split(diag.message, "\n")
    local message = lines[1]
  -- DO WHAT YOU WANT WITH MESSAGE HERE
end
piersolenski commented 1 year ago

I'll close this for now but let me know if you come up with something cool!