From e118ca5bdf4fb3ef99e23a7518d61b5aab22d89e Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Thu, 22 Feb 2024 10:33:20 +0100 Subject: [PATCH] docs: add in a minimal minimal example in the README closes #651 --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 13c2f14..efca98f 100644 --- a/README.md +++ b/README.md @@ -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