From a0d4284f53f90fb94430edb5309cee4bc0067e7e Mon Sep 17 00:00:00 2001 From: phajw Date: Thu, 25 Jan 2024 16:31:23 +0100 Subject: Add licence, enable silent formatters execution --- lua/config/editor.lua | 137 +++++++++++++++----------------------------------- lua/config/lsp.lua | 108 +++++++++++++++++---------------------- lua/config/packer.lua | 115 ++++++++++++++++++++++-------------------- 3 files changed, 148 insertions(+), 212 deletions(-) (limited to 'lua') diff --git a/lua/config/editor.lua b/lua/config/editor.lua index 9594778..daff2ad 100644 --- a/lua/config/editor.lua +++ b/lua/config/editor.lua @@ -1,35 +1,30 @@ local js_based_languages = { "typescript", "javascript", "typescriptreact", "javascriptreact" } -local option = vim.opt; -local keymap = vim.keymap; +local option = vim.opt +local keymap = vim.keymap -local dap = require("dap") -local telescope = require('telescope.builtin'); -local autotag = require('nvim-ts-autotag').setup(); -local dap_vscode = require("dap-vscode-js").setup({ - debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", - adapters = { 'chrome', 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost', 'node', 'chrome' }, -}) +local telescope = require("telescope.builtin") +local autotag = require("nvim-ts-autotag").setup() --Basic Editor Setup -option.nu = true; -option.tabstop = 2; -option.softtabstop = 2; -option.shiftwidth = 2; -option.expandtab = true; -option.smartindent = true; -option.wrap = false; -option.swapfile = false; -option.hlsearch = false; -option.incsearch = true; -option.updatetime = 50; -option.laststatus = 0; -option.signcolumn = "number"; -option.autoindent = true; -option.clipboard = "unnamedplus"; -option.termguicolors = true; +option.nu = true +option.tabstop = 2 +option.softtabstop = 2 +option.shiftwidth = 2 +option.expandtab = true +option.smartindent = true +option.wrap = false +option.swapfile = false +option.hlsearch = false +option.incsearch = true +option.updatetime = 50 +option.laststatus = 0 +option.signcolumn = "number" +option.autoindent = true +option.clipboard = "unnamedplus" +option.termguicolors = true -- Setup Editor Theme -vim.cmd.colorscheme("darkblue") +vim.cmd.colorscheme("gruvbox") vim.cmd([[ highlight GitGutterAdd ctermbg=none highlight GitGutterAdd guibg=none @@ -39,92 +34,42 @@ highlight signcolumn ctermbg=none highlight signcolumn guibg=none ]]) + -- run specific commands after different file extensions vim.cmd([[ augroup RunPfOnSave autocmd! -autocmd BufWritePost *.js,*.ts,*.jsx,*json !prettier --write % +autocmd BufWritePost *.js,*.ts,*.jsx,*json,*.tsx,*.css,*.html,*.yaml,*.md silent! !prettier --write % autocmd BufWritePost *.tex :VimtexCompile -autocmd BufWritePost *.md :MarkdownPreview +autocmd BufWritePost *.md silent! :MarkdownPreview +autocmd BufWritePost *.php silent! !php-cs-fixer fix % augroup END ]]) -- Gui options vim.o.guifont = "Fira Code:h7" -vim.g.vimtex_view_method = 'zathura' -vim.g.vimtex_compiler_method = 'latexrun' -vim.g.gitgutter_set_sign_backgrounds = 1; -vim.fn.sign_define('DapBreakpoint',{ text ='🟥', texthl ='', linehl ='', numhl =''}) -vim.fn.sign_define('DapStopped',{ text ='▶️', texthl ='', linehl ='', numhl =''}) +vim.g.vimtex_view_method = "zathura" +vim.g.vimtex_compiler_method = "latexrun" +vim.g.gitgutter_set_sign_backgrounds = 1 --Keybinds -vim.g.mapleader = (" ") +vim.g.mapleader = " " keymap.set("n", "e", vim.cmd.Ex) -keymap.set('n', 'f', telescope.find_files, {}) -keymap.set('n', 'fg', telescope.live_grep, {}) -keymap.set('n', 'fb', telescope.buffers, {}) -keymap.set('n', 'fh', telescope.help_tags, {}) +keymap.set("n", "f", telescope.find_files, {}) +keymap.set("n", "fg", telescope.live_grep, {}) +keymap.set("n", "fb", telescope.buffers, {}) +keymap.set("n", "fh", telescope.help_tags, {}) keymap.set("n", "s", [[:%s/\<\>//gI]]) keymap.set("n", "a", "ggVG") keymap.set("v", "J", ":m '>+1gv=gv") keymap.set("v", "K", ":m '<-2gv=gv") --- Debugger keybinds -keymap.set('n', '', require 'dap'.continue) -keymap.set('n', '', require 'dap'.step_over) -keymap.set('n', '', require 'dap'.step_into) -keymap.set('n', '', require 'dap'.step_out) -keymap.set('n', 'b', require 'dap'.toggle_breakpoint) - -keymap.set('n', 'B', function() - require 'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: ')) -end) - -keymap.set('n', 'ui', require 'dapui'.toggle) -for _, language in ipairs(js_based_languages) do - require("dap").configurations[language] = { - { - type = "pwa-node", - request = "launch", - name = "Launch file", - program = "${file}", - cwd = "${workspaceFolder}", - }, - { - type = "pwa-node", - request = "attach", - name = "Attach", - processId = require 'dap.utils'.pick_process, - cwd = "${workspaceFolder}", - }, - { - type = "pwa-chrome", - request = "launch", - name = "Start Chrome with \"localhost\"", - url = "http://localhost:3000", - webRoot = "${workspaceFolder}", - userDataDir = "${workspaceFolder}/.vscode/vscode-chrome-debug-userdatadir" - } - } -end -require("dapui").setup() -local dap, dapui = require("dap"), require("dapui") -dap.listeners.after.event_initialized["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 - --Treesitter -require 'nvim-treesitter.configs'.setup { - ensure_installed = { "javascript", "typescript", "rust", "c", "lua", "vim" }, - sync_install = false, - auto_install = true, - highlight = { - enable = true, - } -} +require("nvim-treesitter.configs").setup({ + ensure_installed = { "javascript", "typescript", "rust", "c", "lua", "vim" }, + sync_install = false, + auto_install = true, + highlight = { + enable = true, + }, +}) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 3fdc2e0..fdcfe99 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -1,78 +1,64 @@ -- local lsp = require('lsp-zero') -local lsp_zero = require('lsp-zero') -local cmp = require('cmp') +local lsp_zero = require("lsp-zero") +local cmp = require("cmp") require("luasnip.loaders.from_vscode").lazy_load() -lsp_zero.preset('recommended') +lsp_zero.preset("recommended") lsp_zero.setup() -lsp_zero.on_attach(function(client, bufnr) - -- see :help lsp-zero-keybindings - -- to learn the available actions - lsp_zero.default_keymaps({buffer = bufnr}) +lsp_zero.on_attach(function(client_id, bufnr) + lsp_zero.default_keymaps({ buffer = bufnr }) end) -require('mason').setup({}) -require('mason-lspconfig').setup({ - -- Replace the language servers listed here - -- with the ones you want to install - ensure_installed = {'tsserver', 'rust_analyzer', 'eslint'}, - handlers = { - lsp_zero.default_setup, - }, +require("mason").setup({}) +require("mason-lspconfig").setup({ + ensure_installed = { "tsserver", "rust_analyzer", "eslint" }, + handlers = { + lsp_zero.default_setup, + }, }) - - ---require('tabnine').setup({ --- disable_auto_comment=true, --- accept_keymap="", --- dismiss_keymap = "", --- debounce_ms = 800, --- suggestion_color = {gui = "#808080", cterm = 244}, --- execlude_filetypes = {"TelescopePrompt"} ---}) - cmp.setup({ - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - window = { - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = 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' }, - }) + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + window = {}, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + [""] = 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" }, + }), }) function PrintDiagnostics(opts, bufnr, line_nr, client_id) - bufnr = bufnr or 0 - line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) - opts = opts or { ['lnum'] = line_nr } + bufnr = bufnr or 0 + line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) + opts = opts or { ["lnum"] = line_nr } - local line_diagnostics = vim.diagnostic.get(bufnr, opts) - if vim.tbl_isempty(line_diagnostics) then return end + local line_diagnostics = vim.diagnostic.get(bufnr, opts) + if vim.tbl_isempty(line_diagnostics) then + return + end - local diagnostic_message = "" - for i, diagnostic in ipairs(line_diagnostics) do - diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") - print(diagnostic_message) - if i ~= #line_diagnostics then - diagnostic_message = diagnostic_message .. "\n" - end - end - vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {}) + local diagnostic_message = "" + for i, diagnostic in ipairs(line_diagnostics) do + diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") + print(diagnostic_message) + if i ~= #line_diagnostics then + diagnostic_message = diagnostic_message .. "\n" + end + end + vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {}) end -vim.cmd [[ autocmd! CursorHold * lua PrintDiagnostics() ]] +vim.cmd([[ autocmd! CursorHold * lua PrintDiagnostics() ]]) diff --git a/lua/config/packer.lua b/lua/config/packer.lua index 887b330..36b9058 100644 --- a/lua/config/packer.lua +++ b/lua/config/packer.lua @@ -1,56 +1,61 @@ -vim.cmd [[packadd packer.nvim]] -return require('packer').startup(function(use) - use 'wbthomason/packer.nvim' - use 'nvim-treesitter/nvim-treesitter' - use 'neovim/nvim-lspconfig' - use 'lukas-reineke/indent-blankline.nvim' - use 'lervag/vimtex' - use 'morhetz/gruvbox' - use 'airblade/vim-gitgutter' - use 'jose-elias-alvarez/null-ls.nvim' - use 'windwp/nvim-ts-autotag' - use 'lunacookies/vim-colors-xcode' - use 'mfussenegger/nvim-dap' - use 'mxsdev/nvim-dap-vscode-js' - use { "rcarriga/nvim-dap-ui", requires = {"mfussenegger/nvim-dap"} } -use { - 'nvim-telescope/telescope.nvim', tag = '0.1.4', - requires = { {'nvim-lua/plenary.nvim'} } -} - use { - 'VonHeikemen/lsp-zero.nvim', - requires = { - { 'neovim/nvim-lspconfig' }, - { 'williamboman/mason.nvim' }, - { 'williamboman/mason-lspconfig.nvim' }, - { 'hrsh7th/nvim-cmp' }, - { 'hrsh7th/cmp-buffer' }, - { 'hrsh7th/cmp-path' }, - { 'saadparwaiz1/cmp_luasnip' }, - { 'hrsh7th/cmp-nvim-lsp' }, - { 'hrsh7th/cmp-nvim-lua' }, - { 'rafamadriz/friendly-snippets' }, - } - } - use({ - "L3MON4D3/LuaSnip", - tag = "v2.*", - run = "make install_jsregexp" - }) - use { - 'numToStr/Comment.nvim', - config = function() - require('Comment').setup() - end - } - use({ - "iamcco/markdown-preview.nvim", - run = "cd app && npm install", - setup = function() vim.g.mkdp_filetypes = { "markdown" } end, - ft = { "markdown" }, - }) - use { - "windwp/nvim-autopairs", - config = function() require("nvim-autopairs").setup {} end - } +vim.cmd([[packadd packer.nvim]]) +return require("packer").startup(function(use) + use("wbthomason/packer.nvim") + use("nvim-treesitter/nvim-treesitter") + use("neovim/nvim-lspconfig") + use("lukas-reineke/indent-blankline.nvim") + use("lervag/vimtex") + use("morhetz/gruvbox") + use("airblade/vim-gitgutter") + use("jose-elias-alvarez/null-ls.nvim") + use("windwp/nvim-ts-autotag") + use("lunacookies/vim-colors-xcode") + use("mfussenegger/nvim-dap") + use("mxsdev/nvim-dap-vscode-js") + use({ "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap" } }) + use({ + "nvim-telescope/telescope.nvim", + tag = "0.1.4", + requires = { { "nvim-lua/plenary.nvim" } }, + }) + use({ + "VonHeikemen/lsp-zero.nvim", + requires = { + { "neovim/nvim-lspconfig" }, + { "williamboman/mason.nvim" }, + { "williamboman/mason-lspconfig.nvim" }, + { "hrsh7th/nvim-cmp" }, + { "hrsh7th/cmp-buffer" }, + { "hrsh7th/cmp-path" }, + { "saadparwaiz1/cmp_luasnip" }, + { "hrsh7th/cmp-nvim-lsp" }, + { "hrsh7th/cmp-nvim-lua" }, + { "rafamadriz/friendly-snippets" }, + }, + }) + use({ + "L3MON4D3/LuaSnip", + tag = "v2.*", + run = "make install_jsregexp", + }) + use({ + "numToStr/Comment.nvim", + config = function() + require("Comment").setup() + end, + }) + use({ + "iamcco/markdown-preview.nvim", + run = "cd app && npm install", + setup = function() + vim.g.mkdp_filetypes = { "markdown" } + end, + ft = { "markdown" }, + }) + use({ + "windwp/nvim-autopairs", + config = function() + require("nvim-autopairs").setup({}) + end, + }) end) -- cgit v1.2.3