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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b7ff920
add forge lsp
mmsaki Aug 1, 2025
990732d
add lsp crate
mmsaki Aug 1, 2025
b65969c
Merge branch 'foundry-rs:master' into lsp
mmsaki Aug 1, 2025
2997735
fmt and cargo update
mmsaki Aug 1, 2025
e926489
add forge linting diagnostics capabilities
mmsaki Aug 1, 2025
c6ba04f
add testdata and tests
mmsaki Aug 1, 2025
6b286b7
add neovim logs
mmsaki Aug 1, 2025
3c36a29
Merge branch 'foundry-rs:master' into lsp
mmsaki Aug 2, 2025
9655850
feat(lsp): refactor adds server to forge cmd
mmsaki Aug 2, 2025
b142c1b
Merge branch 'foundry-rs:master' into lsp
mmsaki Aug 2, 2025
7cf3215
clean up lint_file method
mmsaki Aug 2, 2025
a18690a
fmt
mmsaki Aug 2, 2025
6304f7d
Merge branch 'master' into lsp
mmsaki Aug 2, 2025
d2beb49
Merge branch 'foundry-rs:master' into lsp
mmsaki Aug 3, 2025
7afb011
add forge build warnings & error diagnsotics
mmsaki Aug 4, 2025
9767787
colapse if statement
mmsaki Aug 4, 2025
71f6bc5
combine lint and build diagnostics fixes overring bug
mmsaki Aug 4, 2025
1cb3197
read byte offsets for build errors
mmsaki Aug 4, 2025
5207cd4
remove comment
mmsaki Aug 4, 2025
af9b975
ignore code size limit warning for test files
mmsaki Aug 4, 2025
70c5eb3
update readme doc
mmsaki Aug 4, 2025
c4d35b7
add return on nvim lsp file
mmsaki Aug 4, 2025
bc90368
refactor code + add test for byte offsets
mmsaki Aug 4, 2025
cb43585
move structs
mmsaki Aug 4, 2025
00a328f
fmt
mmsaki Aug 4, 2025
18f5586
refactor
mmsaki Aug 4, 2025
8019317
(chore): refactor method names
mmsaki Aug 4, 2025
32a2be5
chore: example not using nvim-config
mmsaki Aug 4, 2025
07da00f
chore: update readme
mmsaki Aug 4, 2025
c9ef019
use SHORT_VERSION from foundry commons
mmsaki Aug 5, 2025
5987960
fix doc ci error
mmsaki Aug 5, 2025
4823303
Merge branch 'foundry-rs:master' into lsp
mmsaki Aug 10, 2025
0251293
disable lint on build
mmsaki Aug 10, 2025
5273fea
use temp files for testing
mmsaki Aug 10, 2025
ef35e6f
fix reset hunk
mmsaki Aug 10, 2025
8d5ca1d
feat(lsp): add gotoDeclaration and gotoDefinition
mmsaki Aug 11, 2025
a38fb7d
fix(lsp): track rellative file based nodes fixes broken goto definitions
mmsaki Aug 11, 2025
a228703
feat(lsp): add go to definition for contract inheritances
mmsaki Aug 11, 2025
5cb4576
feat(lsp): add value nodes in expressions
mmsaki Aug 11, 2025
0a81408
feat(lsp): add go to definition in user defined mapping structs
mmsaki Aug 11, 2025
4d9310e
feat(lsp): goto definitions for conditions, trueBody and subExpressions
mmsaki Aug 11, 2025
30f317e
feat(lsp): add left + right expressions, adds intialValues node
mmsaki Aug 11, 2025
bb919bb
feat(lsp): add event call goto, fix handles list and object parameters
mmsaki Aug 11, 2025
f5b8fd9
feat(lsp): fix handles arguments of array type
mmsaki Aug 11, 2025
dce0efa
feat(lsp): add handle for false body on ast
mmsaki Aug 11, 2025
cce016e
feat(lsp): add base expression + index expression ast node types
mmsaki Aug 11, 2025
01f8f40
fix(lsp): fix clippy warnings
mmsaki Aug 11, 2025
6226184
feat(lsp): add override nodes types
mmsaki Aug 11, 2025
d6413d5
chore(lsp): create helper function for pushing nodes to queue
mmsaki Aug 11, 2025
f701d4f
feat(lsp): add abstract and storage layout node
mmsaki Aug 11, 2025
17e000d
feat(lsp): add file, literals and unitAliases
mmsaki Aug 11, 2025
a0f3148
Merge branch 'master' into lsp
mmsaki Aug 11, 2025
0de7c43
fix(lsp): no need for abstract node
mmsaki Aug 12, 2025
e7f8231
chore(lsp): sort names alphabetically
mmsaki Aug 12, 2025
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
130 changes: 116 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"crates/macros/",
"crates/test-utils/",
"crates/lint/",
"crates/lsp/",
]
resolver = "2"

Expand Down Expand Up @@ -180,6 +181,7 @@ forge = { path = "crates/forge" }
forge-doc = { path = "crates/doc" }
forge-fmt = { path = "crates/fmt" }
forge-lint = { path = "crates/lint" }
forge-lsp = { path = "crates/lsp" }
forge-verify = { path = "crates/verify" }
forge-script = { path = "crates/script" }
forge-sol-macro-gen = { path = "crates/sol-macro-gen" }
Expand Down
2 changes: 2 additions & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ chrono.workspace = true
forge-doc.workspace = true
forge-fmt.workspace = true
forge-lint.workspace = true
forge-lsp.workspace = true
forge-verify.workspace = true
forge-script.workspace = true
forge-sol-macro-gen.workspace = true
Expand Down Expand Up @@ -89,6 +90,7 @@ watchexec-signals = "5.0"
clearscreen = "4.0"
evm-disassembler.workspace = true
path-slash.workspace = true
tower-lsp = "0.20"

# doc server
axum = { workspace = true, features = ["ws"] }
Expand Down
1 change: 1 addition & 0 deletions crates/forge/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,6 @@ pub fn run_command(args: Forge) -> Result<()> {
ForgeSubcommand::Eip712(cmd) => cmd.run(),
ForgeSubcommand::BindJson(cmd) => cmd.run(),
ForgeSubcommand::Lint(cmd) => cmd.run(),
ForgeSubcommand::Lsp(cmd) => global.block_on(cmd.run()),
}
}
31 changes: 31 additions & 0 deletions crates/forge/src/cmd/lsp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use clap::Parser;
use eyre::Result;

use forge_lsp::lsp::ForgeLsp;
use tower_lsp::{LspService, Server};
use tracing::info;

/// Start the Foundry Language Server Protocol (LSP) server
#[derive(Clone, Debug, Parser)]
pub struct LspArgs {
/// See: <https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#implementationConsiderations>
#[arg(long)]
pub stdio: bool,
Copy link
Member

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

Copy link
Author

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.

Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

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

Okay i'll leave it as is, it'll work on both forge lsp and forge lsp --stdio. I only plan on implementing stdio.

}

impl LspArgs {
pub async fn run(self) -> Result<()> {
// Start stdio LSP server
info!("Starting Foundry LSP server...");

let stdin = tokio::io::stdin();
let stdout = tokio::io::stdout();
let (service, socket) = LspService::new(ForgeLsp::new);

Server::new(stdin, stdout, socket).serve(service).await;

info!("Foundry LSP server stopped");

Ok(())
}
}
1 change: 1 addition & 0 deletions crates/forge/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod init;
pub mod inspect;
pub mod install;
pub mod lint;
pub mod lsp;
pub mod remappings;
pub mod remove;
pub mod selectors;
Expand Down
7 changes: 5 additions & 2 deletions crates/forge/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::cmd::{
bind::BindArgs, bind_json, build::BuildArgs, cache::CacheArgs, clone::CloneArgs,
compiler::CompilerArgs, config, coverage, create::CreateArgs, doc::DocArgs, eip712, flatten,
fmt::FmtArgs, geiger, generate, init::InitArgs, inspect, install::InstallArgs, lint::LintArgs,
remappings::RemappingArgs, remove::RemoveArgs, selectors::SelectorsSubcommands, snapshot,
soldeer, test, tree, update,
lsp::LspArgs, remappings::RemappingArgs, remove::RemoveArgs, selectors::SelectorsSubcommands,
snapshot, soldeer, test, tree, update,
};
use clap::{Parser, Subcommand, ValueHint};
use forge_script::ScriptArgs;
Expand Down Expand Up @@ -136,6 +136,9 @@ pub enum ForgeSubcommand {
#[command(visible_alias = "l")]
Lint(LintArgs),

/// Start the Foundry Language Server Protocol (LSP) server
Lsp(LspArgs),

/// Get specialized information about a smart contract.
#[command(visible_alias = "in")]
Inspect(inspect::InspectArgs),
Expand Down
Loading
Loading