Skip to content

Latest commit

 

History

History
99 lines (70 loc) · 3.18 KB

README.md

File metadata and controls

99 lines (70 loc) · 3.18 KB

boilerplate for a rust language server powered by tower-lsp

Note

This repo use a language which is a very small subset of rust called nano rust

A valid program in nano rust

fn factorial(x) {
    // Conditionals are supported!
    if x == 0 {
        1
    } else {
        x * factorial(x - 1)
    }
}

// The main function
fn main() {
    let three = 3;
    let meaning_of_life = three * 14 + 1;

    print("Hello, world!");
    print("The meaning of life is...");

    if meaning_of_life == 42 {
        print(meaning_of_life);
    } else {
        print("...something we cannot know");

        print("However, I can tell you that the factorial of 10 is...");
        // Function calling
        print(factorial(10));
    }
}

Introduction

This repo is a template for tower-lsp, a useful github project template which makes writing new language servers easier.

Development using VSCode

  1. pnpm i
  2. cargo build
  3. Open the project in VSCode: code .
  4. In VSCode, press F5 or change to the Debug panel and click Launch Client.
  5. In the newly launched VSCode instance, open the file examples/test.nrs from this project.
  6. If the LSP is working correctly you should see syntax highlighting and the features described below should work.

Note

If encountered errors like Cannot find module '/xxx/xxx/dist/extension.js' please try run command tsc -b manually, you could refer #6 for more details

Preview and test extension locally with VsCode

  1. Make sure all dependency are installed.
  2. Make sure the nrs-language-server is under your PATH
  3. pnpm run package
  4. code --install-extension nrs-language-server-${version}.vsix, the version you could inspect in file system.
  5. Restart the VsCode, and write a minimal nano rust file, then inspect the effect.

For other editor, please refer the related manual, you could skip steps above.

Features

This repo use a language nano rust which first introduced by chumsky . Most common language feature has been implemented, you could preview via the video below.

  • InlayHint for LiteralType inlay hint

  • semantic token
    make sure your semantic token is enabled, you could enable your semantic token by adding this line to your settings.json

{
 "editor.semanticHighlighting.enabled": true,
}
  • syntactic error diagnostic
syntactic.mp4
  • code completion
Peek.2022-03-06.21-47.mp4
  • go to definition
definition.mp4
  • find reference
reference.mp4
  • rename
rename.mp4