Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
634 changes: 629 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ members = [
"numbat",
"numbat-exchange-rates",
"numbat-cli",
"numbat-lsp",
]

exclude = [
"numbat-wasm"
]

[profile.release]
lto = true
strip = true
codegen-units = 1
# lto = true
# strip = true
# codegen-units = 1
2 changes: 2 additions & 0 deletions numbat-lsp/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
lint = "clippy --workspace --all-targets -- --deny warnings"
7 changes: 7 additions & 0 deletions numbat-lsp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/target
node_modules
out/
.pnpm-debug.log
*.ast
dist/
*.vsix
56 changes: 56 additions & 0 deletions numbat-lsp/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.2.0",
"configurations": [
{
"type": "extensionHost",
"request": "launch",
"name": "Launch Client",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"outFiles": [
"${workspaceRoot}/client/out/**/*.js"
],
"preLaunchTask": {
"type": "npm",
"script": "watch"
},
"env": {
"SERVER_PATH": "${workspaceRoot}/target/debug/nrs-language-server"
}
},
// {
// "type": "node",
// "request": "attach",
// "name": "Attach to Server",
// "port": 6009,
// "restart": true,
// "outFiles": ["${workspaceRoot}/server/out/**/*.js"]
// },
{
"name": "Language Server E2E Test",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/client/out/test/index",
"${workspaceRoot}/client/testFixture"
],
"outFiles": [
"${workspaceRoot}/client/out/test/**/*.js"
]
}
],
"compounds": [
{
"name": "Client + Server",
"configurations": [
"Launch Client",
// "Attach to Server"
]
}
]
}
11 changes: 11 additions & 0 deletions numbat-lsp/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
35 changes: 35 additions & 0 deletions numbat-lsp/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "compile",
"group": "build",
"presentation": {
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": [
"$tsc"
]
},
{
"type": "npm",
"script": "watch",
"isBackground": true,
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": [
"$tsc-watch"
]
}
]
}
8 changes: 8 additions & 0 deletions numbat-lsp/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.vscode
node_modules
out/
src/
tsconfig.json
webpack.config.js
client/**
target
21 changes: 21 additions & 0 deletions numbat-lsp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "numbat-lsp"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chumsky = "0.8.0"
env_logger = "0.9.0"
ropey = "1.5.0"
serde_json = "1.0.78"
tokio = { version = "1.17.0", features = ["full"] }
tower-lsp = { version = "0.20.0", features = ["proposed"]}
serde = { version = "1.0", features = ["derive"] }
dashmap = "5.1.0"
dirs = "5"
log = "0.4.14"
im-rc = "15.0.0"
numbat = { path = "../numbat" }

21 changes: 21 additions & 0 deletions numbat-lsp/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 IWANABETHATGUY

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
84 changes: 84 additions & 0 deletions numbat-lsp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# boilerplate for a rust language server powered by `tower-lsp`
## 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 <kbd>F5</kbd> or change to the Debug panel and click <kbd>Launch Client</kbd>.
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 https://github.com/IWANABETHATGUY/tower-lsp-boilerplate/issues/6 for more details
## A valid program in nano rust
```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));
}
}
```
## Features
This repo use a language `nano rust` which first introduced by [ chumsky ](https://github.com/zesterer/chumsky/blob/master/examples/nano_rust.rs). Most common language feature has been implemented, you could preview via the video below.

- [x] InlayHint for LiteralType
![inlay hint](https://user-images.githubusercontent.com/17974631/156926412-c3823dac-664e-430e-96c1-c003a86eabb2.gif)

- [x] semantic token
make sure your semantic token is enabled, you could enable your `semantic token` by
adding this line to your `settings.json`
```json
{
"editor.semanticHighlighting.enabled": true,
}
```
- [x] syntactic error diagnostic

https://user-images.githubusercontent.com/17974631/156926382-a1c4c911-7ea1-4d3a-8e08-3cf7271da170.mp4

- [x] code completion

https://user-images.githubusercontent.com/17974631/156926355-010ef2cd-1d04-435b-bd1e-8b0dab9f44f1.mp4

- [x] go to definition

https://user-images.githubusercontent.com/17974631/156926103-94d90bd3-f31c-44e7-a2ce-4ddfde89bc33.mp4

- [x] find reference

https://user-images.githubusercontent.com/17974631/157367235-7091a36c-631a-4347-9c1e-a3b78db81714.mp4

- [x] rename

https://user-images.githubusercontent.com/17974631/157367229-99903896-5583-4f67-a6da-1ae1cf206876.mp4







15 changes: 15 additions & 0 deletions numbat-lsp/client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "nrs-language-client",
"description": "VSCode part of a language server",
"license": "MIT",
"version": "0.0.1",
"engines": {
"vscode": "^1.85.0"
},
"dependencies": {},
"devDependencies": {
"@types/node": "^17.0.18",
"vscode-test": "^1.3.0",
"@types/vscode": "1.86.0"
}
}
Loading