Created
January 16, 2023 06:13
-
-
Save majamin/71c19bc463fdbdd55388a1c0e3398c73 to your computer and use it in GitHub Desktop.
MRE of a Neovim config using Mason and Null-ls to format files using prettierd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim' | |
local is_bootstrap = false | |
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then | |
is_bootstrap = true | |
vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path } | |
vim.cmd [[packadd packer.nvim]] | |
end | |
require('packer').startup(function(use) | |
use 'wbthomason/packer.nvim' | |
use { | |
'neovim/nvim-lspconfig', | |
requires = { | |
'williamboman/mason.nvim', | |
'williamboman/mason-lspconfig.nvim', | |
}, | |
} | |
use { | |
'jose-elias-alvarez/null-ls.nvim', | |
requires = 'nvim-lua/plenary.nvim' | |
} | |
if is_bootstrap then | |
require('packer').sync() | |
end | |
end) | |
if is_bootstrap then | |
return | |
end | |
local on_attach = function(_, bufnr) | |
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) | |
vim.lsp.buf.format({ | |
bufnr = bufnr, | |
filter = function(client) | |
return client.name == "null-ls" | |
end | |
}) | |
print("File formatted") | |
end, { desc = 'Format current buffer with LSP' }) | |
end | |
local servers = { | |
tsserver = {}, | |
} | |
require('mason').setup() | |
local mason_lspconfig = require 'mason-lspconfig' | |
mason_lspconfig.setup { | |
ensure_installed = vim.tbl_keys(servers), | |
} | |
mason_lspconfig.setup_handlers { | |
function(server_name) | |
require('lspconfig')[server_name].setup { | |
capabilities = capabilities, | |
on_attach = on_attach, | |
settings = servers[server_name], | |
} | |
end, | |
} | |
local null_ls = require("null-ls") | |
null_ls.setup({ | |
sources = { | |
null_ls.builtins.formatting.prettierd, | |
}, | |
}) | |
vim.cmd([[colo slate]]) |
Is there a way to undo what this script has done ?
Now I have this message everytime I open nvim
[lspconfig] requires neovim 0.8 or later. Detected neovim version: 0.7.2
update your neovim
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to undo what this script has done ?
Now I have this message everytime I open nvim