Giter Club home page Giter Club logo

lsp_lines.nvim's Introduction

lsp_lines.nvim

lsp_lines is a simple neovim plugin that renders diagnostics using virtual lines on top of the real line of code.

A screenshot of the plugin in action

Font is Fira Code, a classic. Theme is tokyonight.nvim.

Background

LSPs provide lots of useful diagnostics for code (typically: errors, warnings, linting). By default they're displayed using virtual text at the end of the line which is in many cases good enough, but often there's more than one diagnostic per line. It's also quite common to have more than one diagnostic per line, but again, there's no handy way to read the whole thing.

lsp_lines solves this issue.

Installation

With Lazy.nvim

Using lazy.nvim

{
    "steven-liou/lsp_lines.nvim",
    event = "LspAttach",
    config = function()
        require("lsp_lines").setup({
        severity = vim.diagnostic.severity.WARN, -- only severity at or above this level will show
        current_line_only = true, -- only show virtual lines on cursor line only
        show_virt_line_events = { "CursorHold" }, -- events to show virtual lines
        hide_virt_line_events = {"CursorMoved", "InsertEnter"}, -- events to hide virtual lines. CursorMoved is recommended only if current_line_only is true
        diagnostics_filter = require("lsp_lines").most_severe_level_of_buffer, -- pick available diagnostic filters or write your own for this key, or omit this key to not use any filter
        })
    end,
}
  • Below examples are based on:
    • Minimum severity level of INFO
    • Given a buffer with:
      • One ERROR and one WARN on line 2
      • One WARN and one HINT on line 3
  • diagnostics_filter function can be:
    • minimum_severity_level show diagnostics at or above the specified minimum severity level. Both ERROR and WARN will show on line 2, and only WARN will show on line 3, since HINT doesn't meet minimum severity criteria. Recommended if current_line_only is true
    • most_severe_level_per_line only shows the most severe diagnostics in a given line at or above the specified minimum severity level. Only ERROR will show on line 2, and WARN on line 3. Recommended if current_line_only is false
    • most_severe_level_of_buffer only shows the most severe diagnostics in a buffer at or above the specified minimum severity level. Only ERROR will show on line 2, since the most severe error in the whole buffer is ERROR
    • Any custom function that you write, with first parameter a table of LSP diagnostics, and second parameter any table of options

With git

You can algo just clone the repo into neovim's plug-in directory:

mkdir -p $HOME/.local/share/nvim/site/pack/plugins/start/
cd $HOME/.local/share/nvim/site/pack/plugins/start/
git clone [email protected]:~whynothugo/lsp_lines.nvim

And then in init.lua:

require("lsp_lines").setup()

Setup

It's recommended to also remove the regular virtual text diagnostics to avoid pointless duplication:

-- Disable virtual_text since it's redundant due to lsp_lines.
vim.diagnostic.config({
  virtual_text = false,
})

Usage

This plugin's functionality can be disabled with:

vim.diagnostic.config({ virtual_lines = false })

And it can be re-enabled via:

vim.diagnostic.config({ virtual_lines = true })

A helper is also provided to toggle, which is convenient for mappings:

vim.keymap.set(
  "",
  "<Leader>l",
  require("lsp_lines").toggle,
  { desc = "Toggle lsp_lines" }
)

Contributing

Development

It would be nice to show connecting lines when there's relationship between diagnostics (as is the case with rust_analyzer). Oh perhaps surface them via hover().

Licence

This project is licensed under the ISC licence. See LICENCE for more details.

lsp_lines.nvim's People

Contributors

steven-liou avatar whynothugo avatar maan2003 avatar mhanberg avatar

Stargazers

Bruno Krugel 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.