-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 🙌. |
pub struct LspArgs { | ||
/// See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#implementationConsiderations | ||
#[arg(long)] | ||
pub stdio: bool, |
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.
this does nothing? I think stdin/stdout should be the default
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.
it doesn’t do anything at the moment 🤔 spec recommended to use the —stdio flag just to be explicit which transport method we use but maybe we don’t need to do it after all. I think we can remove it.
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.
Ah I see, this is fine then
crates/lsp/src/lsp.rs
Outdated
Ok(InitializeResult { | ||
server_info: Some(ServerInfo { | ||
name: "forge lsp".to_string(), | ||
version: Some(env!("CARGO_PKG_VERSION").to_string()), |
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.
we can use SHORT_VERSION from foundry_common
checkout https://github.com/ferranbt/solstice/tree/main/extension for potential reference |
@DaniPopes can you help with the ci failures, is there something I am doing wrong with the way I set up my tests that they keep failing in CI but locally pass. The lsp implementation depends on forge being installed and available in PATH and test stored in |
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
,go-to-definition
, andcode actions
is planned.forge lint
notification via "textDocument/publishDiagnostics" requests with streaming updatesPR Checklist
Planned