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

feat!: utilize new autocmd api #369

Merged
merged 1 commit into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ integrations with other projects such as

## Prerequisites

- Before you get started you need to ensure that you are using nvim v.0.6.0 or
- Before you get started you need to ensure that you are using nvim v.0.7.0 or
newer.
- Ensure [Coursier](https://get-coursier.io/docs/cli-installation) is installed
on your machine. `nvim-metals` uses Coursier to download and update Metals.
Expand Down
26 changes: 13 additions & 13 deletions doc/metals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ the correct `init_options`.
================================================================================
PREREQUISITES *metals-prerequisites*

- Ensure you're using at least Neovim v0.6.0. While `nvim-metals` will aim to
- Ensure you're using at least Neovim v0.7.0. While `nvim-metals` will aim to
always work with the latest stable version of Neovim, there is no guarantee
of compatibility with older versions.
- WARNING: use this plugin for Metals and also `neovim/nvim-lspconfig` for
Expand Down Expand Up @@ -59,24 +59,24 @@ PREREQUISITES *metals-prerequisites*
- Check out the features list in
https://github.com/scalameta/nvim-metals/discussions/279. New features will
always be added there.
- If you're unfamiliar with configuring Neovim with Lua or not sure how to
call Lua from Vimscript, check out the awesome guide at
https://github.com/nanotee/nvim-lua-guide. The help docs here always assume
Lua.

================================================================================
GETTING STARTED *metals-getting-started*

Once installed, the most basic setup is to have the following: >

augroup lsp
au!
au FileType java,scala,sbt lua require("metals").initialize_or_attach({})
augroup end
<

Or as a |vim.cmd| if using a pure Lua setup. >

cmd [[augroup lsp]]
cmd [[au!]]
cmd [[au FileType java,scala,sbt lua require("metals").initialize_or_attach({})]]
cmd [[augroup end]]
local nvim_metals_group = api.nvim_create_augroup("nvim-metals", { clear = true })
api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt", "java" },
callback = function()
require("metals").initialize_or_attach({})
end,
group = nvim_metals_group,
})
<

This will give you the defaults that Metals provides. The empty `{}` that
Expand Down
12 changes: 8 additions & 4 deletions lua/metals/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ local valid_nvim_metals_settings = {
--- auto commands necessary for `metals/didFocusTextDocument`.
--- https://scalameta.org/metals/docs/integrations/new-editor.html#metalsdidfocustextdocument
local function auto_commands()
api.nvim_command([[augroup NvimMetals]])
api.nvim_command([[autocmd!]])
api.nvim_command([[autocmd BufEnter * lua require("metals").did_focus()]])
api.nvim_command([[augroup end]])
local nvim_metals_group = api.nvim_create_augroup("nvim-metals", { clear = true })
api.nvim_create_autocmd("BufEnter", {
pattern = { "*" },
callback = function()
require("metals").did_focus()
end,
group = nvim_metals_group,
})
end

local commands = {}
Expand Down
12 changes: 9 additions & 3 deletions lua/metals/doctor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ Doctor.create = function(args)
api.nvim_buf_set_option(float.bufnr, "filetype", "markdown")
api.nvim_buf_set_lines(float.bufnr, 0, -1, false, output)

vim.cmd("autocmd WinLeave <buffer> lua require('metals.doctor').visibility_did_change(false)")
local nvim_metals_group = api.nvim_create_augroup("nvim-metals", { clear = true })

api.nvim_create_autocmd("WinLeave", {
buffer = float.bufnr,
callback = function()
require("metals.doctor").visibility_did_change(false)
end,
group = nvim_metals_group,
})

-- we have the win_id and then with that win_id we could set an autocmd that
-- on close it calls some function
doctor_win_id = float.win_id
end

Expand Down