nvim
This commit is contained in:
		
							parent
							
								
									474f3b1657
								
							
						
					
					
						commit
						94b8437962
					
				
					 3 changed files with 47 additions and 59 deletions
				
			
		|  | @ -32,29 +32,9 @@ if has_lsp_status then | ||||||
|     capabilities = vim.tbl_extend("keep", capabilities, lsp_status.capabilities) |     capabilities = vim.tbl_extend("keep", capabilities, lsp_status.capabilities) | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| local format_augroup = setmetatable({}, { | local has_lsp_format, lsp_format = pcall(require, "lsp-format") | ||||||
|     __index = function(self, id) | if has_lsp_format then | ||||||
|         local group = vim.api.nvim_create_augroup(string.format("lsp-format-%s", id), { clear = true }) |     lsp_format.setup() | ||||||
|         rawset(self, id, group) |  | ||||||
|         return group |  | ||||||
|     end, |  | ||||||
| }) |  | ||||||
| 
 |  | ||||||
| local format_saving = {} |  | ||||||
| 
 |  | ||||||
| local format_handler = function(err, result, ctx) |  | ||||||
|     if not result then |  | ||||||
|         return |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     local client = vim.lsp.get_client_by_id(ctx.client_id) |  | ||||||
|     vim.lsp.util.apply_text_edits(result, ctx.bufnr, client.offset_encoding) |  | ||||||
| 
 |  | ||||||
|     if ctx.bufnr == vim.api.nvim_get_current_buf() then |  | ||||||
|         format_saving[ctx.bufnr] = true |  | ||||||
|         vim.cmd [[update]] |  | ||||||
|         format_saving[ctx.bufnr] = false |  | ||||||
|     end |  | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| local on_attach = function(client, bufnr) | local on_attach = function(client, bufnr) | ||||||
|  | @ -84,32 +64,43 @@ local on_attach = function(client, bufnr) | ||||||
|         }) |         }) | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     -- Format on save |  | ||||||
|     if client.server_capabilities.documentFormattingProvider then |  | ||||||
|         vim.lsp.handlers["textDocument/formatting"] = vim.lsp.with(format_handler, {}) |  | ||||||
|         vim.api.nvim_clear_autocmds { |  | ||||||
|             buffer = bufnr, |  | ||||||
|             group = format_augroup[client.id], |  | ||||||
|         } |  | ||||||
|         vim.api.nvim_create_autocmd({ "BufWritePost" }, { |  | ||||||
|             group = format_augroup[client.id], |  | ||||||
|             desc = "format on save", |  | ||||||
|             pattern = "<buffer>", |  | ||||||
|             callback = function() |  | ||||||
|                 if format_saving[bufnr] == true then |  | ||||||
|                     return |  | ||||||
|                 end |  | ||||||
|                 vim.lsp.buf.format({ async = true }) |  | ||||||
|             end, |  | ||||||
|         }) |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     if has_lsp_status then |     if has_lsp_status then | ||||||
|         lsp_status.on_attach(client) |         lsp_status.on_attach(client) | ||||||
|     end |     end | ||||||
|  | 
 | ||||||
|  |     if has_lsp_format then | ||||||
|  |         lsp_format.on_attach(client) | ||||||
|  |     end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
|  | local prettier = { | ||||||
|  |     formatCommand = [[prettier --stdin-filepath ${INPUT} ${--tab-width:tab_width}]], | ||||||
|  |     formatStdin = true, | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | local eslint = { | ||||||
|  |     lintCommand = [[eslint_d -f visualstudio --stdin --stdin-filename ${INPUT}]], | ||||||
|  |     lintIgnoreExitCode = true, | ||||||
|  |     lintStdin = true, | ||||||
|  |     lintFormats = { | ||||||
|  |         "%f(%l,%c): %tarning %m", | ||||||
|  |         "%f(%l,%c): %rror %m", | ||||||
|  |     }, | ||||||
|  |     lintSource = "eslint", | ||||||
|  | } | ||||||
|  | 
 | ||||||
| local servers = { | local servers = { | ||||||
|  |     efm = { | ||||||
|  |         filetypes = { "typescript", "typescriptreact" }, | ||||||
|  |         init_options = { documentFormatting = true }, | ||||||
|  |         settings = { | ||||||
|  |             rootMarkers = { ".git/" }, | ||||||
|  |             languages = { | ||||||
|  |                 typescript = { prettier, eslint }, | ||||||
|  |                 typescriptreact = { prettier, eslint }, | ||||||
|  |             }, | ||||||
|  |         }, | ||||||
|  |     }, | ||||||
|     gopls = {}, |     gopls = {}, | ||||||
|     pylsp = {}, |     pylsp = {}, | ||||||
|     rust_analyzer = { |     rust_analyzer = { | ||||||
|  | @ -145,9 +136,18 @@ local servers = { | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
|     elixirls = { |     elixirls = { | ||||||
|         cmd = { "elixir-ls" } |         cmd = { "/home/nikos/Projects/elixir-ls/release/language_server.sh" }, | ||||||
|  |         settings = { | ||||||
|  |             elixirLS = { | ||||||
|  |                 dialyzerEnabled = true, | ||||||
|  |             }, | ||||||
|  |         }, | ||||||
|  |     }, | ||||||
|  |     tsserver = { | ||||||
|  |         settings = { | ||||||
|  |             documentFormatting = false, | ||||||
|  |         }, | ||||||
|     }, |     }, | ||||||
|     tsserver = {}, |  | ||||||
|     psalm = { |     psalm = { | ||||||
|         cmd = { "vendor/bin/psalm-language-server" }, |         cmd = { "vendor/bin/psalm-language-server" }, | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|  | @ -1,12 +0,0 @@ | ||||||
| local ok, null = pcall(require, "null-ls") |  | ||||||
| if not ok then |  | ||||||
|     return |  | ||||||
| end |  | ||||||
| 
 |  | ||||||
| null.setup { |  | ||||||
|     sources = { |  | ||||||
|         null.builtins.diagnostics.eslint, |  | ||||||
|         null.builtins.diagnostics.shellcheck, |  | ||||||
|         null.builtins.formatting.prettierd, |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | @ -28,9 +28,9 @@ require "paq" { | ||||||
|     { "nvim-telescope/telescope.nvim",            branch = "0.1.x" }, |     { "nvim-telescope/telescope.nvim",            branch = "0.1.x" }, | ||||||
|     { "nvim-telescope/telescope-fzf-native.nvim", run = "make" }, |     { "nvim-telescope/telescope-fzf-native.nvim", run = "make" }, | ||||||
|     { "catppuccin/nvim",                          as = "catppuccin" }, |     { "catppuccin/nvim",                          as = "catppuccin" }, | ||||||
|     { "williamboman/mason.nvim",                  branch = "v1.0.1" }, |     { "williamboman/mason.nvim",                  branch = "v1.6.0" }, | ||||||
|  |     { "lukas-reineke/lsp-format.nvim",            branch = "v2.5.1" }, | ||||||
|     "stevearc/oil.nvim", |     "stevearc/oil.nvim", | ||||||
|     "jose-elias-alvarez/null-ls.nvim", |  | ||||||
| 
 | 
 | ||||||
|     -- Treesitter |     -- Treesitter | ||||||
|     { "nvim-treesitter/nvim-treesitter", branch = "master" }, |     { "nvim-treesitter/nvim-treesitter", branch = "master" }, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue