Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for simultaneous lean3/lean4 (in separate windows/tabs) #35

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
d7e0685
Implement lean3 vs. lean4 filetype detection; remove lean.vim depende…
rish987 Jun 1, 2021
1de6b3b
Fix infoview.
rish987 Jun 1, 2021
cd18592
Fix 4-second lean4 updatetime.
rish987 Jun 2, 2021
d6ea036
Implement multi-tab infoview.
rish987 Jun 2, 2021
70dca5d
Fix infoview toggle.
rish987 Jun 2, 2021
5976501
Index infoviews by windows rather than buffers.
rish987 Jun 2, 2021
23522d4
Update README and add infoview server startup grace period.
rish987 Jun 2, 2021
f15f610
Merge remote-tracking branch 'upstream/main' into main
rish987 Jun 2, 2021
c2db67d
More README notes and add all remaining lean.vim files.
rish987 Jun 2, 2021
f9ac13a
README formatting.
rish987 Jun 2, 2021
edeaa70
Bring syntax files up-to-date, duplicate plugin files from lean to le…
rish987 Jun 3, 2021
81ab591
Remove some lean3 switch mappings from lean4.
rish987 Jun 3, 2021
e6c4656
Update indent file for lean4.
rish987 Jun 3, 2021
50953f9
Remove lean4 executable path stuff from README.
rish987 Jun 3, 2021
7a90e25
Implement dynamically configurable per-tab/per-window option.
rish987 Jun 3, 2021
b9e0576
Slight refactor of infoview.lua.
rish987 Jun 3, 2021
d3ebca1
Fix default one_per_tab setting.
rish987 Jun 3, 2021
0a9a20f
Merge remote-tracking branch 'upstream/main' into main
rish987 Jun 3, 2021
bcef288
Fix some remaining instances of indexing solely by nvim_get_current_w…
rish987 Jun 3, 2021
126690c
Rename src_winnr -> src_idx (readability).
rish987 Jun 3, 2021
5d45699
Get seemingly working auto-infoview-close functionality, but throws e…
rish987 Jun 4, 2021
adf970d
Fix closing single source with multiple source windows in tab in per-…
rish987 Jun 4, 2021
d039630
Refactor autocmds.
rish987 Jun 4, 2021
333c84a
Remove debug print, minor formatting.
rish987 Jun 4, 2021
12e14bd
Fix E855 (per-tab mode error mentioned above) by making an autocmd di…
rish987 Jun 4, 2021
8ade70b
Put back <afile> expansion on WinClosed to avoid any timing issues.
rish987 Jun 5, 2021
5138c58
Remove more begin/ends from Lean 4.
Julian Jun 5, 2021
ef93fa1
pre-commit
Julian Jun 5, 2021
5d1e7a9
Make robust to manual infoview close by user.
rish987 Jun 5, 2021
27dda16
Relocate some refresh_infos() calls.
rish987 Jun 5, 2021
5e024be
Specify whether the infoview is already closed to close_win_wrapper().
rish987 Jun 5, 2021
ba3b226
Make 'lean' filetype refer to Lean 4 and 'lean3' refer to Lean 3.
rish987 Jun 5, 2021
fec293f
Make suggested keymappings buffer-local; make user commands for setti…
rish987 Jun 6, 2021
8e15a8f
Describe suggested mappings in README.
rish987 Jun 6, 2021
6eecae6
Fix abbreviations for lean3/lean4.
rish987 Jun 6, 2021
04d4f60
Revert snippets setting to previous format (accidentally overrode exi…
rish987 Jun 6, 2021
2836a3e
'Fix' compe abbreviations (not sure how to test this).
rish987 Jun 6, 2021
61ff2b6
Fix a minor typo in the README.
Julian Jun 6, 2021
6fca73c
Document the current mappings.
Julian Jun 6, 2021
ff94cd4
Remove the note on LeanPlainGoal.
Julian Jun 6, 2021
28b62d8
Fix automated tests.
rish987 Jun 6, 2021
3265d1b
Merge remote-tracking branch 'upstream/main' into main
rish987 Jun 6, 2021
0c29f2d
Pre-commit
rish987 Jun 6, 2021
bbf811a
Fix README typos.
rish987 Jun 6, 2021
1250a0a
Fix error message when closing infoview after closing source with CTR…
rish987 Jun 6, 2021
1689187
Fix autocmd use of '<buffer=0>'.
rish987 Jun 6, 2021
9f5b875
Add more details to README about new features.
rish987 Jun 6, 2021
22b873b
pre-commit
rish987 Jun 6, 2021
14fbe51
Fix bug where in per-tab mode, closing the 'original' window would ca…
rish987 Jun 6, 2021
7ec6249
Add source comments.
rish987 Jun 6, 2021
0e5d621
Support buffer-local suggested mapping application.
Julian Jun 7, 2021
37be218
Add back the infoview mode-toggling mappings.
Julian Jun 7, 2021
40666a2
Merge branch 'main' into rish
Julian Jun 7, 2021
8885da7
Merge branch 'main' into rish
Julian Jun 7, 2021
e25e07e
Minor readme revert.
Julian Jun 7, 2021
ae3f0bc
Remove some less-relevant notes with the infoview.
Julian Jun 7, 2021
c0b6c0e
Merge branch 'main' into rish
Julian Jun 7, 2021
01f7e35
Merge branch 'main' into rish
Julian Jun 8, 2021
7540117
Minor ternary style, which Lua people seem to like.
Julian Jun 8, 2021
beef5e4
Merge remote-tracking branch 'upstream/main' into main
rish987 Jun 10, 2021
24a4137
Revert a couple ternary refactors and minor close_win_wrapper() fix.
rish987 Jun 10, 2021
d48c9f8
For now, always erase infoviews.
Julian Jun 10, 2021
e73cc6d
Pull in some upstream changes.
Julian Jun 10, 2021
c63b1eb
Remove dead code.
Julian Jun 11, 2021
f97b0a0
Remove some sections from the README.
Julian Jun 11, 2021
1033ed2
Pull in the max_width change.
Julian Jun 11, 2021
0e3e2f6
Pull in the augroup helper
Julian Jun 11, 2021
01d6f99
Use is_lean3_project in _update to detect lean3 projects.
Julian Jun 11, 2021
e3b1063
Guard against lean3ls not existing yet until the PR is merged.
Julian Jun 11, 2021
8604975
Partially pull in teardown.
Julian Jun 11, 2021
ac92804
Remove the note about Lean3 being removed in the future.
Julian Jun 11, 2021
6cb1154
Use lspconfig.util to find leanpkg.toml
Julian Jun 11, 2021
58da940
Get rid of lean3.detect if we already have ft.detect.
Julian Jun 11, 2021
3cdad44
Properly detect leanpkg.toml relative to the lean file, not cwd.
Julian Jun 11, 2021
eb4cd45
Fix infoview closing.
rish987 Jun 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 58 additions & 24 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ Prerequisites
``lean.nvim`` currently requires `neovim 0.5 HEAD / nightly
<https://github.com/neovim/neovim/releases/tag/nightly>`_.

For syntax highlighting and basic language support, you should either:
NOTE: ``lean.nvim`` is incompatible with `lean.vim <https://github.com/leanprover/lean.vim>`_,
as it implements its own kind of filetype detection.
You should NOT have ``lean.vim`` installed if using ``lean.nvim``.

* Install the normal `lean.vim <https://github.com/leanprover/lean.vim>`_.
Syntax highlighting and basic language support is included, for Lean 4 you can also
try the experimental support present via `tree-sitter-lean
<https://github.com/Julian/tree-sitter-lean>`_ by installing
`nvim-treesitter <https://github.com/nvim-treesitter/nvim-treesitter>`_

* or try the experimental support present via `tree-sitter-lean
<https://github.com/Julian/tree-sitter-lean>`_ by installing
`nvim-treesitter <https://github.com/nvim-treesitter/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.

Note that many simple syntactical things are not yet implemented
(help is of course welcome), and that ``tree-sitter-lean`` is lean
4-only.
``lean.nvim`` currently supports both Lean 3 and Lean 4,
which can be used simultaneously in a single session.
However, support for Lean 3 may be removed in the future.

Installation
------------
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should remove line 37 here suggesting installing lean.vim I suppose

Expand Down Expand Up @@ -64,9 +69,11 @@ Features

* ``<LocalLeader>i``: toggle infoview

* ``<LocalLeader>s``: ``sorry`` insertion corresponding to the number of open goals
* ``<LocalLeader>pt``: set infoview per-tab mode

* ``<LocalLeader>pw``: set infoview per-window mode

* ``<LocalLeader>3``: force a buffer into Lean 3 mode
* ``<LocalLeader>s``: ``sorry`` insertion corresponding to the number of open goals

* A basic infoview which can show persistent goal, term & tactic state

Expand All @@ -88,12 +95,34 @@ You may find browsing `my own dotfiles
<https://github.com/Julian/dotfiles/tree/main/.config/nvim>`_ useful for
seeing how I use this plugin myself.

Infoview
---------------------

Infoviews can be used on a per-tab or per-window basis.
You can use the commands ``LeanInfoPerTab`` and ``LeanInfoPerWin`` to choose between them.

The "correct" way to exit a Lean source window is to use ``:q`` with your cursor in that window.
This will automatically close its corresponding infoview. Closing the source window directly
using, for example, ``CTRL-W + c``, will close the source window and leave the infoview in a "detached"
state - this is a feature, not a bug!

Configuration & Usage
---------------------

In e.g. your ``init.lua``:

.. code-block:: lua
-- If you don't already have an existing LSP setup, you may want
-- to reference the keybindings section of the nvim-lspconfig
-- documentation, which can be found at:
-- https://github.com/neovim/nvim-lspconfig#keybindings-and-completion
on_attach = function(client, bufnr)
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

require('lean').setup{
-- Abbreviation support
Expand Down Expand Up @@ -124,26 +153,20 @@ In e.g. your ``init.lua``:
-- Clip the infoview to a maximum width
max_width = 79,
},
-- Enable the Lean language server?
-- Enable the Lean3(lsp3)/Lean4(lsp) language servers?
--
-- 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)
-- If you don't already have an existing LSP setup, you
-- may want to reference the keybindings section of the
-- aforementioned nvim-lspconfig documentation, which
-- can be found at:
-- https://github.com/neovim/nvim-lspconfig#keybindings-and-completion
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,
lsp3 = {
on_attach = on_attach,
cmd = {"lean-language-server", "--stdio", '--', "-M", "4096"},
},

lsp = {
on_attach = on_attach,
cmd = {"lean", "--server"},
}
}

Expand Down Expand Up @@ -179,6 +202,17 @@ you're interested in. Below is a (hopelessly incomplete) list of a few:
* `lsp-trouble <https://github.com/folke/lsp-trouble.nvim>`_ for
showing a grouped view of diagnostics to pair with the "infauxview"

Roadmap
-------------

Some features we plan to implement in the near future:

* Pinnable and pausable infoview messages (à la VSCode)

* Connection to true HTML infoviews (in a separate browser window)

* ... suggestions welcome!

Contributing
------------

Expand Down
2 changes: 1 addition & 1 deletion ftdetect/lean.vim
Original file line number Diff line number Diff line change
@@ -1 +1 @@
autocmd BufRead,BufNewFile *.lean lua require'lean.lean3'.detect()
autocmd BufRead,BufNewFile *.lean lua require'lean.ft'.detect(); require'lean.lean3'.detect()
30 changes: 30 additions & 0 deletions ftplugin/lean/lean.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if exists('b:did_ftplugin')
finish
endif
let b:did_ftplugin = 1

set wildignore+=*.olean

setlocal iskeyword=@,48-57,_,-,!,#,$,%

setlocal comments=s0:/-,mb:\ ,ex:-/,:--
setlocal commentstring=/-\ %s\ -/

setlocal expandtab
setlocal shiftwidth=2
setlocal softtabstop=2

function! lean#dotted2path(fname)
return substitute(a:fname, '\.', '/', 'g') . '.lean'
endfunction
setlocal includeexpr=lean#dotted2path(v:fname)

setlocal matchpairs+=⟨:⟩

" Matchit support
if exists('loaded_matchit') && !exists('b:match_words')
let b:match_ignorecase = 0

let b:match_words =
\ ',\<\%(namespace\|section\)\s\+\(.\{-}\)\>:\<end\s\+\1\>'
endif
5 changes: 0 additions & 5 deletions ftplugin/lean/switch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ endif
let b:switch_definitions = [
\ g:switch_builtins.true_false,
\ ["#check", "#eval", "#reduce"],
\ ['\(begin\n\s*\)\@<!sorry', 'begin\r sorry\rend'],
\ ["tidy", "suggest", "hint", "linarith", "library_search"],
\ ["rw", "simp", "simp?"],
\ ["cases", "rcases", "obtain"],
\ ["norm_cast", "push_cast"],
\ ["inl", "inr"],
\ ["tt", "ff"],
\ ["=", "≠"],
Expand Down
2 changes: 2 additions & 0 deletions ftplugin/lean3/infoview.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
" required for infoview
setlocal updatetime=100
31 changes: 31 additions & 0 deletions ftplugin/lean3/lean.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if exists('b:did_ftplugin')
finish
endif
let b:did_ftplugin = 1

set wildignore+=*.olean

setlocal iskeyword=@,48-57,_,-,!,#,$,%

setlocal comments=s0:/-,mb:\ ,ex:-/,:--
setlocal commentstring=/-\ %s\ -/

setlocal expandtab
setlocal shiftwidth=2
setlocal softtabstop=2

function! lean#dotted2path(fname)
return substitute(a:fname, '\.', '/', 'g') . '.lean'
endfunction
setlocal includeexpr=lean#dotted2path(v:fname)

setlocal matchpairs+=⟨:⟩

" Matchit support
if exists('loaded_matchit') && !exists('b:match_words')
let b:match_ignorecase = 0

let b:match_words =
\ '\<begin\>:\<end$' .
\ ',\<\%(namespace\|section\)\s\+\(.\{-}\)\>:\<end\s\+\1\>'
endif
40 changes: 40 additions & 0 deletions ftplugin/lean3/switch.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
" This possibly belongs in lean.vim or switch.vim itself but putting it here
" for now.

if !exists("g:loaded_switch")
finish
endif

let b:switch_definitions = [
\ g:switch_builtins.true_false,
\ ["#check", "#eval", "#reduce"],
\ ['\(begin\n\s*\)\@<!sorry', 'begin\r sorry\rend'],
\ ["tidy", "suggest", "hint", "linarith", "library_search"],
\ ["rw", "simp", "simp?"],
\ ["cases", "rcases", "obtain"],
\ ["norm_cast", "push_cast"],
\ ["inl", "inr"],
\ ["tt", "ff"],
\ ["=", "≠"],
\ ["∈", "∉"],
\ ["∪", "∩"],
\ ["⋃", "⋂"],
\ ["⊆", "⊂", "⊃", "⊇"],
\ ["Σ", "∑"],
\ ["∀", "∃"],
\ ["∧", "∨"],
\ ["⊔", "⊓"],
\ ["⊥", "⊤"],
\ ["⋀", "⋁"],
\ ["×", "→"],
\ ["0", "₀", "⁰"],
\ ["1", "₁", "¹"],
\ ["2", "₂", "²"],
\ ["3", "₃", "³"],
\ ["4", "₄", "⁴"],
\ ["5", "₅", "⁵"],
\ ["6", "₆", "⁶"],
\ ["7", "₇", "⁷"],
\ ["8", "₈", "⁸"],
\ ["9", "₉", "⁹"],
\ ]
4 changes: 4 additions & 0 deletions indent/lean.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
6 changes: 6 additions & 0 deletions indent/lean3.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if exists("b:did_indent")
finish
endif
let b:did_indent = 1

setlocal indentkeys+==end,==begin
2 changes: 1 addition & 1 deletion lua/lean/_compe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
Source.get_metadata = function(_)
return {
priority = 100;
filetypes = {'lean'};
filetypes = {'lean3', 'lean'};
dup = true;
sort = true;
menu = '[LA]';
Expand Down
1 change: 1 addition & 0 deletions lua/lean/abbreviations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local function snippets_nvim_enable(snippets, lean_abbreviations)
end

local all_snippets = snippets.snippets or {}
all_snippets.lean3 = lean_abbreviations
all_snippets.lean = lean_abbreviations
snippets.snippets = all_snippets
end
Expand Down
22 changes: 22 additions & 0 deletions lua/lean/ft.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local util = require'lean.util'

-- Ideally this obviously would use a TOML parser but yeah choosing to
-- do nasty things and not add the dependency for now.
local _MARKER = '.*lean_version.*\".*:3.*'


local M = {}

-- If a TOML file with a lean3 version string is found, use filetype "lean3".
-- Otherwise use "lean" (lean4).
function M.detect()
local toml_file = util.find_toml(vim.api.nvim_buf_get_name(0))
if not toml_file then vim.bo.ft = "lean" return end
local _, result = pcall(vim.fn.readfile, toml_file)
for _, line in ipairs(result) do
if line:match(_MARKER) then vim.bo.ft = "lean3" return end
end
vim.bo.ft = "lean"
end

return M
Loading