Skip to content

Commit

Permalink
Also prevent accidental modification of project dependencies.
Browse files Browse the repository at this point in the history
Matches the current Mathlib setting (which is done via
`vscode/settings.json` -- maybe at some point we'll attempt to parse
this).

See e.g. https://leanprover.zulipchat.com/#narrow/channel/412902-Polynomial-Freiman-Ruzsa-conjecture/topic/.E2.9C.94.20Local.20build.20issue/near/481118068
  • Loading branch information
Julian committed Nov 7, 2024
1 parent e32e351 commit 07c9dc1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ globals = {
fields = {
"contents",
"message",
"is_falsy",
"is_truthy",
}
},
}
2 changes: 2 additions & 0 deletions lua/lean/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ local DEFAULTS = {
ft = {
nomodifiable = {
'.*/src/lean/.*', -- Lean core library
'.*/.elan/.*', -- elan toolchains
'.*/.lake/.*', -- project dependencies
},

---Check whether a given path should be modifiable.
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ local fixtures = {
some_nonexisting_file = child 'DoesNotExist.lean',
some_nested_existing_file = child 'Test/Squares.lean',
some_nested_nonexisting_file = child 'Test/DoesNotExist.lean',

some_dependency_file = child '.lake/packages/importGraph/ImportGraph/Imports.lean',
},
}

assert.is_truthy(vim.uv.fs_stat(fixtures.project.some_existing_file))
assert.is_falsy(vim.uv.fs_stat(fixtures.project.some_nonexisting_file))
assert.is_truthy(vim.uv.fs_stat(fixtures.project.some_nested_existing_file))
assert.is_falsy(vim.uv.fs_stat(fixtures.project.some_nested_nonexisting_file))
assert.is_truthy(vim.uv.fs_stat(fixtures.project.some_dependency_file))

function fixtures.project:files()
return vim.iter {
['existing'] = self.some_existing_file,
Expand Down
7 changes: 6 additions & 1 deletion spec/ft_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ describe('ft.detect', function()
assert.is_falsy(vim.bo.modifiable)
end)

it('marks dependency files nomodifable by default', function()
vim.cmd.edit { project.some_dependency_file, bang = true }
assert.is_falsy(vim.bo.modifiable)
end)

it('does not mark other lean files nomodifiable', function()
vim.cmd('edit! ' .. project.some_existing_file)
vim.cmd.edit { project.some_existing_file, bang = true }
assert.is_truthy(vim.bo.modifiable)
end)
end)

0 comments on commit 07c9dc1

Please sign in to comment.