Эх сурвалжийг харах

✨feat: add LSP and IDEish plugins

Naz 2 сар өмнө
parent
commit
9b9eab0b94

+ 1 - 1
init.lua

@@ -1,3 +1,3 @@
-require("config.lazy")
 require("config.options")
+require("config.lazy")
 require("config.mappings")

+ 22 - 2
lua/config/mappings.lua

@@ -15,7 +15,27 @@ vim.api.nvim_set_keymap(
 )
 vim.api.nvim_set_keymap("n", "<Esc>", ":noh<CR>", { noremap = true, silent = true, desc = "Clear Search" })
 
-
 -- bufferline keymaps
 
-vim.api.nvim_set_keymap("n", "<leader>C", ":BufferLineCloseOthers<CR>", { noremap = true, silent = true, desc = "Close Other Buffers" })
+vim.api.nvim_set_keymap(
+	"n",
+	"<leader>C",
+	":BufferLineCloseOthers<CR>",
+	{ noremap = true, silent = true, desc = "Close Other Buffers" }
+)
+
+-- nvim-dap keymaps
+
+vim.keymap.set("n", "<Leader>db", require("dap").toggle_breakpoint, { desc = "DAP Toggle Breakpoint" })
+vim.keymap.set("n", "<Leader>dc", require("dap").continue, { desc = "DAP Continue" })
+vim.keymap.set("n", "<Leader>dsv", require("dap").step_over, { desc = "DAP Step Over" })
+vim.keymap.set("n", "<Leader>dsi", require("dap").step_into, { desc = "DAP Step Into" })
+vim.keymap.set("n", "<Leader>dso", require("dap").step_out, { desc = "DAP Step Out" })
+
+-- lsp keymaps
+
+vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "LSP Hover" })
+vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "LSP Definition" })
+vim.keymap.set("n", "er", vim.diagnostic.open_float, { desc = "LSP Diagnostics" })
+vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, { desc = "LSP Code Action" })
+vim.keymap.set("n", "<leader>gf", vim.lsp.buf.format, { desc = "LSP Format" })

+ 52 - 0
lua/plugins/completions.lua

@@ -0,0 +1,52 @@
+return {
+	{
+		"hrsh7th/cmp-nvim-lsp",
+		lazy = false,
+		config = true,
+	},
+	{
+		"L3MON4D3/LuaSnip",
+		lazy = false,
+		dependencies = {
+			"saadparwaiz1/cmp_luasnip",
+			"rafamadriz/friendly-snippets",
+		},
+		config = function()
+			require("luasnip.loaders.from_vscode").lazy_load()
+			require("luasnip.loaders.from_vscode").load({ paths = { "~/.config/nvim/snippets" } })
+		end,
+	},
+	{
+		"hrsh7th/nvim-cmp",
+		lazy = false,
+		config = function()
+			local cmp = require("cmp")
+			cmp.setup({
+				snippet = {
+					expand = function(args)
+						require("luasnip").lsp_expand(args.body)
+					end,
+				},
+				window = {
+					completion = cmp.config.window.bordered(),
+					documentation = cmp.config.window.bordered(),
+				},
+				mapping = cmp.mapping.preset.insert({
+					["<Tab>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
+					["<S-Tab>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
+					["<C-b>"] = cmp.mapping.scroll_docs(-4),
+					["<C-f>"] = cmp.mapping.scroll_docs(4),
+					["<C-Space>"] = cmp.mapping.complete(),
+					["<C-e>"] = cmp.mapping.abort(),
+					["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
+				}),
+				sources = cmp.config.sources({
+					{ name = "nvim_lsp" },
+					{ name = "luasnip" },
+				}, {
+					{ name = "buffer" },
+				}),
+			})
+		end,
+	},
+}

+ 16 - 0
lua/plugins/dadbod.lua

@@ -0,0 +1,16 @@
+return {
+	"kristijanhusak/vim-dadbod-ui",
+	dependencies = {
+		{ "tpope/vim-dadbod", lazy = true },
+		{ "kristijanhusak/vim-dadbod-completion", ft = { "sql", "mysql", "plsql", "sqloracle" }, lazy = true },
+	},
+	cmd = {
+		"DBUI",
+		"DBUIToggle",
+		"DBUIAddConnection",
+		"DBUIFindBuffer",
+	},
+	init = function()
+		vim.g.db_ui_use_nerd_fonts = 1
+	end,
+}

+ 68 - 0
lua/plugins/debugging.lua

@@ -0,0 +1,68 @@
+return {
+	"mfussenegger/nvim-dap",
+	dependencies = {
+		"rcarriga/nvim-dap-ui",
+		"nvim-neotest/nvim-nio",
+	},
+
+	config = function()
+		local dap, dapui = require("dap"), require("dapui")
+
+		require("dapui").setup()
+
+		dap.listeners.before.attach.dapui_config = function()
+			dapui.open()
+		end
+		dap.listeners.before.launch.dapui_config = function()
+			dapui.open()
+		end
+		dap.listeners.before.event_terminated.dapui_config = function()
+			dapui.close()
+		end
+		dap.listeners.before.event_exited.dapui_config = function()
+			dapui.close()
+		end
+
+		dap.adapters.lldb = {
+			type = "executable",
+			command = "/usr/bin/lldb-vscode",
+			name = "lldb",
+		}
+
+		dap.configurations.rust = {
+			{
+				name = "Launch",
+				type = "lldb",
+				request = "launch",
+				program = function()
+					return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
+				end,
+				cwd = "${workspaceFolder}",
+				stopOnEntry = false,
+				args = {},
+
+				initCommands = function()
+					-- Find out where to look for the pretty printer Python module
+					local rustc_sysroot = vim.fn.trim(vim.fn.system("rustc --print sysroot"))
+
+					local script_import = 'command script import "'
+						.. rustc_sysroot
+						.. '/lib/rustlib/etc/lldb_lookup.py"'
+					local commands_file = rustc_sysroot .. "/lib/rustlib/etc/lldb_commands"
+
+					local commands = {}
+					local file = io.open(commands_file, "r")
+					if file then
+						for line in file:lines() do
+							table.insert(commands, line)
+						end
+						file:close()
+					end
+					table.insert(commands, 1, script_import)
+
+					return commands
+				end,
+			},
+		}
+	end,
+}

+ 13 - 0
lua/plugins/indent-blankline.lua

@@ -0,0 +1,13 @@
+return {
+	"lukas-reineke/indent-blankline.nvim",
+	main = "ibl",
+	opts = {},
+	config = function()
+		require("ibl").setup({
+			whitespace = {
+				remove_blankline_trail = true,
+			},
+			scope = { enabled = false },
+		})
+	end,
+}

+ 55 - 0
lua/plugins/lsp-config.lua

@@ -0,0 +1,55 @@
+return {
+	{
+		"williamboman/mason.nvim",
+		config = function()
+			require("mason").setup()
+		end,
+	},
+	{
+		"williamboman/mason-lspconfig.nvim",
+		config = function()
+			require("mason-lspconfig").setup({
+				ensure_installed = {
+					"lua_ls",
+					"rust_analyzer",
+					"texlab",
+					"svelte",
+					"bashls",
+					"cssls",
+					"html",
+					"vtsls",
+					"ts_ls",
+					"clangd",
+					"tailwindcss",
+				},
+			})
+		end,
+	},
+	{
+		"neovim/nvim-lspconfig",
+		config = function()
+			local capabilities = require("cmp_nvim_lsp").default_capabilities()
+
+			local lspconfig = require("lspconfig")
+			local servers = {
+				"lua_ls",
+				"texlab",
+				"svelte",
+				"bashls",
+				"cssls",
+				"html",
+				"vtsls",
+				"ts_ls",
+				"clangd",
+				"clangd",
+				"tailwindcss",
+			}
+
+			for _, lsp in ipairs(servers) do
+				lspconfig[lsp].setup({
+					capabilities = capabilities,
+				})
+			end
+		end,
+	},
+}

+ 16 - 0
lua/plugins/none-ls.lua

@@ -0,0 +1,16 @@
+return {
+	"nvimtools/none-ls.nvim",
+	config = function()
+		local null_ls = require("null-ls")
+
+		null_ls.setup({
+			sources = {
+				null_ls.builtins.formatting.stylua,
+				null_ls.builtins.formatting.prettier,
+				null_ls.builtins.formatting.markdownlint,
+				null_ls.builtins.formatting.sql_formatter,
+				null_ls.builtins.formatting.bibclean,
+			},
+		})
+	end,
+}

+ 5 - 0
lua/plugins/rustaceanvim.lua

@@ -0,0 +1,5 @@
+return {
+	"mrcjkb/rustaceanvim",
+	version = "^5", -- Recommended
+	lazy = false, -- This plugin is already lazy
+}

+ 5 - 0
lua/plugins/tailwind-tools.lua

@@ -0,0 +1,5 @@
+return {
+	"luckasRanarison/tailwind-tools.nvim",
+	dependencies = { "nvim-treesitter/nvim-treesitter" },
+	opts = {}, -- your configuration
+}

+ 18 - 0
lua/plugins/treesitter.lua

@@ -0,0 +1,18 @@
+return {
+	"nvim-treesitter/nvim-treesitter",
+	build = ":TSUpdate",
+	config = function()
+		local configs = require("nvim-treesitter.configs")
+		configs.setup({
+			sync_install = false,
+
+			auto_install = true,
+
+			highlight = {
+				enable = true,
+				additional_vim_regex_highlighting = false,
+			},
+			indent = { enable = true },
+		})
+	end,
+}

+ 7 - 0
snippets/global.json

@@ -0,0 +1,7 @@
+{
+  "Naz's git config": {
+    "prefix": "gitnaz",
+    "body": ["[user]", "  name = Naz", "  email = [email protected]"],
+    "description": "Naz's git config"
+  }
+}

+ 27 - 0
snippets/package.json

@@ -0,0 +1,27 @@
+{
+  "name": "my-snippets",
+  "engines": {
+    "vscode": "^1.11.0"
+  },
+  "contributes": {
+    "snippets": [
+      {
+        "language": [
+          "plaintext",
+          "markdown",
+          "tex",
+          "html",
+          "global",
+          "all"
+        ],
+        "path": "./global.json"
+      },
+      {
+        "language": [
+          "sql"
+        ],
+        "path": "./sql.json"
+      }
+    ]
+  }
+}

+ 21 - 0
snippets/sql.json

@@ -0,0 +1,21 @@
+{
+  "BaseAuditEntity fields": {
+    "prefix": "sqlbae",
+    "body": [
+      "-- BaseAuditEntity fields",
+      "creator INT NOT NULL, -- FK to users.user_id",
+      "date_created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,",
+      "changed_by INT DEFAULT NULL, -- FK to users.user_id",
+      "date_changed TIMESTAMP DEFAULT NULL,",
+      "voided BOOLEAN NOT NULL DEFAULT FALSE,",
+      "voided_by INT DEFAULT NULL, -- FK to users.user_id",
+      "date_voided TIMESTAMP DEFAULT NULL,",
+      "void_reason VARCHAR(256) DEFAULT NULL,",
+      "uuid UUID NOT NULL DEFAULT gen_random_uuid () UNIQUE,",
+      "CONSTRAINT fk_${0}_creator FOREIGN KEY (creator) REFERENCES users (user_id),",
+      "CONSTRAINT fk_${0}_changed_by FOREIGN KEY (changed_by) REFERENCES users (user_id),",
+      "CONSTRAINT fk_${0}_voided_by FOREIGN KEY (voided_by) REFERENCES users (user_id)"
+    ],
+    "description": "BaseAuditEntity fields"
+  }
+}