Code Monkey home page Code Monkey logo

neovim_diagnostic_filter's Introduction

TL;DR

Add below strings in diagnostic.lua.

  if last.message:find("unbound") or 
     last.message:find("is not accessed") or
     last.message:find("Cannot access member") or
     last.message:find("Argument of type") then
    return nil
  end

About

How to filter Neovim diagnostic (like below "randint" is ...) with some specific strings.

  • Not kill all diagnostic function.
  • Not suppress specific diagnostic level (like hiding less than warning level).

image

How to

Add below text in neovim/runtime/lua/vim/diagnostic.lua, around line number 1065. Then, restart Neovim.

  for i = 1, #line_diags - 1 do
    table.insert(virt_texts, { prefix, virtual_text_highlight_map[line_diags[i].severity] })
  end
  local last = line_diags[#line_diags]

  -- ADDED FROM HERE
  if last.message:find("unbound") or 
     last.message:find("is not accessed") or
     last.message:find("Cannot access member") or
     last.message:find("Argument of type") or
     last.message:find("Import ") or
     last.message:find('Object of type "None"') or
     last.message:find('is not a known member of "None"') then
    return nil
  end
  -- UNTIL HERE

  -- TODO(tjdevries): Allow different servers to be shown first somehow?
  -- TODO(tjdevries): Display server name associated with these?
  if last.message then
    table.insert(virt_texts, {
      string.format('%s %s', prefix, last.message:gsub('\r', ''):gsub('\n', '  ')),
      virtual_text_highlight_map[last.severity],
    })
  • If you add last.message:find("xxx") with or in above code, you can filter "xxx" also.
  • If you're Mac user, find a location you installed Neovim. And modify Neovim/share/nvim/runtime/lua/vim/diagnostic.lua.
  • If you're Linux user and installed with AppImage, modify /squashfs-root/usr/share/nvim/runtime/lua/vim/diagnostic.lua.
    • Then, type ln -sf /squashfs-root/usr/bin/nvim /usr/bin/nvim in bash/zsh.
  • Be careful not to confuse with neovim/runtime/lua/vim/lsp/diagnostic.lua. You don't need to put /lsp/ before diagnostic.lua

Option

If you modify local prefix = opts.prefix or 'โ– ' located at the above of previous code, you can change prefix of diagnostic also.

local prefix = opts.prefix or '๐Ÿ‘€'

image

Note

  • I'm not professional of Neovim nor lua. Change code with your responsiblity.
  • As of today (3 Dec, 2022), I cannot find this info (= diagnostic filter) on the Internet (in spite of it seems this is normal demands). This code change may harm something?

neovim_diagnostic_filter's People

Contributors

laughingmanbtc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.