Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"auto-session": { "branch": "main", "commit": "00334ee24b9a05001ad50221c8daffbeedaa0842" },
"bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" },
"cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" },
"cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" },
"cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" },
"cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" },
"conform.nvim": { "branch": "master", "commit": "6feb2f28f9a9385e401857b21eeac3c1b66dd628" },
Expand All @@ -11,17 +12,20 @@
"gitsigns.nvim": { "branch": "main", "commit": "8b729e489f1475615dc6c9737da917b3bc163605" },
"harpoon": { "branch": "master", "commit": "1bc17e3e42ea3c46b33c0bbad6a880792692a1b3" },
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
"lazydev.nvim": { "branch": "main", "commit": "2367a6c0a01eb9edb0464731cc0fb61ed9ab9d2c" },
"lspkind.nvim": { "branch": "master", "commit": "d79a1c3299ad0ef94e255d045bed9fa26025dab6" },
"lualine.nvim": { "branch": "master", "commit": "0c6cca9f2c63dadeb9225c45bc92bb95a151d4af" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "d24b3f1612e53f9d54d866b16bedab51813f2bf1" },
"mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" },
"mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" },
"mini.ai": { "branch": "main", "commit": "b91997d220086e92edc1fec5ce82094dcc234291" },
"mini.indentscope": { "branch": "main", "commit": "8af2569a7d7fd37300dfa760e44e71efbbf322fd" },
"mini.pairs": { "branch": "main", "commit": "69864a2efb36c030877421634487fd90db1e4298" },
"mini.surround": { "branch": "main", "commit": "5aab42fcdcf31fa010f012771eda5631c077840a" },
"neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" },
"nvim-autopairs": { "branch": "master", "commit": "4d74e75913832866aa7de35e4202463ddf6efd1b" },
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },
"nvim-lspconfig": { "branch": "master", "commit": "562487bc108bf73c2493f9e701b9334b48163216" },
"nvim-lsp-file-operations": { "branch": "master", "commit": "9744b738183a5adca0f916527922078a965515ed" },
"nvim-lspconfig": { "branch": "master", "commit": "3ea99227e316c5028f57a4d86a1a7fd01dd876d0" },
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
"nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" },
"ollama.nvim": { "branch": "main", "commit": "45e58779fecde7ac5b8f62800bbe7180d4b48507" },
Expand Down
44 changes: 21 additions & 23 deletions lua/ronb/lazy.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)

-- -- TODO: move this to a different file
-- TODO: move this to a different file

-- -- Enable mouse support
-- vim.o.mouse = "a"
Expand All @@ -22,20 +22,18 @@ vim.opt.rtp:prepend(lazypath)
-- command = "set mouse=a",
-- })



require("lazy").setup({
spec = {
{ import = "ronb.plugins" },
{ import = "ronb.plugins.lsp" },
},
spec = {
{ import = "ronb.plugins" },
{ import = "ronb.plugins.lsp" },
},
}, {
checker = {
enabled = true,
notify = false,
},
change_detection = {
notify = false,
},
version = false,
checker = {
enabled = true,
notify = false,
},
change_detection = {
notify = false,
},
version = false,
})
215 changes: 95 additions & 120 deletions lua/ronb/plugins/lsp/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,169 +5,144 @@ return {
"hrsh7th/cmp-nvim-lsp",
{ "antosha417/nvim-lsp-file-operations", config = true },
{ "folke/lazydev.nvim", opts = {} },
{
"williamboman/mason.nvim",
opts = {
ui = {
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "✗",
},
},
},
},
{
"williamboman/mason-lspconfig.nvim",
opts = {
ensure_installed = {
-- Add your desired LSP servers here, e.g. "lua_ls", "svelte", etc.
},
automatic_installation = true,
dependencies = {
{ "mason-org/mason.nvim", opts = {} },
"neovim/nvim-lspconfig",
},
},
},
},

config = function()
-- import lspconfig plugin
local lspconfig = require("lspconfig")

-- import mason_lspconfig plugin
local mason_lspconfig = require("mason-lspconfig")

-- import cmp-nvim-lsp plugin
local cmp_nvim_lsp = require("cmp_nvim_lsp")

-- LSP keymaps (buffer-local)
local keymap = vim.keymap -- for conciseness

vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
local keymap = vim.keymap
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf, silent = true }

-- set keybinds
opts.desc = "Show LSP references"
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts)
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts) -- show definition, references

opts.desc = "Go to declaration"
keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration

opts.desc = "Show LSP definitions"
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts) -- show lsp definitions

opts.desc = "Show LSP implementations"
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts) -- show lsp implementations

opts.desc = "Show LSP type definitions"
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts) -- show lsp type definitions

opts.desc = "See available code actions"
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection

-- CopilotChat
keymap.set({ "n", "v" }, "<leader>cc", vim.cmd.CopilotChatToggle, { desc = "CopilotChat" })

opts.desc = "Smart rename"
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename

opts.desc = "Show buffer diagnostics"
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts)
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file

opts.desc = "Show line diagnostics"
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line

opts.desc = "Go to previous diagnostic"
keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer

opts.desc = "Go to next diagnostic"
keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer

opts.desc = "Show documentation for what is under cursor"
keymap.set("n", "K", vim.lsp.buf.hover, opts)
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor

opts.desc = "Restart LSP"
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts)
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
end,
})

-- Autocompletion capabilities
-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()

-- Diagnostic signs (Neovim 0.11+ style)
vim.diagnostic.config({
signs = {
text = {
[vim.diagnostic.severity.ERROR] = " ",
[vim.diagnostic.severity.WARN] = " ",
[vim.diagnostic.severity.HINT] = "󰠠 ",
[vim.diagnostic.severity.INFO] = " ",
},
},
-- Change the Diagnostic symbols in the sign column (gutter)
-- (not in youtube nvim video)
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

mason_lspconfig.setup_handlers({
-- default handler for installed servers
function(server_name)
lspconfig[server_name].setup({
capabilities = capabilities,
})
end,
["svelte"] = function()
-- configure svelte server
lspconfig["svelte"].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.js", "*.ts" },
callback = function(ctx)
-- Here use ctx.match instead of ctx.file
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
Comment on lines +98 to +100
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the change from ctx.file to ctx.match.

The svelte server configuration now uses ctx.match instead of ctx.file. Ensure this is the correct field for the file URI in the autocmd callback context.


🏁 Script executed:

#!/bin/bash
# Description: Check Neovim documentation and similar usage patterns for autocmd context fields

# Search for other uses of BufWritePost autocmd callbacks to see the pattern
rg -A 5 -B 5 'BufWritePost.*callback.*ctx\.(file|match)' --type lua

# Search for notify with uri parameter patterns
ast-grep --pattern 'client.notify($_, { uri = $_ })'

Length of output: 233


🌐 Web query:

In Neovim Lua nvim_create_autocmd callback context, what are ctx.file and ctx.match?

💡 Result:

When working with Neovim's Lua API for creating autocommands, the callback function receives a context table with several important fields. The ctx.file and ctx.match properties provide valuable information about the event that triggered the autocommand.

Autocommand Callback Context

In Neovim's nvim_create_autocmd API, the callback function receives a context table (often referred to as args in examples) containing several properties:

ctx.file represents the file name of the buffer in which the autocommand event was triggered[6]. This corresponds to what you would access with <afile> in Vimscript autocommands. It provides the full path to the file that triggered the event.

ctx.match contains the string that matched the pattern specified in your autocommand[6]. This corresponds to <amatch> in Vimscript. The value of ctx.match depends on the specific event type:

  • For buffer-related events, it typically contains the buffer name
  • For FileType events, it contains the filetype that was set[5]
  • For other events, it contains whatever matched against your specified pattern

Example Usage

Here's how you might use these properties in practice:

vim.api.nvim_create_autocmd("FileType", {
  pattern = "lua",
  callback = function(args)
    -- args.match would contain "lua" here
    -- args.file would contain the file path
    print("FileType set to: " .. args.match)
    print("File path: " .. args.file)
    
    -- Set buffer-local mapping
    vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf })
  end
})

The callback receives other useful properties as well:

  • ctx.buf: the buffer number where the event was triggered[6]
  • ctx.data: a table with event-specific data that's passed for some events[6]

This context information allows you to create highly customized autocommands that respond intelligently to different conditions and file types in your Neovim configuration.

Citations:


Use ctx.file for the file URI

The ctx.match field maps to <amatch> (the autocommand pattern), not the actual filename. To send the correct URI in your Svelte LSP notification, switch back to ctx.file (<afile>).

  • File: lua/ronb/plugins/lsp/lspconfig.lua
    Lines: 98–100
    Change:
     callback = function(ctx)
       -- Here use ctx.match instead of ctx.file
  • client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
  • client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.file })
    end



<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion
callback = function(ctx)
  -- Here use ctx.file instead of ctx.match
  client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.file })
🤖 Prompt for AI Agents
In lua/ronb/plugins/lsp/lspconfig.lua around lines 98 to 100, the callback uses
ctx.match for the file URI, but ctx.match corresponds to the autocommand pattern
match, not the actual file path. To fix this, revert to using ctx.file which
holds the correct file URI for the notification. Replace ctx.match with ctx.file
in the client.notify call.

end,
})
end,
})
end,
["graphql"] = function()
-- configure graphql language server
lspconfig["graphql"].setup({
capabilities = capabilities,
filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" },
})
end,
["emmet_ls"] = function()
-- configure emmet language server
lspconfig["emmet_ls"].setup({
capabilities = capabilities,
filetypes = {
"html",
"typescriptreact",
"javascriptreact",
"css",
"sass",
"scss",
"less",
"svelte",
},
})
end,
["lua_ls"] = function()
-- configure lua server (with special settings)
lspconfig["lua_ls"].setup({
capabilities = capabilities,
settings = {
Lua = {
-- make the language server recognize "vim" global
diagnostics = {
globals = { "vim" },
},
completion = {
callSnippet = "Replace",
},
},
},
})
end,
})

-- Setup handlers for LSP servers (requires mason-lspconfig >=2.0.0)
-- mason_lspconfig.setup_handlers({
-- -- Default handler for all installed servers
-- function(server_name)
-- lspconfig[server_name].setup({
-- capabilities = capabilities,
-- })
-- end,
-- -- Custom handler for svelte
-- ["svelte"] = function()
-- lspconfig.svelte.setup({
-- capabilities = capabilities,
-- on_attach = function(client, bufnr)
-- vim.api.nvim_create_autocmd("BufWritePost", {
-- pattern = { "*.js", "*.ts" },
-- callback = function(ctx)
-- client:notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
-- end,
-- })
-- end,
-- })
-- end,
-- -- Custom handler for graphql
-- ["graphql"] = function()
-- lspconfig.graphql.setup({
-- capabilities = capabilities,
-- filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" },
-- })
-- end,
-- -- Custom handler for emmet_ls
-- ["emmet_ls"] = function()
-- lspconfig.emmet_ls.setup({
-- capabilities = capabilities,
-- filetypes = {
-- "html",
-- "typescriptreact",
-- "javascriptreact",
-- "css",
-- "sass",
-- "scss",
-- "less",
-- "svelte",
-- },
-- })
-- end,
-- -- Custom handler for lua_ls
-- ["lua_ls"] = function()
-- lspconfig.lua_ls.setup({
-- capabilities = capabilities,
-- settings = {
-- Lua = {
-- diagnostics = {
-- globals = { "vim" },
-- },
-- completion = {
-- callSnippet = "Replace",
-- },
-- workspace = {
-- library = vim.api.nvim_get_runtime_file("", true),
-- checkThirdParty = false,
-- },
-- telemetry = { enable = false },
-- },
-- },
-- })
-- end,
-- })
end,
}
4 changes: 4 additions & 0 deletions lua/ronb/plugins/lsp/mason-workaround.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
return {
{ "mason-org/mason.nvim", version = "^1.0.0" },
{ "mason-org/mason-lspconfig.nvim", version = "^1.0.0" },
}
Comment on lines +1 to +4
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Document the purpose of this workaround.

This file introduces a workaround but lacks documentation explaining:

  • What issue is being worked around
  • Why version constraints are needed
  • When this workaround can be removed

Consider adding a comment block at the top of the file explaining the context.

+-- TODO: This is a temporary workaround for [describe issue here]
+-- Can be removed when [describe condition here]
 return {
 	{ "mason-org/mason.nvim", version = "^1.0.0" },
 	{ "mason-org/mason-lspconfig.nvim", version = "^1.0.0" },
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return {
{ "mason-org/mason.nvim", version = "^1.0.0" },
{ "mason-org/mason-lspconfig.nvim", version = "^1.0.0" },
}
-- TODO: This is a temporary workaround for [describe issue here]
-- Can be removed when [describe condition here]
return {
{ "mason-org/mason.nvim", version = "^1.0.0" },
{ "mason-org/mason-lspconfig.nvim", version = "^1.0.0" },
}
🤖 Prompt for AI Agents
In lua/ronb/plugins/lsp/mason-workaround.lua at lines 1 to 4, add a comment
block at the top of the file explaining the purpose of this workaround. Document
what specific issue this workaround addresses, why the version constraints are
necessary, and under what conditions or future updates this workaround can be
removed. This will provide clarity and context for future maintainers.

Loading