ashinkarov / nvim-agda

Agda interaction pluging for neovim
34 stars 5 forks source link

Agda for neovim

asciicast

Installation

This plugin requires Neovim (0.5) to work. One could probably force earlier versions to work as well, but this is non-trivial.

  1. Install lua-utf8 library on your system.

  2. Use a plugin manager such as paq and pass the name of this repository:

    paq 'ashinkarov/nvim-agda'

    Alternatively, you can install the plugin manually as follows:

    $ mkdir -p ~/.local/share/nvim/site/pack/git-plugins/start
    $ git clone https://github.com/ashinkarov/nvim-agda.git --depth=1 ~/.local/share/nvim/site/pack/git-plugins/start/nvim-agda

Configuration

The plugin can be configured by defining a global variable named g:nvim_agda_settings of type dictionary. So far the following options are supported (I use lua syntax, but you can define this in vimscript too).

{
  agda : "/usr/local/bin/agda",            -- Location of Agda binary
  agda_args : { "--arg1", "--arg2"  },     -- Default arguments to Agda binary
  debug_p : true                           -- Turn debug prints on or off
}

All the fields of the dictionary may be omitted, as well as the definition of g:nvim_agda_settings. In this case hard-coded defaults would be used.

Details

NeoVim comes with built-in Lua support which dramatically simplifies development of complex plugins. This plugin is written almost entirely in Lua, which handles asynchronous interaction and editor state manipulation.

Design principles

Status

Minimal functionality including communication with Agda process, basic utf8 input, and basic commands are implemented. Goal specific information such as context, goal type, etc. is shown in a popup window appearing at the goal location. The goal content is edited in a separate window, so that it does not alter the state of the file. Goal actions on a modified file reload the file and synchronise the goal list. Both ? and {! !} goals are supported, however the latter is discouraged, as every edit would modify the file and trigger file reload.

Implemented commands and shortcuts.

Mostly we implement the same commands as agda-mode in emacs. Several new commands have to do with management of the popups and goal editing.

<LocalLeader> Key Agda mode Command
l Load file
, Show type and context
d Infer type
r Refine the goal
c Case split on a variable(s)
n Compute the goal content or toplevel expression
a Automatically solve a goal (or all goals in the file)
s Automatically solve constraints in a goal (or in all goals in the file)
h Helper function for the goal
o Show the content of the module
w Explain why the name (under cursor) is in scope
? Show Goals
f Go to the next goal
b Go to the previous goal
<LocalLeader> Key Agda mode Command
q Close the message box
e Edit the goal content

Within the goal-edit window, q is mapped to close the window. The regular :q command would work as well.

Todo

Done

Credit