Skip to content

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

78 Commits

Folders and files

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, plus context-aware use paths and public importable items

completion

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

hover

  • Go to definition for functions

goto-definition

  • Document formatting with simfmt, the formatter behind simplex fmt

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,
      "enums": false
    },
    "project": {
      "simplex": {
        "enabled": true,
        "manifestPath": ""
      },
      "sourceDirectory": "",
      "dependencies": {}
    },
    "formatter": {
      "path": ""
    }
  }
}
  • 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.
  • experimentalFeatures.enums enables enum declarations and enum match patterns, likewise unstable in the compiler.
  • project.simplex.enabled looks for the nearest 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/. Like simplex, it only reads a file named exactly Simplex.toml.
  • 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.

  • formatter.path sets the simfmt binary used for formatting. If empty, the server looks for simfmt next to simplex on PATH, then in ~/.simplex/bin (or $SIMPLEX_DIR/bin), then anywhere on PATH. The nearest simfmt.toml applies, same as with simplex fmt.

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, enums = false },
      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

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages