Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@nomicfoundation/solidity-language-server
Advanced tools
Solidity language server by Nomic Foundation
A language server for the Solidity programming language, used in the Solidity by Nomic Foundation
VS code extension and the @nomicfoundation/coc-solidity
coc.nvim extension.
Built by the Nomic Foundation for the Ethereum community.
Join our Hardhat Support Discord server to stay up to date on new releases, plugins and tutorials.
The language server can be installed via npm:
npm install @nomicfoundation/solidity-language-server -g
To run the server standalone:
nomicfoundation-solidity-language-server --stdio
For coc the extension for this language server (found here) can be installed through the coc vim command:
:CocInstall @nomicfoundation/coc-solidity
To run the language server directly through the neovim lsp (assuming neovim/nvim-lspconfig)
local lspconfig = require 'lspconfig'
local configs = require 'lspconfig.configs'
configs.solidity = {
default_config = {
cmd = {'nomicfoundation-solidity-language-server', '--stdio'},
filetypes = { 'solidity' },
root_dir = lspconfig.util.find_git_ancestor,
single_file_support = true,
},
}
lspconfig.solidity.setup {}
The solidity language server autocompletes references to existing symbols (e.g. contract instances, globally available variables and built-in types like arrays) and import directives (i.e. it autocompletes the path to the imported file).
Direct imports (those not starting with ./
or ../
) are completed based on suggestions from ./node_modules
.
Relative imports pull their suggestions from the file system based on the current solidity file's location.
Natspec documentation completion is also supported
Move through your codebase with semantic navigation commands:
Navigates to the definition of an identifier.
Navigates to the type of an identifier.
Shows all references of the identifier under the cursor.
Rename the identifier under the cursor and all of its references:
Apply solidity formatting to the current document.
The formatting configuration can be overriden through a .prettierrc
file, see Formatting Configuration.
Hovering the cursor over variables, function calls, errors and events will display a popup showing type and signature information:
As code is edited, Solidity by Nomic Foundation runs the solc compiler over the changes and displays any warnings or errors it finds.
This feature is only available in solidity files that are part of a Hardhat project, as Hardhat is used for import resolution, see Hardhat Projects for details.
Code actions, or quickfixes are refactorings suggested to resolve a solc warning or error.
A line with a warning/error that has a code action, will appear with small light bulb against it; clicking the light bulb will provide the option to trigger the code action.
A contract that implements an interface, but is missing functions specified in the interface, will get a solidity(3656)
error.
The matching code action Add missing functions from interface will determine which functions need to be implemented to satisfy the interface and add them as stubs to the body of the contract.
A function without a mutability keyword but which does not update contract state will show a solidity(2018)
warning, with solc
suggesting adding either the view
or pure
keyword depending on whether the function reads from state.
The matching code action Add view/pure modifier to function declaration resolves the warning by adding the keyword to the function signature.
virtual
/override
on inherited function signatureA function in an inheriting contract, that has the same name and parameters as a function in the base contract, causes solidity(4334)
in the base contract function if it does not have the virtual
keyword and solidity(9456)
in the inheriting contract function if does not have the override
keyword.
The Add virtual specifier to function definition and Add override specifier to function definition code actions appear against functions with these errors.
public
/private
to function signatureA function without an accessibility keyword will cause the solidity(4937)
error.
Two code actions will appear against a function with this error: Add public visibility to declaration and Add private visibility to declaration.
pragma solidity
versionWhen no license is specified on a contract, the solidity(1878)
warning is raised by the compiler. Similarly, when no compiler version is specified with a pragma solidity
statement, the compiler shows the solidity(3420)
warning. There are code actions available for quick fixes.
Some types require you to specify a data location (memory, storage, calldata), depending on where they are defined. The available code actions allow the user to add, change or remove data locations depending on the error being raised.
The solidity compiler requires explicit addresses to be in the correct checksummed format. This quickfix transforms any address to the expected format.
Hardhat's console.sol
can be imported with this quickfix. Please note that this only available on hardhat projects.
Solidity by Nomic Foundation provides enhanced functionality for Solidity files within a Hardhat project, including inline validation and quick fixes.
To take advantage of these features, use the File
menu to Open Folder
, and select the folder containing the hardhat.config.{js,ts}
file.
Inline validation (the display of compiler errors and warnings against the code) is based on your Hardhat configuration file. The version of the solc
solidity compiler used for validation is set within this file, see the Hardhat documentation for more details.
Solidity by Nomic Foundation will detect Hardhat projects (folders containing a hardhat.config.{js,ts}
file) within a monorepo, when the root of the monorepo is opened as a workspace folder.
The Hardhat config file that is used when validating a Solidity file is shown in the Solidity section on the Status Bar:
Contributions are always welcome! Feel free to open any issue or send a pull request.
Go to CONTRIBUTING.md to learn about how to set up a development environment.
Hardhat Support Discord server: for questions and feedback.
FAQs
Solidity language server by Nomic Foundation
The npm package @nomicfoundation/solidity-language-server receives a total of 163 weekly downloads. As such, @nomicfoundation/solidity-language-server popularity was classified as not popular.
We found that @nomicfoundation/solidity-language-server demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.