Skip to content

Commit

Permalink
Add TS formatter and linter for VSCode extension (starkware-libs#2762)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr authored Apr 13, 2023
1 parent 48f07a4 commit a647d98
Show file tree
Hide file tree
Showing 11 changed files with 2,406 additions and 278 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/vscode-cairo-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: VSCode Cairo Extension CI

on:
push:
branches:
- main
paths:
- 'vscode-cairo/**'
pull_request:
paths:
- 'vscode-cairo/**'
merge_group:

jobs:
fmt-and-lint:
name: format and lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./vscode-cairo
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: npm
cache-dependency-path: vscode-cairo/package-lock.json
- run: npm ci
- run: npm run fmt:check
- run: npm run lint
9 changes: 9 additions & 0 deletions vscode-cairo/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
]
}
1 change: 0 additions & 1 deletion vscode-cairo/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/node_modules
/out
/package-lock.json
/*.vsix
1 change: 1 addition & 0 deletions vscode-cairo/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out
1 change: 1 addition & 0 deletions vscode-cairo/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
13 changes: 9 additions & 4 deletions vscode-cairo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Install Node.js 18 LTS:
See troubleshooting section.

From the directory of this file, run:

```
sudo npm install --global @vscode/vsce
npm install
Expand All @@ -12,6 +13,7 @@ code --install-extension cairo1*.vsix
```

Remember to build the language server:

```
cargo build --bin cairo-language-server --release
```
Expand All @@ -20,22 +22,22 @@ Now open vscode, find the Cairo extension and fill in the path to the cairo lang

![image](./resources/img/extSettings.png)



It should look like:
``/path/cairo/target/release/cairo-language-server``
Where *path* is the path to the cairo folder you got when cloning this repository.
`/path/cairo/target/release/cairo-language-server`
Where _path_ is the path to the cairo folder you got when cloning this repository.

## Troubleshooting

If `sudo npm install -g vsce` fails try this:

```
sudo apt remove nodejs
sudo apt update
sudo apt install curl dirmngr apt-transport-https lsb-release ca-certificates vim
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install nodejs
```

If successful, go back to `sudo npm install -g vsce` and continue from there.

# Run the extension (for development)
Expand All @@ -52,17 +54,20 @@ If successful, go back to `sudo npm install -g vsce` and continue from there.
# Debugging

To make the "Debug"/"Run" CodeLens above your tests work - add this to your ~/.config/Code/User/settings.json:

```
"rust-analyzer.runnableEnv": {
"CARGO_MANIFEST_DIR": "/path/to/workspace/repo_name/any_dir"
},
```

If you also want logs to be printed in your VSCode terminal when you click the "Debug"/"Run" CodeLens above your tests, also add the "RUST_LOG" field:

```
"rust-analyzer.runnableEnv": {
"CARGO_MANIFEST_DIR": "/path/to/workspace/repo_name/any_dir",
"RUST_LOG": "debug,salsa=off,minilp=off"
},
```

Use `debug`/`trace` at your preference.
50 changes: 25 additions & 25 deletions vscode-cairo/language-configuration.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"comments": {
// Symbol used for single line comment.
"lineComment": "//",
},
// Symbols used as brackets.
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"],
],
// Symbols that are auto closed when typing.
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "\"", "close": "\"", "notIn": ["string"] },
{ "open": "'", "close": "'", "notIn": ["string"] },
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
]
"comments": {
// Symbol used for single line comment.
"lineComment": "//"
},
// Symbols used as brackets.
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// Symbols that are auto closed when typing.
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "\"", "close": "\"", "notIn": ["string"] },
{ "open": "'", "close": "'", "notIn": ["string"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
Loading

0 comments on commit a647d98

Please sign in to comment.