Thanks to visit codestin.com
Credit goes to github.com

Skip to content

aodecipher/lean.nvim

 
 

Repository files navigation

lean.nvim

neovim support for the Lean Theorem Prover.

Prerequisites

lean.nvim currently requires neovim 0.5 HEAD / nightly.

For syntax highlighting and basic language support, you should either:

  • Install the normal lean.vim.

  • or try the experimental support present via tree-sitter-lean by installing nvim-treesitter

    Note that many simple syntactical things are not yet implemented (help is of course welcome), and that tree-sitter-lean is lean 4-only.

Installation

Install via your favorite plugin manager. E.g., with vim-plug via:

Plug 'Julian/lean.nvim'

Plug 'hrsh7th/nvim-compe'
Plug 'leanprover/lean.vim'
Plug 'neovim/nvim-lspconfig'

For LSP support in Lean 3, you also first need to install lean-language-server, which can be done via e.g.:

$ npm install -g lean-language-server

In the future, support may be added for automatically installing it as part of this plugin.

Features

  • abbreviation (unicode character) insertion using either nvim-compe or snippets.nvim

  • Initial implementations of some editing helpers (note: no mappings are associated with these by default unless you call lean.use_suggested_mappings() or set mappings = true in the configuration)

    • "try this:" suggestion replacement
    • sorry insertion corresponding to the number of open goals
  • LSP Commands

    • :LeanPlainGoal for showing the tactic state (good for binding to CursorHold, and can be customized via vim.lsp.handlers["$/lean/plainGoal"])
  • An infauxview which can show persistent goal & tactic state

  • switch.vim base definitions for Lean

  • Simple snippets (in VSCode-compatible format, so usable with e.g. vim-vsnip)

You may find browsing my own dotfiles useful for seeing how I use this plugin myself.

Configuration & Usage

In e.g. your init.lua:

require('lean').setup{
    -- Enable abbreviation support?
    --
    -- false to disable, otherwise a table of options described below
    abbreviations = {,
        extra = {
            -- Add a \wknight abbreviation to insert ♘
            --
            -- Note that the backslash is implied, and that you of
            -- course may also use a snippet engine directly to do
            -- this if so desired.
            wknight = '',
        },
    }
    -- Enable suggested mappings?
    --
    -- false by default, true to enable
    mappings = false,
    -- Enable the Lean language server?
    --
    -- false to disable, otherwise should be a table of options to pass to
    --  `leanls`. See https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#leanls
    -- for details though lean-language-server actually doesn't support all
    -- the options mentioned there yet.
    lsp = {
        on_attach = function(client, bufnr)
            -- See https://github.com/neovim/nvim-lspconfig#keybindings-and-completion
            -- for detailed examples of what you may want to do here.
            --
            -- Mapping a key (typically K) to `vim.lsp.buf.hover()`
            -- is highly recommended for Lean, since the hover LSP command
            -- is where you'll see the current goal state.
            --
            -- You may furthermore want to add an `autocmd` to run it on
            -- `CursorHoldI`, which will show the goal state any time the
            -- cursor is unmoved in insert mode.
            --
            -- In the future, this plugin may offer a recommended "complete
            -- setup" for easy enabling of the above.
            local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
            local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
            buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', {noremap = true})
            buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', {noremap = true})
            buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
        end,
        cmd = {"lean-language-server", "--stdio", '--', "-M", "4096"},
    }
}

If you're using an init.vim-only configuration setup, simply surround the above with:

lua <<EOF
    require('lean').setup{
        ...
    }
EOF

You may find some small additional inspiration in my own (Julian's) configuration here.

Other Plugins

Particularly if you're also a VSCode user, there may be other plugins you're interested in. Below is a (hopelessly incomplete) list of a few:

  • nvim-lightbulb for signalling when code actions are available
  • lspsaga.nvim for an extended LSP experience on top of the builtin one
  • lsp-status.nvim for showing LSP information in your status bar
  • lsp-trouble for showing a grouped view of diagnostics to pair with the "infauxview"

Contributing

Contributions are most welcome, as is just letting me know you use this at this point :)

Running the tests can be done via the Makefile:

$ make test

which will execute against a minimal vimrc isolated from your own setup.

Some linting and style checking is done via pre-commit, which once installed (via the linked instructions) can be run via:

$ make lint

or on each commit automatically by running pre-commit install in your repository checkout.

About

neovim support for the Lean theorem prover

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Lua 81.8%
  • Scheme 12.0%
  • Vim Script 5.1%
  • Makefile 1.1%