-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: master
Are you sure you want to change the base?
Conversation
- Add linting by running forge lint --json on current file buffer on save and on file open
- Adds `--stdio` arg to forge lsp
Thanks for carrying the torch on this, I have wanted a solid LSP for what feels like ages. The fact that |
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. |
@mmsaki Lol, I had a similar PR the other day This actually solves one of my main frustrations when running 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"
]
}
] ![]() |
@0xClandestine Thanks for testing it on vscode! Looks amazing 🙌. |
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
lsp
): Language Server Protocol (LSP)
There was a problem hiding this 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.
Happy to see this getting pick up upstream! LFG 🙌 |
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:
forge lsp
tokio
-based LSP server implementation using tower-lspcrates/lsp
, and registered as a new Forge subcommand.hover
, andcode actions
is planned.forge lint
notification via "textDocument/publishDiagnostics" requests with streaming updatesPR Checklist
Done
Planned