Added formatting, linter, and mason_tool_install
This commit is contained in:
		
							parent
							
								
									c54236b7ac
								
							
						
					
					
						commit
						8bce42bec4
					
				
							
								
								
									
										146
									
								
								init.lua
								
								
								
								
							
							
						
						
									
										146
									
								
								init.lua
								
								
								
								
							| 
						 | 
					@ -69,6 +69,7 @@ require('lazy').setup({
 | 
				
			||||||
      -- Automatically install LSPs to stdpath for neovim
 | 
					      -- Automatically install LSPs to stdpath for neovim
 | 
				
			||||||
      { 'williamboman/mason.nvim', config = true },
 | 
					      { 'williamboman/mason.nvim', config = true },
 | 
				
			||||||
      'williamboman/mason-lspconfig.nvim',
 | 
					      'williamboman/mason-lspconfig.nvim',
 | 
				
			||||||
 | 
					      'WhoIsSethDaniel/mason-tool-installer.nvim',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      -- Useful status updates for LSP
 | 
					      -- Useful status updates for LSP
 | 
				
			||||||
      -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
 | 
					      -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
 | 
				
			||||||
| 
						 | 
					@ -171,9 +172,18 @@ require('lazy').setup({
 | 
				
			||||||
    'lukas-reineke/indent-blankline.nvim',
 | 
					    'lukas-reineke/indent-blankline.nvim',
 | 
				
			||||||
    -- Enable `lukas-reineke/indent-blankline.nvim`
 | 
					    -- Enable `lukas-reineke/indent-blankline.nvim`
 | 
				
			||||||
    -- See `:help indent_blankline.txt`
 | 
					    -- See `:help indent_blankline.txt`
 | 
				
			||||||
 | 
					    main = "ibl",
 | 
				
			||||||
    opts = {
 | 
					    opts = {
 | 
				
			||||||
      char = '┊',
 | 
					      indent = {
 | 
				
			||||||
      show_trailing_blankline_indent = false,
 | 
					        --[[ highlight = highlight ]]
 | 
				
			||||||
 | 
					        char = "┆",
 | 
				
			||||||
 | 
					        smart_indent_cap = true,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      whitespace = {
 | 
				
			||||||
 | 
					        --[[ highlight = highlight, ]]
 | 
				
			||||||
 | 
					        remove_blankline_trail = false,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      scope = { enabled = true },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -211,8 +221,13 @@ require('lazy').setup({
 | 
				
			||||||
    'nvim-treesitter/nvim-treesitter',
 | 
					    'nvim-treesitter/nvim-treesitter',
 | 
				
			||||||
    dependencies = {
 | 
					    dependencies = {
 | 
				
			||||||
      'nvim-treesitter/nvim-treesitter-textobjects',
 | 
					      'nvim-treesitter/nvim-treesitter-textobjects',
 | 
				
			||||||
 | 
					      'windwp/nvim-ts-autotag',
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    build = ':TSUpdate',
 | 
					    build = ':TSUpdate',
 | 
				
			||||||
 | 
					    -- setup autotag with default options
 | 
				
			||||||
 | 
					    opts = {
 | 
				
			||||||
 | 
					      enable = true,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart
 | 
					  -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart
 | 
				
			||||||
| 
						 | 
					@ -321,7 +336,7 @@ vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc =
 | 
				
			||||||
-- See `:help nvim-treesitter`
 | 
					-- See `:help nvim-treesitter`
 | 
				
			||||||
require('nvim-treesitter.configs').setup {
 | 
					require('nvim-treesitter.configs').setup {
 | 
				
			||||||
  -- Add languages to be installed here that you want installed for treesitter
 | 
					  -- Add languages to be installed here that you want installed for treesitter
 | 
				
			||||||
  ensure_installed = { 'c', 'cpp', 'lua', 'python', 'vimdoc', 'vim' },
 | 
					  ensure_installed = { 'c', 'cpp', 'lua', 'python', 'go', 'vimdoc', 'vim' },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
 | 
					  -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
 | 
				
			||||||
  auto_install = false,
 | 
					  auto_install = false,
 | 
				
			||||||
| 
						 | 
					@ -432,6 +447,14 @@ local on_attach = function(_, bufnr)
 | 
				
			||||||
  vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
 | 
					  vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
 | 
				
			||||||
    vim.lsp.buf.format()
 | 
					    vim.lsp.buf.format()
 | 
				
			||||||
  end, { desc = 'Format current buffer with LSP' })
 | 
					  end, { desc = 'Format current buffer with LSP' })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -- Enable auto-formatting on save
 | 
				
			||||||
 | 
					  vim.api.nvim_command([[
 | 
				
			||||||
 | 
					    augroup AutoFormatOnSave
 | 
				
			||||||
 | 
					      autocmd!
 | 
				
			||||||
 | 
					      autocmd BufWritePre * :Format
 | 
				
			||||||
 | 
					    augroup END
 | 
				
			||||||
 | 
					  ]])
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Enable the following language servers
 | 
					-- Enable the following language servers
 | 
				
			||||||
| 
						 | 
					@ -442,19 +465,98 @@ end
 | 
				
			||||||
--
 | 
					--
 | 
				
			||||||
--  If you want to override the default filetypes that your language server will attach to you can
 | 
					--  If you want to override the default filetypes that your language server will attach to you can
 | 
				
			||||||
--  define the property 'filetypes' to the map in question.
 | 
					--  define the property 'filetypes' to the map in question.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Function to find the nearest venv path in parent directories.
 | 
				
			||||||
 | 
					local function find_nearest_venv(starting_path)
 | 
				
			||||||
 | 
					  local current_path = starting_path
 | 
				
			||||||
 | 
					  while current_path do
 | 
				
			||||||
 | 
					    local venv_path = current_path .. '/venv/bin/python'
 | 
				
			||||||
 | 
					    if vim.fn.filereadable(venv_path) == 1 then
 | 
				
			||||||
 | 
					      return venv_path
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    local parent_path = vim.fn.fnamemodify(current_path, ':h')
 | 
				
			||||||
 | 
					    if parent_path == current_path then
 | 
				
			||||||
 | 
					      break
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    current_path = parent_path
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  return nil
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Get the path of the current file.
 | 
				
			||||||
 | 
					local current_file = vim.fn.expand('%:p')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Get the venv path for the current project directory.
 | 
				
			||||||
 | 
					local venv_path = find_nearest_venv(current_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if venv_path then
 | 
				
			||||||
 | 
					  -- Use the venv path as your Python interpreter.
 | 
				
			||||||
 | 
					  vim.g.python3_host_prog = venv_path
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					  -- Fallback to a system-wide Python interpreter.
 | 
				
			||||||
 | 
					  vim.g.python3_host_prog = '/usr/bin/python3'
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local servers = {
 | 
					local servers = {
 | 
				
			||||||
  clangd = {},
 | 
					  clangd = {},
 | 
				
			||||||
  -- gopls = {},
 | 
					  gopls = {
 | 
				
			||||||
  pyright = {
 | 
					 | 
				
			||||||
    settings = {
 | 
					    settings = {
 | 
				
			||||||
      pyright = { autoImportCompletion = true, },
 | 
					      plugins = {
 | 
				
			||||||
 | 
					        revive = {},
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      gopls = {
 | 
				
			||||||
 | 
					        completeUnimported = true,
 | 
				
			||||||
 | 
					        usePlaceholders = true,
 | 
				
			||||||
 | 
					        analysis = {
 | 
				
			||||||
 | 
					          unusedarams = true,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  pylsp = {
 | 
				
			||||||
 | 
					    settings = {
 | 
				
			||||||
 | 
					      pylsp = {
 | 
				
			||||||
 | 
					        plugins = {
 | 
				
			||||||
 | 
					          pycodestyle = {
 | 
				
			||||||
 | 
					            ignore = { 'W391' },
 | 
				
			||||||
 | 
					            maxLineLength = 79
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          flake8 = {},
 | 
				
			||||||
 | 
					          black = {
 | 
				
			||||||
 | 
					            lineLength = 79,
 | 
				
			||||||
 | 
					            -- Configure Black to split lines without specifying a target version
 | 
				
			||||||
 | 
					            blackArgs = {
 | 
				
			||||||
 | 
					              "--line-length",
 | 
				
			||||||
 | 
					              "79",
 | 
				
			||||||
 | 
					              "--exclude",
 | 
				
			||||||
 | 
					              "venv",
 | 
				
			||||||
 | 
					              "--exclude",
 | 
				
			||||||
 | 
					              "env",
 | 
				
			||||||
 | 
					              "--exclude",
 | 
				
			||||||
 | 
					              ".git",
 | 
				
			||||||
 | 
					              "--exclude",
 | 
				
			||||||
 | 
					              ".hg",
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          mypy = {
 | 
				
			||||||
 | 
					            enabled = true,
 | 
				
			||||||
 | 
					            command = 'mypy',
 | 
				
			||||||
 | 
					            args = {},
 | 
				
			||||||
 | 
					            diagnostics = true,
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          isort = {
 | 
				
			||||||
 | 
					            profile = 'black',
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
        python = {
 | 
					        python = {
 | 
				
			||||||
 | 
					          -- Specify the path to your Python interpreter
 | 
				
			||||||
          pythonPath = "/usr/bin/python3",
 | 
					          pythonPath = "/usr/bin/python3",
 | 
				
			||||||
          analysis = {
 | 
					          analysis = {
 | 
				
			||||||
            autoSearchPaths = true,
 | 
					            autoSearchPaths = true,
 | 
				
			||||||
            diagnosticMode = 'openFilesOnly',
 | 
					            diagnosticMode = 'openFilesOnly',
 | 
				
			||||||
            useLibraryCodeForTypes = true,
 | 
					            useLibraryCodeForTypes = true,
 | 
				
			||||||
          typeCheckingMode = 'off',
 | 
					            typeCheckingMode = 'on',
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
| 
						 | 
					@ -477,7 +579,18 @@ require('neodev').setup()
 | 
				
			||||||
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
 | 
					-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
 | 
				
			||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
 | 
					local capabilities = vim.lsp.protocol.make_client_capabilities()
 | 
				
			||||||
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
 | 
					capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
 | 
				
			||||||
 | 
					-- Setup Mason condifuration
 | 
				
			||||||
 | 
					local mason = require 'mason'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mason.setup {
 | 
				
			||||||
 | 
					  ui = {
 | 
				
			||||||
 | 
					    icons = {
 | 
				
			||||||
 | 
					      package_installed = "✓",
 | 
				
			||||||
 | 
					      package_pending = "➜",
 | 
				
			||||||
 | 
					      package_uninstalled = "✗",
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
-- Ensure the servers above are installed
 | 
					-- Ensure the servers above are installed
 | 
				
			||||||
local mason_lspconfig = require 'mason-lspconfig'
 | 
					local mason_lspconfig = require 'mason-lspconfig'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -496,6 +609,22 @@ mason_lspconfig.setup_handlers {
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Setup Linters
 | 
				
			||||||
 | 
					local mason_tool_installer = require("mason-tool-installer")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mason_tool_installer.setup({
 | 
				
			||||||
 | 
					  ensure_installed = {
 | 
				
			||||||
 | 
					    "prettier",
 | 
				
			||||||
 | 
					    "stylua",
 | 
				
			||||||
 | 
					    "isort",
 | 
				
			||||||
 | 
					    "black",
 | 
				
			||||||
 | 
					    "flake8",
 | 
				
			||||||
 | 
					    "mypy",
 | 
				
			||||||
 | 
					    "revive",
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- [[ Configure nvim-cmp ]]
 | 
					-- [[ Configure nvim-cmp ]]
 | 
				
			||||||
-- See `:help cmp`
 | 
					-- See `:help cmp`
 | 
				
			||||||
local cmp = require 'cmp'
 | 
					local cmp = require 'cmp'
 | 
				
			||||||
| 
						 | 
					@ -544,8 +673,5 @@ cmp.setup {
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require("venv-selector").setup({
 | 
					 | 
				
			||||||
  poetry_path = "%~",
 | 
					 | 
				
			||||||
})
 | 
					 | 
				
			||||||
-- The line beneath this is called `modeline`. See `:help modeline`
 | 
					-- The line beneath this is called `modeline`. See `:help modeline`
 | 
				
			||||||
-- vim: ts=2 sts=2 sw=2 et
 | 
					-- vim: ts=2 sts=2 sw=2 et
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,9 @@
 | 
				
			||||||
local opt = vim.opt
 | 
					local opt = vim.opt
 | 
				
			||||||
local g = vim.g
 | 
					local g = vim.g
 | 
				
			||||||
local options = {
 | 
					local options = {
 | 
				
			||||||
 | 
					  -- change cursor in insert mode 
 | 
				
			||||||
 | 
					  guicursor = "",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- Make line numbers default
 | 
					  -- Make line numbers default
 | 
				
			||||||
  relativenumber = true,
 | 
					  relativenumber = true,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -124,11 +127,11 @@ opt.formatoptions = opt.formatoptions
 | 
				
			||||||
    + "j" -- Auto-remove comments if possible.
 | 
					    + "j" -- Auto-remove comments if possible.
 | 
				
			||||||
    - "2" -- I'm not in gradeschool anymore
 | 
					    - "2" -- I'm not in gradeschool anymore
 | 
				
			||||||
 | 
					
 | 
				
			||||||
opt.guicursor = {
 | 
					-- opt.guicursor = {
 | 
				
			||||||
  "n-v:block",
 | 
					--   "n-v:block",
 | 
				
			||||||
  "i-c-ci-ve:ver25",
 | 
					--   "i-c-ci-ve:ver25",
 | 
				
			||||||
  "r-cr:hor20",
 | 
					--   "r-cr:hor20",
 | 
				
			||||||
  "o:hor50",
 | 
					--   "o:hor50",
 | 
				
			||||||
  "i:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor",
 | 
					--   "i:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor",
 | 
				
			||||||
  "sm:block-blinkwait175-blinkoff150-blinkon175",
 | 
					--   "sm:block-blinkwait175-blinkoff150-blinkon175",
 | 
				
			||||||
}
 | 
					-- }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,25 @@
 | 
				
			||||||
 | 
					return {
 | 
				
			||||||
 | 
					  "stevearc/conform.nvim",
 | 
				
			||||||
 | 
					  event = { "BufReadPre", "BufNewFile" },
 | 
				
			||||||
 | 
					  config = function()
 | 
				
			||||||
 | 
					    local conform = require("conform")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    conform.setup({
 | 
				
			||||||
 | 
					      formatters_by_ft = {
 | 
				
			||||||
 | 
					        python = { "isort", "black" },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      format_on_save = {
 | 
				
			||||||
 | 
					        lsp_fallback = true,
 | 
				
			||||||
 | 
					        async = false,
 | 
				
			||||||
 | 
					        timeout_ms = 500,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    vim.keymap.set({ "n", "v" }, "<leader>mp", function()
 | 
				
			||||||
 | 
					      conform.format({
 | 
				
			||||||
 | 
					        lsp_fallback = true,
 | 
				
			||||||
 | 
					        async = false,
 | 
				
			||||||
 | 
					        timeout_ms = 500,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    end, { desc = "Format file or range (in visual mode)" })
 | 
				
			||||||
 | 
					  end,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,29 @@
 | 
				
			||||||
 | 
					return {
 | 
				
			||||||
 | 
					  "mfussenegger/nvim-lint",
 | 
				
			||||||
 | 
					  event = {
 | 
				
			||||||
 | 
					    "BufReadPre",
 | 
				
			||||||
 | 
					    "BufNewFile",
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  config = function()
 | 
				
			||||||
 | 
					    local lint = require("lint")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    lint.linters_by_ft = {
 | 
				
			||||||
 | 
					      python = { "flake8", "mypy" },
 | 
				
			||||||
 | 
					      yaml = { "yamllint" },
 | 
				
			||||||
 | 
					      json = { "jsonlint" }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
 | 
				
			||||||
 | 
					      group = lint_augroup,
 | 
				
			||||||
 | 
					      callback = function()
 | 
				
			||||||
 | 
					        lint.try_lint()
 | 
				
			||||||
 | 
					      end,
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    vim.keymap.set("n", "<leader>ml", function()
 | 
				
			||||||
 | 
					      lint.try_lint()
 | 
				
			||||||
 | 
					    end, { desc = "Trigger linting for current file" })
 | 
				
			||||||
 | 
					  end,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue