Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimplicityHL LSP

This project was originally part of SimplicityHL, the high-level language for writing Simplicity smart contracts.

Language Server for SimplicityHL language.

Features

  • Basic diagnostic for SimplicityHL code

diagnostics

  • Completions of built-ins, jets and functions

completion

  • Hover for built-ins, jets and functions, with support of documentation

hover

  • Go to definition for functions

goto-definition

Configuration

Editors send settings under the simplicityhl section. Every field is optional; the defaults below are what the server uses when a client sends nothing.

{
  "simplicityhl": {
    "experimentalFeatures": {
      "imports": false
    },
    "project": {
      "simplex": {
        "enabled": true,
        "manifestPath": ""
      },
      "sourceDirectory": "",
      "dependencies": {}
    }
  }
}
  • experimentalFeatures.imports enables the compiler's unstable use / mod / pub syntax. It is off by default because the feature is unstable in the compiler itself.
  • project.simplex.enabled looks for the nearest Simplex.toml (or simplex.toml) in the file's ancestors and honours its build.src_dir and [dependencies], resolving path dependencies recursively and locating installed git dependencies under deps/.
  • project.simplex.manifestPath pins an explicit manifest instead of searching. Relative values resolve from the containing workspace folder. A path that does not exist is reported as a diagnostic rather than silently ignored.
  • project.sourceDirectory overrides the package root when there is no manifest, or when the manifest's src_dir is not what the editor should use.
  • project.dependencies adds import roots by hand. They supplement the manifest and win on a colliding alias:
{
  "std": "../simplicityhl-std/simf",
  "math": { "path": "../math/simf", "context": "simf/contracts" }
}

The shorthand form maps an alias for the whole package. The detailed form restricts the mapping to files under context, matching how the compiler scopes dependencies per package.

Configuration changes take effect immediately: the server re-analyses open documents on workspace/didChangeConfiguration, on workspace-folder changes, and when a watched .simf file or Simplex manifest changes on disk.

Installation

Install Language Server using cargo:

cargo install simplicityhl-lsp

Integration with editors

Neovim

LSP

  1. Install simplicityhl-lsp to your PATH.

  2. Include this Lua snippet to your Neovim config:

vim.filetype.add({
	extension = {
		simf = "simf",
	},
})

vim.lsp.config["simplicityhl-lsp"] = {
	cmd = { "simplicityhl-lsp" },
	filetypes = { "simf" },
	settings = {
		simplicityhl = {
			experimentalFeatures = { imports = true },
			project = { simplex = { enabled = true, manifestPath = "" } },
		},
	},
}
vim.lsp.enable("simplicityhl-lsp")
  1. Open .simf file and check that LSP is active ("attached"):
:checkhealth vim.lsp

Tree-sitter (Highlighting)

Currently, the Language Server does not provide any syntax highlighting on its own, but you can install tree-sitter for SimplicityHL:

  1. Set up the nvim-treesitter plugin.

  2. Include this Lua snippet in your Neovim config to register parser:

vim.api.nvim_create_autocmd("User", {
	pattern = "TSUpdate",
	callback = function()
		require("nvim-treesitter.parsers").simplicityhl = {
			install_info = {
				url = "https://github.com/distributed-lab/tree-sitter-simplicityhl",
				queries = "queries",
			},
			filetype = "simf",
			tier = 0,
		}
	end,
})

vim.treesitter.language.register("simplicityhl", { "simf" })

vim.api.nvim_create_autocmd("FileType", {
	pattern = { "simf" },
	callback = function()
		vim.treesitter.start()
	end,
})
  1. Restart Neovim and run:
:TSInstall simplicityhl

If everything is working correctly, you should see syntax highlighting in .simf files.

Note: This method is compatible only with nvim-treesitter v0.10 or newer.

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages