GithubHelp home page GithubHelp logo

whoissethdaniel / toggle-lsp-diagnostics.nvim Goto Github PK

View Code? Open in Web Editor NEW
96.0 3.0 10.0 27 KB

Neovim plugin for toggling the LSP diagnostics.

License: MIT License

Lua 72.09% Vim Script 27.91%
neovim lsp neovim-plugin neovim-lsp nvim-plugin nvim

toggle-lsp-diagnostics.nvim's Introduction

Description

A Neovim plugin for toggling the LSP diagnostics. Turn all diagnostics on/off or turn on/off individual features of diagnostics (virtual text, underline, signs, etc...).

Compatibility

Neovim >= 0.5.0

Installation

Install using your favorite plugin manager.

If you use vim-plug:

Plug 'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim'

Or if you use Vim 8 style packages:

cd <plugin dir>
git clone https://github.com/WhoIsSethDaniel/toggle-lsp-diagnostics.nvim

Configuration

Somwhere in your config you should have this:

require('toggle_lsp_diagnostics').init()

If you are using Vimscript for configuration:

lua <<EOF
require'toggle_lsp_diagnostics'.init()
EOF

To preserve the current diagnostic configuration upon initializing this module you can do the following (assuming your Neovim is at least 0.7):

vim.diagnostic.config { ...some config... }
require('toggle_lsp_diagnostics').init(vim.diagnostic.config())

You can pass an initial configuration for each of the diagnostic settings:

require('toggle_lsp_diagnostics').init { underline = false, virtual_text = { prefix = 'XXX', spacing = 5 } }

The above turns off underlining by default and configures the virtual text with a prefix of 'XXX' and five spaces prior to the virtual text being printed. The complete list of settings may be found in lsp help page.

You can configure diagnostics so that they are off when you first start Neovim:

require'toggle_lsp_diagnostics'.init({ start_on = false })

Simply toggle them back on when you want to see them.

Behavior

The toggling is currently done globally. When you turn off all diagnostics you do so for all buffers / clients both now and in the future. When you turn diagnostics back on the same applies.

You can change the default settings by passing a configuration to the init() method (see the 'Configuration' section above).

Mappings

The following mappings are available.

<Plug>(toggle-lsp-diag-underline) Toggle underlining diagnostic information.

<Plug>(toggle-lsp-diag-signs) Toggle displaying signs in the sign column.

<Plug>(toggle-lsp-diag-vtext) Toggle displaying virtual text in your code.

<Plug>(toggle-lsp-diag-update_in_insert) Toggle updating diagnostic information while in insert mode.

<Plug>(toggle-lsp-diag) Toggle all diagnostics. Turn them all off / or back to what was passed to init().

<Plug>(toggle-lsp-diag-default) Set all diagnostics to their default. The default is everything is on, unless other values were passed to init().

<Plug>(toggle-lsp-diag-on) Turn all diagnostics on.

<Plug>(toggle-lsp-diag-off) Turn all diagnostics off.

An example configuration:

nmap <leader>tlu <Plug>(toggle-lsp-diag-underline)
nmap <leader>tls <Plug>(toggle-lsp-diag-signs)
nmap <leader>tlv <Plug>(toggle-lsp-diag-vtext)
nmap <leader>tlp <Plug>(toggle-lsp-diag-update_in_insert)

nmap <leader>tld  <Plug>(toggle-lsp-diag)
nmap <leader>tldd <Plug>(toggle-lsp-diag-default)
nmap <leader>tldo <Plug>(toggle-lsp-diag-off)
nmap <leader>tldf <Plug>(toggle-lsp-diag-on)

Commands

The following commands are available:

:ToggleDiag Toggle ALL diagnostics on/off

:ToggleDiagDefault Toggle ALL diagnostics to their default

:ToggleDiagOn Turn ALL diagnostics on

:ToggleDiagOff Turn ALL diagnostics off

toggle-lsp-diagnostics.nvim's People

Contributors

naranyala avatar ttytm avatar whoissethdaniel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

toggle-lsp-diagnostics.nvim's Issues

Toggling diagnostics resets my customization

When I <Plug>(toggle-lsp-diag) they turn off fine, but when I do that again the diagnostics lose any of the settings I have assigned. If I do <Plug>(toggle-lsp-diag-default) my customization is back again. This is unexpected behavior. I would like to toggle on/off without it changing any settings. Pressing two keys to turn them back on [properly] is also unacceptable.

Error on :ToggleDiagOff

E5108: Error executing lua ...ggle-lsp-diagnostics.nvim/lua/toggle_lsp_diagnostics.lua:44: attempt to index a nil value
stack traceback:
        ...ggle-lsp-diagnostics.nvim/lua/toggle_lsp_diagnostics.lua:44: in function 'current_settings'
        ...ggle-lsp-diagnostics.nvim/lua/toggle_lsp_diagnostics.lua:133: in function 'configure_diagnostics'
        ...ggle-lsp-diagnostics.nvim/lua/toggle_lsp_diagnostics.lua:57: in function 'turn_off_diagnostics'
        [string ":lua"]:1: in main chunk

nvim --version shows

NVIM v0.9.0-dev-1291+gbad218cd6
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-10 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always -fstack-protector-strong -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/__w/neovim/neovim/.deps/usr/include/luajit-2.1 -I/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/build/src/nvim/auto -I/__w/neovim/neovim/build/include -I/__w/neovim/neovim/build/cmake.config -I/__w/neovim/neovim/src -I/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/__w/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

Error on `<Plug>(toggle-lsp-diag-vtext)`

Default config, LSP attached and operational:

E5108: Error executing lua ...ggle-lsp-diagnostics.nvim/lua/toggle_lsp_diagnostics.lua:90: attempt to index a nil value
stack traceback:
        ...ggle-lsp-diagnostics.nvim/lua/toggle_lsp_diagnostics.lua:90: in function 'toggle_diagnostic'
        ...ggle-lsp-diagnostics.nvim/lua/toggle_lsp_diagnostics.lua:109: in function 'toggle_virtual_text'
        [string ":lua"]:1: in main chunk

Suggested alternative approach

I came across this plugin but it didn't quite solve my desires. However, it was a helpful starting point, and I think the results I got might be useful to share here (either to incorporate or for others to copy).

This will automatically grab a user's existing configuration, and toggle between that config and everything off (in contrast to this plugin currently, which ignores the existing config).

DiagnosticsConfig = vim.diagnostic.config()
DiagnosticsEnabled = true
function ToggleDiagnostics()
   if not DiagnosticsEnabled then
      vim.diagnostic.config(DiagnosticsConfig)
      DiagnosticsEnabled = true
   else
      DiagnosticsConfig = vim.diagnostic.config()
      vim.diagnostic.config({
         virtual_text = false,
         sign = false,
         float = false,
         update_in_insert = false,
         severity_sort = false,
         underline = false,
      })
      DiagnosticsEnabled = false
   end
end
vim.keymap.set("n", "yod", ToggleDiagnostics, { noremap=true, silent=true })

Duplicated status message when toggling on

Hi, thank you for this nice package.

When toggling the diagnostics, there is a final message M.display_status('All diagnostics are', M.settings.all).

M.display_status('All diagnostics are', M.settings.all)

However, in the case of toggling the diagnostics on, there is already a message printed vim.api.nvim_echo({ { 'all diagnostics are at default' } }, false, {}). This causes the output of the toggle call to be a multiline string, which requires to tap enter before being able to continue using nvim.

vim.api.nvim_echo({ { 'all diagnostics are at default' } }, false, {})

Wouldn't it be preferable to delete line 68?

how to disable lsp by default

A simple question, with which option could I disable lsp by default? I want to toggle it on when I need it. Thanks!

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.