Skip to content

Commit

Permalink
docs: add in a minimal minimal example in the README
Browse files Browse the repository at this point in the history
closes #651
  • Loading branch information
ckipp01 committed Feb 22, 2024
1 parent 94c8d4d commit e118ca5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,41 @@ _NOTE_: This plugin works without needing to install
it installed for other languages, that's not a problem, but make sure you do not
have Metals configured through `nvim-lspconfig` while using this plugin.[^no-lspconfig]

## Absolute minimal example using [Lazy.nvim](https://github.com/folke/lazy.nvim)

```lua
{
"scalameta/nvim-metals",
dependencies = {
"nvim-lua/plenary.nvim",
},
ft = { "scala", "sbt", "java" },
opts = function()
local metals_config = require("metals").bare_config()
metals_config.on_attach = function(client, bufnr)
-- your on_attach function
end

return metals_config
end,
config = function(self, metals_config)
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
pattern = self.ft,
callback = function()
require("metals").initialize_or_attach(metals_config)
end,
group = nvim_metals_group,
})
end
}
```

**NOTE**: The above assumes you have your own attach function that sets up all
your LSP mappings. It also doesn't make use of _any_ configuration. You'll
likely want a more involved setup than this, so check out the full minimal
example configuration link below.

- You can find a full [minimal example configuration
here](https://github.com/scalameta/nvim-metals/discussions/39).
- You can find the full documentation with [`:help
Expand Down

0 comments on commit e118ca5

Please sign in to comment.