Skip to content

Fix the lsp#8

Merged
ronbarrantes merged 3 commits intomainfrom
fixing-lsp
May 25, 2025
Merged

Fix the lsp#8
ronbarrantes merged 3 commits intomainfrom
fixing-lsp

Conversation

@ronbarrantes
Copy link
Owner

@ronbarrantes ronbarrantes commented May 25, 2025

Add a workaround to the lspconfig, fixing the issue causing the lsp servers to not work

Summary by CodeRabbit

  • New Features
    • Added new plugins to enhance LSP support and development experience.
  • Refactor
    • Streamlined and restructured plugin configuration for improved clarity and maintainability.
  • Chores
    • Updated plugin versions and dependencies for better stability and compatibility.
    • Reformatted code and improved inline documentation for consistency.

@coderabbitai
Copy link

coderabbitai bot commented May 25, 2025

Walkthrough

The updates add and configure several new Neovim LSP-related plugins, update existing plugin versions, and refactor the plugin setup logic. Configuration for "mason.nvim" and its dependencies is moved from static option tables to explicit Lua setup functions. Additional plugins are registered, and dependency management is clarified with a new workaround module.

Changes

File(s) Change Summary
lazy-lock.json Added new plugins, updated plugin commit hashes, and registered additional dependencies for LSP functionality.
lua/ronb/lazy.lua Reformatted code and adjusted indentation; no functional or control flow changes.
lua/ronb/plugins/lsp/lspconfig.lua Refactored LSP config: removed explicit dependency options, streamlined server setup, clarified keymaps, and diagnostics.
lua/ronb/plugins/lsp/mason.lua Refactored mason plugin config: moved from static opts to explicit config function with direct setup calls.
lua/ronb/plugins/lsp/mason-workaround.lua Added new module exporting two plugin specs for mason with version constraints.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Neovim
    participant Mason
    participant MasonLspConfig
    participant LspConfig

    User->>Neovim: Start
    Neovim->>Mason: require("mason").setup()
    Neovim->>MasonLspConfig: require("mason-lspconfig").setup()
    Neovim->>LspConfig: require("lspconfig").setup_handlers()
    LspConfig->>Neovim: Register LSP servers (with custom handlers)
Loading

Poem

A bunny hopped through code so neat,
Refactored plugins, dependencies complete.
With mason and friends now freshly aligned,
LSP magic is clearly defined.
New modules sprout, old configs unwind—
In the garden of Neovim, what treasures we find!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
lua/ronb/plugins/lsp/lspconfig.lua (1)

4-8: ⚠️ Potential issue

Add missing mason-lspconfig dependency.

The code requires mason-lspconfig on line 14 but it's not declared in the dependencies list. This could cause runtime errors if the plugin isn't installed.

 dependencies = {
 	"hrsh7th/cmp-nvim-lsp",
 	{ "antosha417/nvim-lsp-file-operations", config = true },
 	{ "folke/lazydev.nvim", opts = {} },
+	"williamboman/mason-lspconfig.nvim",
 },
🧹 Nitpick comments (2)
lua/ronb/lazy.lua (1)

14-14: Track the TODO comment for future refactoring.

The TODO comment indicates that some code should be moved to a different file. Consider creating an issue to track this technical debt.

Would you like me to open a new issue to track this refactoring task?

lua/ronb/plugins/lsp/mason.lua (1)

24-45: Consider enabling some LSP servers or documenting the commented configuration.

The ensure_installed list is entirely commented out, which means no LSP servers will be automatically installed. While automatic_installation = true will install servers when they're used, you might want to uncomment some essential servers for a better out-of-the-box experience.

Consider uncommenting commonly used servers:

 			ensure_installed = {
-				-- "tsserver",
-				-- "html",
-				-- "jsonls",
-				-- "cssls",
-				-- "gopls",
-				-- "pyright",
+				"tsserver",
+				"html", 
+				"jsonls",
+				"cssls",
+				"gopls",
+				"pyright",
 				-- "htmx",
 				-- "autotools_ls",
 				-- "tailwindcss",
 				-- "asm_lsp",
 				-- "golangci_lint_ls",
 				-- "graphql",
 				-- "emmet_ls",
 				-- "marksman",
 				-- "sqlls",
 				-- "prismals",
 			},

Alternatively, document why all servers are commented out if this is intentional.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a70fd4d and d88a5d4.

📒 Files selected for processing (5)
  • lazy-lock.json (2 hunks)
  • lua/ronb/lazy.lua (2 hunks)
  • lua/ronb/plugins/lsp/lspconfig.lua (1 hunks)
  • lua/ronb/plugins/lsp/mason-workaround.lua (1 hunks)
  • lua/ronb/plugins/lsp/mason.lua (1 hunks)
🔇 Additional comments (12)
lua/ronb/lazy.lua (2)

3-10: LGTM! Formatting improvements enhance readability.

The indentation adjustments to the git clone command array improve code consistency.


26-38: LGTM! Consistent formatting applied.

The indentation changes to the lazy.setup configuration maintain consistency with the rest of the file.

lua/ronb/plugins/lsp/lspconfig.lua (3)

10-19: LGTM! Improved code documentation.

The added comments clearly explain each import, improving code readability.


77-82: LGTM! Cleaner diagnostic signs configuration.

Using vim.fn.sign_define directly is more explicit than configuring through vim.diagnostic.config.


129-145: LGTM! Simplified lua_ls configuration.

The removal of workspace library and telemetry settings simplifies the configuration while maintaining essential functionality.

lua/ronb/plugins/lsp/mason.lua (3)

3-5: LGTM! Dependencies section correctly simplified.

The refactoring from nested dependency options to a simple string reference is clean and follows the new explicit configuration pattern.


6-23: LGTM! Mason setup is correctly configured.

The explicit mason.setup() call with UI icons configuration is properly implemented and preserves the previous functionality.


6-46:

Details

❓ Verification inconclusive

Verify the configuration refactoring works correctly.

The refactoring from declarative opts to explicit config function calls looks correct, but please ensure this change resolves the LSP issues mentioned in the PR objectives.

Let me verify that both mason modules are properly available:


🏁 Script executed:

#!/bin/bash
# Description: Verify mason modules are correctly referenced and available.

# Search for mason module usage patterns in the codebase
rg -A 3 -B 1 'require.*mason'

# Check if there are any other mason configuration files that might conflict
fd -e lua -x grep -l "mason" {} \;

Length of output: 999


Verify duplicate mason plugin specs and confirm configuration

  • The search output shows both lua/ronb/plugins/lsp/mason.lua and lua/ronb/plugins/lsp/mason-workaround.lua reference the mason.nvim plugin. Please ensure only one plugin spec for mason.nvim is loaded to avoid conflicting setups.
  • If the workaround file is no longer needed after refactoring to the explicit config function, remove or merge its logic into mason.lua.
  • Confirm that your mason.setup({…}) and mason_lspconfig.setup({…}) calls in mason.lua actually resolve the LSP issues outlined in the PR objectives.
  • In Neovim, run :Mason to verify the UI icons and :LspInstall to ensure automatic installation behaves as expected.
lazy-lock.json (4)

6-6: LGTM! LSP completion plugin correctly added.

The addition of cmp-nvim-lsp enhances LSP completion integration, which aligns with fixing LSP functionality.


15-15: LGTM! New LSP development plugins added.

The addition of lazydev.nvim, neodev.nvim, and nvim-lsp-file-operations expands the LSP ecosystem with useful development tools:

  • lazydev.nvim: Enhanced Lua development support
  • neodev.nvim: Neovim API development assistance
  • nvim-lsp-file-operations: File operation integration with LSP

These additions support a more comprehensive LSP setup.

Also applies to: 24-24, 27-27


18-19: LGTM! Mason and LSP config plugins updated to newer versions.

The commit updates for mason-lspconfig.nvim, mason.nvim, and nvim-lspconfig are consistent with the configuration refactoring in mason.lua and should help resolve the LSP issues mentioned in the PR.

Also applies to: 28-28


1-47:

Details

✅ Verification successful

Verify plugin compatibility and potential breaking changes.

While the plugin updates look good, please ensure the newer versions are compatible with the current configuration and don't introduce breaking changes.


🏁 Script executed:

#!/bin/bash
# Description: Check for any potential compatibility issues or breaking changes in updated plugins.

# Check if there are any configuration files that might need updates due to plugin changes
rg -l "mason-lspconfig\|nvim-lspconfig\|lazydev\|neodev" --type lua

# Look for any deprecated configuration patterns
rg -A 5 -B 5 "opts.*mason|config.*mason" --type lua

Length of output: 1393


No immediate breaking changes detected in plugin configurations

I ran searches across your Lua configs (mason.lua and lspconfig.lua) for any deprecated or changed API patterns related to the updated plugins (mason-lspconfig, nvim-lspconfig, lazydev, neodev) and found none. Both files import and call the plugins’ setup functions as before, and there are no lingering opts.*mason or outdated config.*mason patterns.

Unless upstream commits introduce undocumented breaking changes (in which case you’d see errors at runtime), your current configuration should remain compatible.

Comment on lines +1 to +4
return {
{ "mason-org/mason.nvim", version = "^1.0.0" },
{ "mason-org/mason-lspconfig.nvim", version = "^1.0.0" },
}
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.

Comment on lines +98 to +100
callback = function(ctx)
-- Here use ctx.match instead of ctx.file
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
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.

@ronbarrantes ronbarrantes merged commit d2e5a53 into main May 25, 2025
1 check passed
@ronbarrantes ronbarrantes deleted the fixing-lsp branch May 25, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant