mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-12-25 12:14:19 +01:00
feat(lang): add solidity language support (#4742)
## Description
### Summary
This PR adds comprehensive support for Solidity development in Neovim
using LazyVim. The following updates were made to streamline Solidity
development:
### Changes
1. **Solidity File Type Detection**
- Configured LazyVim to recognize Solidity projects by detecting
`foundry.toml`, `hardhat.config.js`, and `hardhat.config.ts` files.
2. **Treesitter Support for Solidity**
- Added `solidity` to the list of languages ensured by
`nvim-treesitter`, providing syntax highlighting and better code
structure understanding.
3. **Language Server Protocol (LSP) Setup**
- Configured `nvim-lspconfig` to support `solidity_ls` as the LSP for
Solidity files.
- Set up `root_dir` detection based on project files or a `.git`
directory to enable proper LSP functioning in Solidity projects.
4. **Solidity Formatter**
- Integrated `forge_fmt` as a formatter for Solidity files using
`conform.nvim`, which utilizes `forge fmt` to format code.
### Why use `forge fmt` instead of Prettier?
- **Prettier's Solidity support requires extra plugins**: Prettier does
not have native Solidity support and depends on
`prettier-plugin-solidity`. Even with
`vim.g.lazyvim_prettier_needs_config = false`, formatting won't work
unless a `.prettierrc` file is configured, creating unnecessary
complexity.
- **`forge fmt` is the native tool for Solidity development**: `Forge`
is a widely used tool within the Solidity ecosystem, especially when
working with Foundry. It provides built-in formatting with no extra
dependencies, making it simpler and more efficient to integrate.
- **Hardhat uses `prettier-plugin-solidity`**: For users of Hardhat,
`prettier-plugin-solidity` is required for code formatting. However, the
integration with Prettier might add complexity, while `forge fmt`
simplifies the process.
- **Future customization**: We may allow users to choose between
`prettier-plugin-solidity` and `forge fmt` for formatting in the future,
depending on their preferred tools.
### Testing
- Confirmed that Solidity files are detected and syntax-highlighted by
Treesitter.
- Verified LSP functionality for Solidity, including code navigation and
error detection.
- Tested `forge_fmt` for automatic code formatting on Solidity files.
### Motivation
These changes provide a smoother and more robust Solidity development
experience in Lazyvim, including syntax highlighting, code navigation,
and automatic formatting.
## Related Issue(s)
https://github.com/LazyVim/LazyVim/issues/1901
## Checklist
- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
---------
Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
42
lua/lazyvim/plugins/extras/lang/solidity.lua
Normal file
42
lua/lazyvim/plugins/extras/lang/solidity.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
return {
|
||||
recommended = function()
|
||||
return LazyVim.extras.wants({
|
||||
ft = "solidity",
|
||||
root = {
|
||||
"foundry.toml",
|
||||
"hardhat.config.js",
|
||||
"hardhat.config.ts",
|
||||
},
|
||||
})
|
||||
end,
|
||||
-- Add Solidity & related to treesitter
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
opts = { ensure_installed = { "solidity" } },
|
||||
},
|
||||
|
||||
-- Correctly setup lspconfig for Solidity
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
opts = {
|
||||
servers = {
|
||||
solidity_ls = {},
|
||||
},
|
||||
},
|
||||
},
|
||||
-- Formatter for Solidity
|
||||
{
|
||||
"conform.nvim",
|
||||
opts = function(_, opts)
|
||||
opts.formatters_by_ft = opts.formatters_by_ft or {}
|
||||
opts.formatters_by_ft.solidity = { "forge_fmt" }
|
||||
|
||||
opts.formatters = {
|
||||
forge_fmt = {
|
||||
command = "forge",
|
||||
args = { "fmt" },
|
||||
},
|
||||
}
|
||||
end,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user