From 12fc965843d9042eeb15990bfd6e3ecaae96da63 Mon Sep 17 00:00:00 2001 From: Belal Elsabbagh Date: Mon, 19 May 2025 10:28:59 +0300 Subject: [PATCH] stuff --- .config/btop/btop.conf | 4 +- .config/nvim/init.lua | 9 +- .config/nvim/lsp/rust-analyzer.lua | 117 +++++++++++++++++++++++- .config/nvim/lsp/sveltels.lua | 38 ++++++++ .config/nvim/lsp/tsls.lua | 132 ++++++++++++++++++++++++++- .config/nvim/lua/plugins/codeium.lua | 1 - .config/tmux/tmux.conf | 15 +++ 7 files changed, 308 insertions(+), 8 deletions(-) create mode 100644 .config/nvim/lsp/sveltels.lua diff --git a/.config/btop/btop.conf b/.config/btop/btop.conf index 93fef25..a0c6c97 100644 --- a/.config/btop/btop.conf +++ b/.config/btop/btop.conf @@ -1,4 +1,4 @@ -#? Config file for btop v. 1.4.2 +#? Config file for btop v. 1.4.3 #* Name of a btop++/bpytop/bashtop formatted ".theme" file, "Default" and "TTY" for builtin themes. #* Themes should be placed in "../share/btop/themes" relative to binary or "$HOME/.config/btop/themes" @@ -63,7 +63,7 @@ proc_sorting = "memory" proc_reversed = False #* Show processes as a tree. -proc_tree = False +proc_tree = True #* Use the cpu graph colors in the process list. proc_colors = True diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index ad940c2..8517173 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -2,11 +2,9 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' vim.g.have_nerd_font = true vim.opt.number = true +vim.opt.relativenumber = true -- vim.opt.mouse = 'a' vim.opt.showmode = false -vim.schedule(function() - vim.opt.clipboard = 'unnamedplus' -end) vim.opt.breakindent = true vim.opt.undofile = true vim.opt.ignorecase = true @@ -23,6 +21,10 @@ vim.opt.cursorline = true vim.opt.scrolloff = 10 -- vim.opt.textwidth = 80 +vim.schedule(function() + vim.opt.clipboard = 'unnamedplus' +end) + vim.keymap.set('n', '', 'nohlsearch') vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) @@ -142,6 +144,7 @@ vim.lsp.enable { 'luals', 'pyright', 'ruff', + 'sveltels', 'rust-analyzer', 'tsls', 'yamlls', diff --git a/.config/nvim/lsp/rust-analyzer.lua b/.config/nvim/lsp/rust-analyzer.lua index a564707..fde5a3a 100644 --- a/.config/nvim/lsp/rust-analyzer.lua +++ b/.config/nvim/lsp/rust-analyzer.lua @@ -1 +1,116 @@ -return {} +---@brief +--- +--- https://github.com/rust-lang/rust-analyzer +--- +--- rust-analyzer (aka rls 2.0), a language server for Rust +--- +--- +--- See [docs](https://rust-analyzer.github.io/book/configuration.html) for extra settings. The settings can be used like this: +--- ```lua +--- vim.lsp.config('rust_analyzer', { +--- settings = { +--- ['rust-analyzer'] = { +--- diagnostics = { +--- enable = false; +--- } +--- } +--- } +--- }) +--- ``` +--- +--- Note: do not set `init_options` for this LS config, it will be automatically populated by the contents of settings["rust-analyzer"] per +--- https://github.com/rust-lang/rust-analyzer/blob/eb5da56d839ae0a9e9f50774fa3eb78eb0964550/docs/dev/lsp-extensions.md?plain=1#L26. + +local function reload_workspace(bufnr) + local clients = vim.lsp.get_clients { bufnr = bufnr, name = 'rust_analyzer' } + for _, client in ipairs(clients) do + vim.notify 'Reloading Cargo Workspace' + client.request('rust-analyzer/reloadWorkspace', nil, function(err) + if err then + error(tostring(err)) + end + vim.notify 'Cargo workspace reloaded' + end, 0) + end +end + +local function is_library(fname) + local user_home = vim.fs.normalize(vim.env.HOME) + local cargo_home = os.getenv 'CARGO_HOME' or user_home .. '/.cargo' + local registry = cargo_home .. '/registry/src' + local git_registry = cargo_home .. '/git/checkouts' + + local rustup_home = os.getenv 'RUSTUP_HOME' or user_home .. '/.rustup' + local toolchains = rustup_home .. '/toolchains' + + for _, item in ipairs { toolchains, registry, git_registry } do + if vim.fs.relpath(item, fname) then + local clients = vim.lsp.get_clients { name = 'rust_analyzer' } + return #clients > 0 and clients[#clients].config.root_dir or nil + end + end +end + +return { + cmd = { 'rust-analyzer' }, + filetypes = { 'rust' }, + root_dir = function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + local reused_dir = is_library(fname) + if reused_dir then + on_dir(reused_dir) + return + end + + local cargo_crate_dir = vim.fs.root(fname, { 'Cargo.toml' }) + local cargo_workspace_root + + if cargo_crate_dir == nil then + on_dir(vim.fs.root(fname, { 'rust-project.json' }) or vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])) + return + end + + local cmd = { + 'cargo', + 'metadata', + '--no-deps', + '--format-version', + '1', + '--manifest-path', + cargo_crate_dir .. '/Cargo.toml', + } + + vim.system(cmd, { text = true }, function(output) + if output.code == 0 then + if output.stdout then + local result = vim.json.decode(output.stdout) + if result['workspace_root'] then + cargo_workspace_root = vim.fs.normalize(result['workspace_root']) + end + end + + on_dir(cargo_workspace_root or cargo_crate_dir) + else + vim.schedule(function() + vim.notify(('[rust_analyzer] cmd failed with code %d: %s\n%s'):format(output.code, cmd, output.stderr)) + end) + end + end) + end, + capabilities = { + experimental = { + serverStatusNotification = true, + }, + }, + before_init = function(init_params, config) + -- See https://github.com/rust-lang/rust-analyzer/blob/eb5da56d839ae0a9e9f50774fa3eb78eb0964550/docs/dev/lsp-extensions.md?plain=1#L26 + if config.settings and config.settings['rust-analyzer'] then + init_params.initializationOptions = config.settings['rust-analyzer'] + end + end, + on_attach = function() + vim.api.nvim_buf_create_user_command(0, 'LspCargoReload', function() + reload_workspace(0) + end, { desc = 'Reload current cargo workspace' }) + end, +} diff --git a/.config/nvim/lsp/sveltels.lua b/.config/nvim/lsp/sveltels.lua new file mode 100644 index 0000000..2a9b452 --- /dev/null +++ b/.config/nvim/lsp/sveltels.lua @@ -0,0 +1,38 @@ +local function migrate_to_svelte_5() + local clients = vim.lsp.get_clients { + bufnr = 0, + name = 'svelte', + } + for _, client in ipairs(clients) do + client:exec_cmd { + command = 'migrate_to_svelte_5', + arguments = { vim.uri_from_bufnr(0) }, + } + end +end + +return { + default_config = { + cmd = { 'svelteserver', '--stdio' }, + filetypes = { 'svelte' }, + root_dir = { 'node_modules', '.git', 'package.json' }, + }, + commands = { + MigrateToSvelte5 = { + migrate_to_svelte_5, + description = 'Migrate Component to Svelte 5 Syntax', + }, + }, + docs = { + description = [[ +https://github.com/sveltejs/language-tools/tree/master/packages/language-server + +Note: assuming that [ts_ls](#ts_ls) is setup, full JavaScript/TypeScript support (find references, rename, etc of symbols in Svelte files when working in JS/TS files) requires per-project installation and configuration of [typescript-svelte-plugin](https://github.com/sveltejs/language-tools/tree/master/packages/typescript-plugin#usage). + +`svelte-language-server` can be installed via `npm`: +```sh +npm install -g svelte-language-server +``` +]], + }, +} diff --git a/.config/nvim/lsp/tsls.lua b/.config/nvim/lsp/tsls.lua index a564707..fb42205 100644 --- a/.config/nvim/lsp/tsls.lua +++ b/.config/nvim/lsp/tsls.lua @@ -1 +1,131 @@ -return {} +---@brief +--- +--- https://github.com/typescript-language-server/typescript-language-server +--- +--- `ts_ls`, aka `typescript-language-server`, is a Language Server Protocol implementation for TypeScript wrapping `tsserver`. Note that `ts_ls` is not `tsserver`. +--- +--- `typescript-language-server` depends on `typescript`. Both packages can be installed via `npm`: +--- ```sh +--- npm install -g typescript typescript-language-server +--- ``` +--- +--- To configure typescript language server, add a +--- [`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) or +--- [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) to the root of your +--- project. +--- +--- Here's an example that disables type checking in JavaScript files. +--- +--- ```json +--- { +--- "compilerOptions": { +--- "module": "commonjs", +--- "target": "es6", +--- "checkJs": false +--- }, +--- "exclude": [ +--- "node_modules" +--- ] +--- } +--- ``` +--- +--- Use the `:LspTypescriptSourceAction` command to see "whole file" ("source") code-actions such as: +--- - organize imports +--- - remove unused code +--- +--- ### Vue support +--- +--- As of 2.0.0, Volar no longer supports TypeScript itself. Instead, a plugin +--- adds Vue support to this language server. +--- +--- *IMPORTANT*: It is crucial to ensure that `@vue/typescript-plugin` and `volar `are of identical versions. +--- +--- ```lua +--- vim.lsp.config('ts_ls', { +--- init_options = { +--- plugins = { +--- { +--- name = "@vue/typescript-plugin", +--- location = "/usr/local/lib/node_modules/@vue/typescript-plugin", +--- languages = {"javascript", "typescript", "vue"}, +--- }, +--- }, +--- }, +--- filetypes = { +--- "javascript", +--- "typescript", +--- "vue", +--- }, +--- }) +--- +--- -- You must make sure volar is setup +--- -- e.g. vim.lsp.config('volar') +--- -- See volar's section for more information +--- ``` +--- +--- `location` MUST be defined. If the plugin is installed in `node_modules`, +--- `location` can have any value. +--- +--- `languages` must include `vue` even if it is listed in `filetypes`. +--- +--- `filetypes` is extended here to include Vue SFC. + +return { + init_options = { + hostInfo = 'neovim', + init_options = { + plugins = { + { + name = '@vue/typescript-plugin', + location = '/usr/local/lib/node_modules/@vue/typescript-plugin', + languages = { 'javascript', 'typescript', 'vue' }, + }, + }, + }, + filetypes = { + 'javascript', + 'typescript', + 'vue', + }, + }, + cmd = { 'typescript-language-server', '--stdio' }, + filetypes = { + 'javascript', + 'javascriptreact', + 'javascript.jsx', + 'typescript', + 'typescriptreact', + 'typescript.tsx', + }, + root_markers = { 'tsconfig.json', 'jsconfig.json', 'package.json', '.git' }, + handlers = { + -- handle rename request for certain code actions like extracting functions / types + ['_typescript.rename'] = function(_, result, ctx) + local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) + vim.lsp.util.show_document({ + uri = result.textDocument.uri, + range = { + start = result.position, + ['end'] = result.position, + }, + }, client.offset_encoding) + vim.lsp.buf.rename() + return vim.NIL + end, + }, + on_attach = function(client) + -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in + -- `vim.lsp.buf.code_action()` if specified in `context.only`. + vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function() + local source_actions = vim.tbl_filter(function(action) + return vim.startswith(action, 'source.') + end, client.server_capabilities.codeActionProvider.codeActionKinds) + + vim.lsp.buf.code_action { + context = { + only = source_actions, + }, + } + end, {}) + end, +} diff --git a/.config/nvim/lua/plugins/codeium.lua b/.config/nvim/lua/plugins/codeium.lua index 6d039c7..f688ecd 100644 --- a/.config/nvim/lua/plugins/codeium.lua +++ b/.config/nvim/lua/plugins/codeium.lua @@ -2,7 +2,6 @@ return { 'exafunction/codeium.nvim', dependencies = { 'nvim-lua/plenary.nvim', - 'hrsh7th/nvim-cmp', }, config = function() require('codeium').setup { diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index 6e1d085..fe37547 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -42,6 +42,21 @@ set -g @tpm_plugins ' tmux-plugins/tmux-yank ' +set -g @dracula-colors " +# Dracula Color Pallette +white='#f8f8f2' +gray='#44475a' +dark_gray='#282a36' +light_purple='#bd93f9' +dark_purple='#6272a4' +cyan='#8be9fd' +green='#50fa7b' +orange='#ffb86c' +red='#ff5555' +pink='#ff79c6' +yellow='#f1fa8c' +" + # available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, tmux-ram-usage, network, network-bandwidth, network-ping, ssh-session, attached-clients, network-vpn, weather, time, mpc, spotify-tui, playerctl, kubernetes-context, synchronize-panes set -g @dracula-plugins "network-bandwidth ram-usage time battery" set -g @dracula-show-left-icon "#[bold]#S"