This commit is contained in:
Belal Elsabbagh
2025-05-19 10:28:59 +03:00
parent 4a30f4e705
commit 12fc965843
7 changed files with 308 additions and 8 deletions

View File

@@ -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', '<Esc>', '<cmd>nohlsearch<CR>')
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
@@ -142,6 +144,7 @@ vim.lsp.enable {
'luals',
'pyright',
'ruff',
'sveltels',
'rust-analyzer',
'tsls',
'yamlls',

View File

@@ -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,
}

View File

@@ -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
```
]],
},
}

View File

@@ -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,
}

View File

@@ -2,7 +2,6 @@ return {
'exafunction/codeium.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
'hrsh7th/nvim-cmp',
},
config = function()
require('codeium').setup {