diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..2e77153 --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,9 @@ +-- If stuff is broken try the following +-- 1. :PackerUpdate +-- 2. :Mason -> U +-- 3. :TSUpdate + +require('pfych.base') +require('pfych.plugins') +require('pfych.colours') +require('pfych.keybinds') diff --git a/.config/nvim/lua/.luarc.json b/.config/nvim/lua/.luarc.json new file mode 100644 index 0000000..deda1dc --- /dev/null +++ b/.config/nvim/lua/.luarc.json @@ -0,0 +1,5 @@ +{ + "diagnostics.disable": [ + "unused-local" + ] +} \ No newline at end of file diff --git a/.config/nvim/lua/pfych/base.lua b/.config/nvim/lua/pfych/base.lua new file mode 100644 index 0000000..b98df67 --- /dev/null +++ b/.config/nvim/lua/pfych/base.lua @@ -0,0 +1,30 @@ +vim.cmd("autocmd!") + +vim.scriptencoding = 'utf-8' +vim.opt.encoding = 'utf-8' +vim.opt.fileencoding = 'utf-8' + +vim.wo.relativenumber = true +vim.wo.number = true + +vim.opt.title = true +vim.opt.autoindent = true +vim.opt.smartindent = true +vim.opt.smarttab = true +vim.opt.expandtab = true +vim.opt.breakindent = true +vim.opt.shiftwidth = 2 +vim.opt.tabstop = 2 +vim.opt.mouse = "a" +vim.opt.undofile = true +vim.opt.undodir = vim.fn.expand('~/.vim/undodir') + +-- UXN Assembly on save +vim.cmd("command Uxnasm !uxnasm % %<.rom") +vim.cmd("autocmd BufWritePost *.tal :Uxnasm") + +-- Line wrap config +vim.opt.wrap = true +vim.opt.linebreak = true +vim.opt.breakindent = true +vim.opt.breakindentopt = "shift:2,min:40,sbr" diff --git a/.config/nvim/lua/pfych/colours.lua b/.config/nvim/lua/pfych/colours.lua new file mode 100644 index 0000000..71e05ae --- /dev/null +++ b/.config/nvim/lua/pfych/colours.lua @@ -0,0 +1,38 @@ +require("catppuccin").setup({ + flavour = "mocha", -- latte, frappe, macchiato, mocha + background = { -- :h background + light = "latte", + dark = "mocha", + }, + transparent_background = false, + no_italic = false, -- Force no italic + no_bold = false, -- Force no bold + styles = { + comments = { "italic" }, + conditionals = {}, + loops = {}, + functions = {}, + keywords = {}, + strings = {}, + variables = {}, + numbers = {}, + booleans = {}, + properties = {}, + types = {}, + operators = {}, + }, + color_overrides = { + mocha = { + base = "#1c1c1c", + mantle = "#1c1c1c", + crust = "#1c1c1c", + }, + }, + integrations = { + cmp = true, + }, +}) + +-- setup must be called before loading +vim.cmd('colorscheme catppuccin-mocha') +vim.api.nvim_set_hl(0, "Normal", { guibg = NONE, ctermbg = NONE }) diff --git a/.config/nvim/lua/pfych/keybinds.lua b/.config/nvim/lua/pfych/keybinds.lua new file mode 100644 index 0000000..1d7d3fa --- /dev/null +++ b/.config/nvim/lua/pfych/keybinds.lua @@ -0,0 +1,7 @@ +-- CodeActionsMenu with ? +vim.api.nvim_set_keymap("n", "?", ":CodeActionMenu", { silent = true, noremap = true }) +vim.api.nvim_set_keymap("n", ">", ":lua vim.diagnostic.goto_next()", { silent = true, noremap = true }) +vim.api.nvim_set_keymap("n", "<", ":lua vim.diagnostic.goto_prev()", { silent = true, noremap = true }) + +vim.opt.splitright = true +vim.api.nvim_set_keymap("n", "f", ":NERDTreeToggle", { noremap = true }) diff --git a/.config/nvim/lua/pfych/plugins.lua b/.config/nvim/lua/pfych/plugins.lua new file mode 100644 index 0000000..87de586 --- /dev/null +++ b/.config/nvim/lua/pfych/plugins.lua @@ -0,0 +1,42 @@ +local status, packer = pcall(require, "packer") +if (not status) then + print("Packer is not installed") + return +end + +vim.cmd [[packadd packer.nvim]] + +packer.startup(function(use) + use 'wbthomason/packer.nvim' + + use 'hrsh7th/cmp-buffer' -- nvim-cmp source for buffer words + use 'hrsh7th/cmp-nvim-lsp' -- nvim-cmp source for neovim's built-in LSP + use 'hrsh7th/nvim-cmp' -- Completion + use 'L3MON4D3/LuaSnip' + + use 'neovim/nvim-lspconfig' -- LSP + use 'jose-elias-alvarez/null-ls.nvim' + use 'williamboman/mason.nvim' -- LSP Installer + use 'williamboman/mason-lspconfig.nvim' + + use 'nvim-tree/nvim-web-devicons' + + use { 'catppuccin/nvim', as = "catppuccin" } + + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.8', -- For file searching :Telescope find_files + requires = { { 'nvim-lua/plenary.nvim' } } + } + + use { 'prettier/vim-prettier', build = 'pnpm install' } + + use { 'weilbith/nvim-code-action-menu', cmd = 'CodeActionMenu' } + + use 'bellinitte/uxntal.vim' + + use { 'edkolev/tmuxline.vim', run = ':Tmuxline vim_statusline_2' } + + use 'preservim/nerdtree' -- For filebrowser :NERDTree + + use 'elkowar/yuck.vim' +end) diff --git a/.config/nvim/plugin/barbar.lua b/.config/nvim/plugin/barbar.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/plugin/cmp.lua b/.config/nvim/plugin/cmp.lua new file mode 100644 index 0000000..b53e8be --- /dev/null +++ b/.config/nvim/plugin/cmp.lua @@ -0,0 +1,33 @@ +local cmp = require'cmp' + +local cmpStatus, cmp = pcall(require, "cmp") +if (not cmpStatus) then + print("cmp is not installed") + return +end + +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + local entry = cmp.get_selected_entry() + if not entry then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) + else + cmp.confirm() + end + else + fallback() + end + end, {"i","s","c",}), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'buffer' }, + }) +}) diff --git a/.config/nvim/plugin/lspconfig.lua b/.config/nvim/plugin/lspconfig.lua new file mode 100644 index 0000000..072df54 --- /dev/null +++ b/.config/nvim/plugin/lspconfig.lua @@ -0,0 +1,114 @@ +local status, nvim_lsp = pcall(require, "lspconfig") +if (not status) then return end + +local protocol = require('vim.lsp.protocol') + +local augroup_format = vim.api.nvim_create_augroup("Format", { clear = true }) +local enable_format_on_save = function(_, bufnr) + vim.api.nvim_clear_autocmds({ group = augroup_format, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup_format, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ bufnr = bufnr }) + end, + }) +end + +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + + local opts = { noremap = true, silent = true } + + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) +end + +protocol.CompletionItemKind = { + '', -- Text + '', -- Method + '', -- Function + '', -- Constructor + '', -- Field + '', -- Variable + '', -- Class + 'ﰮ', -- Interface + '', -- Module + '', -- Property + '', -- Unit + '', -- Value + '', -- Enum + '', -- Keyword + '﬌', -- Snippet + '', -- Color + '', -- File + '', -- Reference + '', -- Folder + '', -- EnumMember + '', -- Constant + '', -- Struct + '', -- Event + 'ﬦ', -- Operator + '', -- TypeParameter +} + +-- Set up completion using nvim_cmp with LSP source +local capabilities = require('cmp_nvim_lsp').default_capabilities() + +nvim_lsp.stylelint_lsp.setup { + filetypes = { "css", "scss" } +} + +nvim_lsp.tsserver.setup { + on_attach = on_attach, + filetypes = { "typescript", "typescriptreact", "typescript.tsx" }, + cmd = { "typescript-language-server", "--stdio" }, + capabilities = capabilities +} + +nvim_lsp.lua_ls.setup { + capabilities = capabilities, + on_attach = function(client, bufnr) + on_attach(client, bufnr) + enable_format_on_save(client, bufnr) + end, + settings = { + Lua = { + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { 'vim' }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + checkThirdParty = false + }, + }, + }, +} + +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + underline = true, + update_in_insert = false, + virtual_text = { spacing = 4, prefix = "●" }, + severity_sort = true, + } +) + +-- Diagnostic symbols in the sign column (gutter) +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end + +vim.diagnostic.config({ + virtual_text = { + prefix = '●' + }, + update_in_insert = true, + float = { + source = "always", -- Or "if_many" + }, +}) diff --git a/.config/nvim/plugin/mason.lua b/.config/nvim/plugin/mason.lua new file mode 100644 index 0000000..9432abf --- /dev/null +++ b/.config/nvim/plugin/mason.lua @@ -0,0 +1,17 @@ +local status, mason = pcall(require, "mason") +if (not status) then + print("mason is not installed") + return +end + +mason.setup({ + ensure_installed = { + "prettier", + "lua-language-server", + "luaformatter", + "eslint_d", + "typescript-language-server", + "stylelint-lsp" + }, + automatic_installation = true +}) diff --git a/.config/nvim/plugin/null-ls.lua b/.config/nvim/plugin/null-ls.lua new file mode 100644 index 0000000..d0274db --- /dev/null +++ b/.config/nvim/plugin/null-ls.lua @@ -0,0 +1,43 @@ +local status, null_ls = pcall(require, "null-ls") +if (not status) then return end + +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + +local lsp_formatting = function(bufnr) + vim.lsp.buf.format({ + filter = function(client) + return client.name == "null-ls" + end, + bufnr = bufnr, + }) +end + +null_ls.setup { + sources = { + null_ls.builtins.formatting.prettierd, + null_ls.builtins.diagnostics.eslint_d.with({ + diagnostics_format = '[eslint] #{m}\n(#{c})' + }), + null_ls.builtins.diagnostics.fish + }, + on_attach = function(client, bufnr) + 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() + lsp_formatting(bufnr) + end, + }) + end + end +} + +vim.api.nvim_create_user_command( + 'DisableLspFormatting', + function() + vim.api.nvim_clear_autocmds({ group = augroup, buffer = 0 }) + end, + { nargs = 0 } +) diff --git a/.config/nvim/plugin/packer_compiled.lua b/.config/nvim/plugin/packer_compiled.lua new file mode 100644 index 0000000..2818f91 --- /dev/null +++ b/.config/nvim/plugin/packer_compiled.lua @@ -0,0 +1,199 @@ +-- Automatically generated packer.nvim plugin loader code + +if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then + vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') + return +end + +vim.api.nvim_command('packadd packer.nvim') + +local no_errors, error_msg = pcall(function() + +_G._packer = _G._packer or {} +_G._packer.inside_compile = true + +local time +local profile_info +local should_profile = false +if should_profile then + local hrtime = vim.loop.hrtime + profile_info = {} + time = function(chunk, start) + if start then + profile_info[chunk] = hrtime() + else + profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 + end + end +else + time = function(chunk, start) end +end + +local function save_profiles(threshold) + local sorted_times = {} + for chunk_name, time_taken in pairs(profile_info) do + sorted_times[#sorted_times + 1] = {chunk_name, time_taken} + end + table.sort(sorted_times, function(a, b) return a[2] > b[2] end) + local results = {} + for i, elem in ipairs(sorted_times) do + if not threshold or threshold and elem[2] > threshold then + results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' + end + end + if threshold then + table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') + end + + _G._packer.profile_output = results +end + +time([[Luarocks path setup]], true) +local package_path_str = "/Users/noah/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/noah/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/noah/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/noah/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/Users/noah/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +if not string.find(package.path, package_path_str, 1, true) then + package.path = package.path .. ';' .. package_path_str +end + +if not string.find(package.cpath, install_cpath_pattern, 1, true) then + package.cpath = package.cpath .. ';' .. install_cpath_pattern +end + +time([[Luarocks path setup]], false) +time([[try_loadstring definition]], true) +local function try_loadstring(s, component, name) + local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) + if not success then + vim.schedule(function() + vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) + end) + end + return result +end + +time([[try_loadstring definition]], false) +time([[Defining packer_plugins]], true) +_G.packer_plugins = { + LuaSnip = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/LuaSnip", + url = "https://github.com/L3MON4D3/LuaSnip" + }, + catppuccin = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/catppuccin", + url = "https://github.com/catppuccin/nvim" + }, + ["cmp-buffer"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/cmp-buffer", + url = "https://github.com/hrsh7th/cmp-buffer" + }, + ["cmp-nvim-lsp"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", + url = "https://github.com/hrsh7th/cmp-nvim-lsp" + }, + ["mason-lspconfig.nvim"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", + url = "https://github.com/williamboman/mason-lspconfig.nvim" + }, + ["mason.nvim"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/mason.nvim", + url = "https://github.com/williamboman/mason.nvim" + }, + ["null-ls.nvim"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/null-ls.nvim", + url = "https://github.com/jose-elias-alvarez/null-ls.nvim" + }, + ["nvim-cmp"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/nvim-cmp", + url = "https://github.com/hrsh7th/nvim-cmp" + }, + ["nvim-code-action-menu"] = { + commands = { "CodeActionMenu" }, + loaded = false, + needs_bufread = true, + only_cond = false, + path = "/Users/noah/.local/share/nvim/site/pack/packer/opt/nvim-code-action-menu", + url = "https://github.com/weilbith/nvim-code-action-menu" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + url = "https://github.com/neovim/nvim-lspconfig" + }, + ["nvim-treesitter"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/nvim-treesitter", + url = "https://github.com/nvim-treesitter/nvim-treesitter" + }, + ["nvim-web-devicons"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/nvim-web-devicons", + url = "https://github.com/nvim-tree/nvim-web-devicons" + }, + ["packer.nvim"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/packer.nvim", + url = "https://github.com/wbthomason/packer.nvim" + }, + ["plenary.nvim"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/plenary.nvim", + url = "https://github.com/nvim-lua/plenary.nvim" + }, + ["telescope-file-browser.nvim"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/telescope-file-browser.nvim", + url = "https://github.com/nvim-telescope/telescope-file-browser.nvim" + }, + ["telescope.nvim"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/telescope.nvim", + url = "https://github.com/nvim-telescope/telescope.nvim" + }, + ["uxntal.vim"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/uxntal.vim", + url = "https://github.com/bellinitte/uxntal.vim" + }, + ["vim-prettier"] = { + loaded = true, + path = "/Users/noah/.local/share/nvim/site/pack/packer/start/vim-prettier", + url = "https://github.com/prettier/vim-prettier" + } +} + +time([[Defining packer_plugins]], false) + +-- Command lazy-loads +time([[Defining lazy-load commands]], true) +pcall(vim.api.nvim_create_user_command, 'CodeActionMenu', function(cmdargs) + require('packer.load')({'nvim-code-action-menu'}, { cmd = 'CodeActionMenu', l1 = cmdargs.line1, l2 = cmdargs.line2, bang = cmdargs.bang, args = cmdargs.args, mods = cmdargs.mods }, _G.packer_plugins) + end, + {nargs = '*', range = true, bang = true, complete = function() + require('packer.load')({'nvim-code-action-menu'}, {}, _G.packer_plugins) + return vim.fn.getcompletion('CodeActionMenu ', 'cmdline') + end}) +time([[Defining lazy-load commands]], false) + + +_G._packer.inside_compile = false +if _G._packer.needs_bufread == true then + vim.cmd("doautocmd BufRead") +end +_G._packer.needs_bufread = false + +if should_profile then save_profiles() end + +end) + +if not no_errors then + error_msg = error_msg:gsub('"', '\\"') + vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') +end diff --git a/.config/nvim/plugin/telescope.lua b/.config/nvim/plugin/telescope.lua new file mode 100644 index 0000000..878b668 --- /dev/null +++ b/.config/nvim/plugin/telescope.lua @@ -0,0 +1,9 @@ +local status, telescope = pcall(require, "telescope") +if (not status) then + print("telescope is not installed") + return +end + +telescope.setup({}) + +telescope.load_extension "file_browser" diff --git a/.config/nvim/plugin/treesitter.lua b/.config/nvim/plugin/treesitter.lua new file mode 100644 index 0000000..c83fa68 --- /dev/null +++ b/.config/nvim/plugin/treesitter.lua @@ -0,0 +1,31 @@ +local status, ts = pcall(require, "nvim-treesitter.configs") +if (not status) then return end + +ts.setup { + highlight = { + enable = true, + disable = {}, + }, + indent = { + enable = true, + disable = {}, + }, + ensure_installed = { + "markdown", + "markdown_inline", + "tsx", + "json", + "yaml", + "css", + "scss", + "html", + "lua", + "vim", + }, + autotag = { + enable = true, + }, +} + +local parser_config = require "nvim-treesitter.parsers".get_parser_configs() +parser_config.tsx.filetype_to_parsername = { "javascript", "typescript.tsx" }