fix lsp autoformatting on save
tested python and rust
This commit is contained in:
		
							parent
							
								
									b521d84e7f
								
							
						
					
					
						commit
						0fabc551bd
					
				
					 1 changed files with 10 additions and 7 deletions
				
			
		
							
								
								
									
										17
									
								
								lua/lsp.lua
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								lua/lsp.lua
									
										
									
									
									
								
							|  | @ -1,5 +1,6 @@ | |||
| local on_attach = function(client, bufnr) | ||||
|     local utils = require('utils') | ||||
|     local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) | ||||
| 
 | ||||
|     -- Mappings. | ||||
|     utils.map("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>") | ||||
|  | @ -12,14 +13,16 @@ local on_attach = function(client, bufnr) | |||
|     utils.map("n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>") | ||||
|     utils.map("n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>") | ||||
| 
 | ||||
|     -- Set formatting keybinds conditional on server capabilities | ||||
|     if client.server_capabilities.document_formatting then | ||||
|         utils.map('n', '<leader>lf', '<cmd>lua vim.lsp.buf.formatting()<CR>') | ||||
|     elseif client.server_capabilities.document_range_formatting then | ||||
|         utils.map('n', '<leader>lf', '<cmd>lua vim.lsp.buf.range_formatting()<CR>') | ||||
|     if client.supports_method("textDocument/formatting") then | ||||
|         vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) | ||||
|         vim.api.nvim_create_autocmd("BufWritePre", { | ||||
|             group = augroup, | ||||
|             buffer = bufnr, | ||||
|             callback = function() | ||||
|                 vim.lsp.buf.format() | ||||
|             end, | ||||
|         }) | ||||
|     end | ||||
| 
 | ||||
|     client.server_capabilities.semanticTokensProvider = nil | ||||
| end | ||||
| 
 | ||||
| local nvim_lsp = require('lspconfig') | ||||
|  |  | |||
		Reference in a new issue