Skip to content

mmsaki/forge-lsp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solidity LSP

A Language Server Protocol (LSP) implementation for Solidity development using Foundry's compilation and linting infrastructure.

This work is a continuation from foundry-rs/foundry PR #11187.

Install

Install binary from crates.io

cargo install forge-lsp

Usage

Start the LSP server using:

forge-lsp --stdio

LSP Features

General

  • initialize - Server initialization
  • initialized - Server initialized notification
  • shutdown - Server shutdown

Text Synchronization

  • textDocument/didOpen - Handle file opening
  • textDocument/didChange - Handle file content changes
  • textDocument/didSave - Handle file saving with diagnostics refresh
  • textDocument/didClose - Handle file closing
  • textDocument/willSave - File will save notification
  • textDocument/willSaveWaitUntil - File will save wait until

Diagnostics

  • textDocument/publishDiagnostics - Publish compilation errors and warnings via forge build
  • textDocument/publishDiagnostics - Publish linting errors and warnings via forge lint

Language Features

  • textDocument/definition - Go to definition
  • textDocument/declaration - Go to declaration
  • textDocument/references - Find all references
  • textDocument/documentSymbol - Document symbol outline (contracts, functions, variables, events, structs, enums, etc.)
  • textDocument/rename - Rename symbols across files
  • textDocument/completion - Code completion
  • textDocument/hover - Hover information
  • textDocument/signatureHelp - Function signature help
  • textDocument/typeDefinition - Go to type definition
  • textDocument/implementation - Go to implementation
  • textDocument/documentHighlight - Document highlighting
  • textDocument/codeAction - Code actions (quick fixes, refactoring)
  • textDocument/codeLens - Code lens
  • textDocument/documentLink - Document links
  • textDocument/documentColor - Color information
  • textDocument/colorPresentation - Color presentation
  • textDocument/formatting - Document formatting
  • textDocument/rangeFormatting - Range formatting
  • textDocument/onTypeFormatting - On-type formatting
  • textDocument/prepareRename - Prepare rename validation
  • textDocument/foldingRange - Folding ranges
  • textDocument/selectionRange - Selection ranges
  • textDocument/semanticTokens - Semantic tokens
  • textDocument/semanticTokens/full - Full semantic tokens
  • textDocument/semanticTokens/range - Range semantic tokens
  • textDocument/semanticTokens/delta - Delta semantic tokens

Workspace Features

  • workspace/symbol - Workspace-wide symbol search
  • workspace/didChangeConfiguration - Acknowledges configuration changes (logs only)
  • workspace/didChangeWatchedFiles - Acknowledges watched file changes (logs only)
  • workspace/didChangeWorkspaceFolders - Acknowledges workspace folder changes (logs only)
  • workspace/executeCommand - Execute workspace commands (stub implementation)
  • workspace/applyEdit - Apply workspace edits
  • workspace/willCreateFiles - File creation preview
  • workspace/willRenameFiles - File rename preview
  • workspace/willDeleteFiles - File deletion preview

Window Features

  • window/showMessage - Show message to user
  • window/showMessageRequest - Show message request to user
  • window/workDoneProgress - Work done progress

Development

Building

cargo build --release

Testing

cargo test

VSCode or Cursor

You can add the following to VSCode (or cursor) using a lsp-proxy extension see comment here:

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

Neovim

If you have neovim 0.11+ installed add these to your config

-- lsp/forge_lsp.lua
return {
  cmd = { "forge-lsp" },
  filetypes = { "solidity" },
  root_markers = { "foundry.toml", ".git" },
  root_dir = vim.fs.root(0, { "foundry.toml", ".git" }),
}
-- init.lua
vim.lsp.enable("forge_lsp")

Debugging in neovim

Lsp logs are stored in ~/.local/state/nvim/lsp.log

To clear lsp logs run:

> -f ~/.local/state/nvim/lsp.log

To monitor logs in real time run:

tail -f ~/.local/state/nvim/lsp.log

Enable traces in neovim to view full traces in logs:

:lua vim.lsp.set_log_level("trace")

Contributing

Check out the foundry contribution guide.

About

Solidity LSP server build in rust using foundry compilation and linting infrastructure.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages