Skip to content

Commit 13d2159

Browse files
committed
update browser_wasi_shim and install with npm
This temporarily regresses ZLS's ability to resolve the zig library directory
1 parent 559430c commit 13d2159

File tree

16 files changed

+121
-1798
lines changed

16 files changed

+121
-1798
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"serve": "parcel 404.html"
66
},
77
"dependencies": {
8+
"@bjorn3/browser_wasi_shim": "^0.4.1",
89
"@codemirror/autocomplete": "^6.4.2",
910
"@codemirror/commands": "^6.2.2",
1011
"@codemirror/language": "^6.6.0",

src/editor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ export default class ZlsClient extends LspClient {
5050
if (this.worker) {
5151
const str = JSON.stringify(message);
5252

53-
const final =
54-
`Content-Length: ${str.length}\r
55-
\r
56-
${str}`
53+
const final = `Content-Length: ${str.length}\r\n\r\n${str}`;
5754

5855
this.sharer.lock();
5956

src/utils.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
import zigTar from "url:./zig.tar.gz";
22
import { ungzip } from "pako";
33
import { untar } from "@immutabl3/tar";
4-
import { Directory, File } from "./wasi";
4+
import { Directory, File } from "@bjorn3/browser_wasi_shim";
55

66
export async function getLatestZigArchive() {
77
const archive = await (await fetch(zigTar, {})).arrayBuffer();
88
const entries = await untar(ungzip(archive));
99

10-
const first = entries[0].path;
11-
12-
let dirs = new Directory({});
10+
let root: TreeNode = new Map();
1311

1412
for (const e of entries) {
15-
if (e.type === "file") {
16-
const path = e.path.slice(first.length);
17-
const splitPath = path.split("/");
18-
19-
let c = dirs;
20-
for (const segment of splitPath.slice(0, -1)) {
21-
c.contents[segment] = c.contents[segment] ?? new Directory({});
22-
c = c.contents[segment] as Directory;
23-
}
13+
if (e.type !== "file") continue;
14+
if (!e.path.startsWith("lib/")) continue;
15+
const path = e.path.slice("lib/".length);
16+
const splitPath = path.split("/");
2417

25-
c.contents[splitPath[splitPath.length - 1]] = new File(e.getBinary())
18+
let c = root;
19+
for (const segment of splitPath.slice(0, -1)) {
20+
if (!c.has(segment)) {
21+
c.set(segment, new Map());
22+
}
23+
c = c.get(segment) as TreeNode;
2624
}
25+
26+
27+
c.set(splitPath[splitPath.length - 1], e.getBinary());
2728
}
2829

29-
return dirs;
30+
return convert(root);
31+
}
32+
33+
type TreeNode = Map<string, TreeNode | Uint8Array>;
34+
35+
function convert(node: TreeNode): Directory {
36+
return new Directory(
37+
[...node.entries()].map(([key, value]) => {
38+
if (value instanceof Uint8Array) {
39+
return [key, new File(value)];
40+
} else {
41+
return [key, convert(value)];
42+
}
43+
})
44+
)
3045
}

src/wasi/LICENSE

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/wasi/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/wasi/fd.ts

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/wasi/fs_core.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)