Skip to content

Commit c998fe6

Browse files
authored
Add C support
- Add basic C Support - Improve test framework
2 parents cc1e1eb + 8f674b4 commit c998fe6

35 files changed

+2076
-768
lines changed

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4

.github/workflows/build.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Package Extension
22
on:
3+
pull_request:
34
push:
5+
branches: main
46
tags-ignore:
57
- "**"
68
release:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
66

77
## [Unreleased]
88

9+
- Improved comment-test framework to allow writing tests for multiple languages
10+
- Added comment-test in-browser rendering to allow better debugging
11+
- Add basic support for C
12+
913
## [0.0.3] - 2024-09-07
1014

1115
- Learned Go's `fallthrough` keyword

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,25 @@ Note that the demo only supports a single function and ignores the cursor locati
1919
## Supported Languages
2020

2121
- Go
22+
23+
## Development
24+
25+
### Requirements
26+
27+
- [Bun](https://bun.sh/) is required to develop the project.
28+
- [Bun for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=oven.bun-vscode) is needed for debugging in VS Code
29+
- [emscripted](https://emscripten.org/) is only required if you want to add new tree-sitter parsers.
30+
31+
### Getting Started
32+
33+
Clone the project and install dependencies.
34+
35+
```bash
36+
git clone https://github.com/tmr232/function-graph-overview/
37+
cd function-graph-overview
38+
bun install
39+
```
40+
41+
You can debug the extension via VS Code by pressing F5.
42+
43+
To run the demo, run `bun demo`.

bun.lockb

1.26 KB
Binary file not shown.

eslint.config.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ export default tseslint.config(
77
eslint.configs.recommended,
88
...tseslint.configs.recommended,
99
{
10-
ignores: ["dist", "webview-content", "src/frontend", "src/demo"],
10+
ignores: [
11+
"dist",
12+
"webview-content",
13+
"src/frontend",
14+
"src/demo",
15+
".vscode-test.mjs",
16+
],
1117
},
1218
{
19+
languageOptions: {
20+
parserOptions: {
21+
projectService: true,
22+
},
23+
},
1324
rules: {
1425
"@typescript-eslint/no-unused-vars": [
1526
"error", // or "error"
@@ -19,6 +30,7 @@ export default tseslint.config(
1930
caughtErrorsIgnorePattern: "^_",
2031
},
2132
],
33+
"@typescript-eslint/no-unnecessary-condition": "error",
2234
},
2335
},
2436
);

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"web-tree-sitter": "^0.23.0"
1212
},
1313
"devDependencies": {
14+
"@codemirror/lang-cpp": "^6.0.2",
1415
"@codemirror/lang-go": "^6.0.1",
1516
"@eslint/js": "^9.9.1",
1617
"@rollup/plugin-wasm": "^6.2.2",
@@ -25,6 +26,7 @@
2526
"prettier-plugin-svelte": "^3.2.6",
2627
"svelte": "^4.2.18",
2728
"svelte-codemirror-editor": "^1.4.1",
29+
"tree-sitter-c": "^0.23.0",
2830
"tree-sitter-cli": "^0.23.0",
2931
"tree-sitter-go": "^0.23.0",
3032
"typescript-eslint": "^8.4.0",
@@ -42,11 +44,12 @@
4244
"package": "bun run build && bun run vsce-package",
4345
"publish": "bun run package && bun run vsce-publish",
4446
"clean": "rm -r ./dist",
45-
"web": "bun run --cwd ./src/frontend/ vite",
47+
"web": "bun run ./scripts/collect-comment-tests.ts && bun run --cwd ./src/frontend/ vite",
4648
"demo": "bun run --cwd ./src/demo/ vite",
4749
"build-demo": "bun run --cwd ./src/demo/ vite build --outDir ../../dist/demo --base '/function-graph-overview/'",
48-
"format": "bun prettier . --write",
49-
"lint": "bun format && bun run eslint"
50+
"format": "bun prettier . --write --log-level silent",
51+
"lint": "bun format && bun run eslint",
52+
"generate-parsers": "bun run ./scripts/generate-parsers.ts"
5053
},
5154
"//": "START EXTENSION ATTRIBUTES",
5255
"publisher": "tamir-bahar",

parsers/tree-sitter-c.wasm

601 KB
Binary file not shown.

scripts/collect-comment-tests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { testFunctions as testFuncsForGo } from "../src/test/collect-go";
2+
import { testFunctions as testFuncsForC } from "../src/test/collect-c";
3+
import { intoRecords } from "../src/test/commentTestUtils";
4+
5+
const records = intoRecords([...testFuncsForC, ...testFuncsForGo]);
6+
7+
Bun.write("./dist/tests/commentTests.json", JSON.stringify(records));

scripts/generate-parsers.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { $ } from "bun";
2+
3+
const treeSitter = Bun.file("./node_modules/web-tree-sitter/tree-sitter.wasm");
4+
await Bun.write("./parsers/tree-sitter.wasm", treeSitter);
5+
6+
const parsers = ["tree-sitter-go", "tree-sitter-c"];
7+
8+
for (const name of parsers) {
9+
await $`bun x --bun tree-sitter build --wasm -o ./parsers/${name}.wasm ./node_modules/${name}/`;
10+
}

0 commit comments

Comments
 (0)