Skip to content

feat(lsp): Language Server Protocol (LSP) #11187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 54 commits into
base: master
Choose a base branch
from
Draft

Conversation

mmsaki
Copy link

@mmsaki mmsaki commented Aug 1, 2025

Motivation

This PR introduces native Language Server Protocol (LSP) support to Foundry via a new forge lsp command.

The motivation behind this is to provide a first-class developer experience for Solidity projects using Foundry by exposing core compiler features (like linting, syntax errors, remappings, etc.) directly to LSP-compatible editors such as Neovim and VSCode.

Previously, users had to rely on external plugins or custom tooling to get real-time feedback while editing Solidity code. This native integration unlocks accurate diagnostics, contextual tooling, and seamless integration with Forge projects out of the box.

Solution

This PR adds:

  • A new command: forge lsp
  • A tokio-based LSP server implementation using tower-lsp
  • The server is implemented in crates/lsp, and registered as a new Forge subcommand.
  • Designed for extensibility: future support for hover, and code actions is planned.
  • Initial support for forge lint notification via "textDocument/publishDiagnostics" requests with streaming updates

PR Checklist

  • Added Tests
  • Added Documentation

Done

  • forge build errors & warnigns
  • forge lint diagnostics
  • textDocument/definition
  • textDocument/declaration

Planned

  • textDocument/rename
  • textDocument/formatting
  • Hover information
  • Symbol search and references
  • Code completion
  • Code Actions

@0xClandestine
Copy link
Contributor

0xClandestine commented Aug 3, 2025

Thanks for carrying the torch on this, I have wanted a solid LSP for what feels like ages. The fact that forge lint is built-in is the cherry on top, well done brother.

@mmsaki
Copy link
Author

mmsaki commented Aug 3, 2025

Thanks for carrying the torch on this, I have wanted a solid LSP for what feels like ages. The fact that forge lint built-in is the cherry on top, well done brother.

It's so underrated. Already used the LSP to remove 84 unused imports in uniswap v4-core 👀 see PR Uniswap/v4-core#979, refactoring 45 files really easy with the LSP even without all the other features.

@0xClandestine Thanks for your work on forge lint too.

@0xClandestine
Copy link
Contributor

@mmsaki Lol, I had a similar PR the other day forge lint is putting in work.

This actually solves one of my main frustrations when running forge lint on larger repos, the output is super noisy without filtering. With forge lsp you can simply navigate to your desired file and hover over concerning highlights.

Anyways, I was able to get it to work with vscode (and cursor) using the following extension and config if others are interested in trying it out:

[
  {
    "languageId": "solidity",
    "command": "forge",
    "fileExtensions": [
      ".sol"
    ],
    "args": [
      "lsp"
    ]
  }
]
image

@mmsaki
Copy link
Author

mmsaki commented Aug 4, 2025

@0xClandestine Thanks for testing it on vscode! Looks amazing 🙌.

mmsaki added 19 commits August 10, 2025 14:44
Both textDocument/definition and textDocument/declaration requests now:
- Return proper Location objects with accurate URIs and ranges
- Handle edge cases gracefully
- Provide diagnostic logging to client
- Use the same underlying symbol resolution logic
- Works for varible declarations
- Works for function definitions
- Works for struct members
- Works for library using for directives referenced declarations
@mmsaki mmsaki changed the title Language Server Protocol (LSP) feat(lsp): Language Server Protocol (LSP) Aug 11, 2025
@mmsaki mmsaki marked this pull request as ready for review August 11, 2025 15:14
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Hi, thanks for your contribution. We would like to hold off on this for the moment as we have plans of implementing it upstream in solar. In this current state it won't work well for large projects, but we will certainly integrate parts of this PR upstream.

@mmsaki
Copy link
Author

mmsaki commented Aug 12, 2025

Happy to see this getting pick up upstream! LFG 🙌

@mmsaki mmsaki marked this pull request as draft August 12, 2025 02:07
@jenpaff jenpaff added this to the v1.4.0 milestone Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

7 participants