Skip to content
Merged
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
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.zig text=auto eol=lf
* text=auto eol=lf
23 changes: 8 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ name: CI

on:
push:
paths:
- "**.zig"
branches:
- main
pull_request:
paths:
- "**.zig"
schedule:
- cron: "0 0 * * *"
branches:
- main
workflow_dispatch:

jobs:
Expand All @@ -18,16 +16,11 @@ jobs:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive
- uses: goto-bus-stop/setup-zig@v2
with:
version: master
- name: Checkout
uses: actions/checkout@v4

- run: zig version
- run: zig env
- name: Setup Zig
uses: mlugg/setup-zig@v2

- name: Build
run: zig build
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/zig-out
/zig-cache
/saved_logs
/repos
zig-out
zig-cache
.zig-cache
saved_logs
repos
node_modules
/.env
.env
d_*.log
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ For a listing of build options, use 'zig build --help'.
```

# .env
if a .env file is present at project root or next to the exe, the following keys will be used as default values.

If a `.env` file is present in the current working directory, the following keys will be used as default values.

```console
zls_path=~/repos/zls/zig-out/bin/zls
zls_path=/path/to/repos/zls/zig-out/bin/zls
mode=markov
markov_training_dir=~/repos/zig/src
markov_training_dir=/path/to/repos/zig/src
```

this allows the project to be run with no args:

```console
zig build run
```
59 changes: 32 additions & 27 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const zig_lsp = b.dependency("zig-lsp", .{}).module("zig-lsp");

const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const exe = b.addExecutable(.{
.name = "sus",
.root_source_file = .{ .path = "src/main.zig" },
const block_len = b.option(
u8,
"block-len",
"how many bytes to consider when predicting the next character. " ++
"defaults to 8. " ++
"note: this may affect performance.",
) orelse 8;

const options = b.addOptions();
options.addOption(u8, "block_len", block_len);

const lsp_module = b.dependency("lsp_kit", .{}).module("lsp");

const root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "lsp", .module = lsp_module },
.{ .name = "build_options", .module = options.createModule() },
},
});

const exe = b.addExecutable(.{
.name = "sus",
.root_module = root_module,
});
exe.root_module.addImport("zig-lsp", zig_lsp);
b.installArtifact(exe);

const exe_check = b.addExecutable(.{
.name = "zls",
.root_module = root_module,
});

const check = b.step("check", "Check if sus compiles");
check.dependOn(&exe_check.step);

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
Expand All @@ -23,25 +49,4 @@ pub fn build(b: *std.Build) void {

const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);

const build_exe_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = .Debug,
});
const run_exe_tests = b.addRunArtifact(build_exe_tests);

const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_exe_tests.step);

const block_len = b.option(
u8,
"block-len",
"how many bytes to consider when predicting the next character. " ++
"defaults to 8. " ++
"note: this may affect performance.",
) orelse 8;
const options = b.addOptions();
options.addOption(u8, "block_len", block_len);
exe.root_module.addOptions("build_options", options);
}
10 changes: 6 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
.{
.name = "sus",
.name = .sus,
.version = "0.1.0",
.minimum_zig_version = "0.15.0-dev.1593+399bace2f",
.dependencies = .{
.@"zig-lsp" = .{
.url = "https://github.com/ziglibs/zig-lsp/archive/1c18c0c64b076e79385e525214a7acc4fdf7d398.tar.gz",
.hash = "12208c1385f4c1adca29fd17cc93397a60e54d5987bb27b9f961cb1945a96fc4a7e1",
.lsp_kit = .{
.url = "git+https://github.com/zigtools/lsp-kit#6031c563c1e1f30e7e2857fcd81a5d06e4a0c099",
.hash = "lsp_kit-0.1.0-bi_PL5YyCgA2QFEza6llr2Uy08QUQsWBu2wKvtr8tbLx",
},
},
.paths = .{
Expand All @@ -14,4 +15,5 @@
"LICENSE",
"README.md",
},
.fingerprint = 0x32b2a22ef62d2b4b, // Changing this has security and trust implications.
}
113 changes: 113 additions & 0 deletions server/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>sus</title>

<style>
:root {
--bg: hsl(0, 0%, 10%);
--fg: hsl(0, 0%, 90%);
}

html, body {
margin: 0;
padding: 0;

color: var(--fg);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
background-color: var(--bg);
}

main {
padding: 2rem;
}

h1 {
margin: 0;
}

table, th, td {
border: 1px solid var(--fg);
border-collapse: collapse;
}

th, td {
padding: 0.45rem 0.3rem;
}

#entries {
list-style: none;
margin: 0;
padding: 0;
}

#entries>li {
margin-top: 1rem;

border: 1.5px solid var(--fg);
border-radius: 5px;
}

header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem;
font-size: 14pt;
cursor: pointer;
}
</style>
</head>
<body>
<main>
<h1>Zig Language Server Fuzzer</h1>

<p>Note that results are not expected to be long-lasting. When documenting a result, copy the reproduction steps.</p>

<ul id="entries">
<% for (const entry of entries) { %>
<li>
<article>
<header>
<code><%= entry.stderr.slice(0, entry.stderr.indexOf("\n")) %></code>
<time datetime="<%= new Date(entry.created_at).toISOString() %>"></time>
</header>
</article>
</li>
<% } %>
</ul>
</main>

<script>
const units = [
{unit: "year", ms: 31536000000},
{unit: "month", ms: 2628000000},
{unit: "day", ms: 86400000},
{unit: "hour", ms: 3600000},
{unit: "minute", ms: 60000},
{unit: "second", ms: 1000},
];
const rtf = new Intl.RelativeTimeFormat("en", {numeric: "auto"});

function relativeTimeFromDates(relative, pivot = new Date()) {
if (!relative) return "";
const elapsed = relative.getTime() - pivot.getTime();
return relativeTimeFromElapsed(elapsed);
}

function relativeTimeFromElapsed(elapsed) {
for (const {unit, ms} of units) {
if (Math.abs(elapsed) >= ms || unit === "second") {
return rtf.format(Math.round(elapsed / ms), unit);
}
}
return "";
}


[...document.querySelectorAll("time")].map(_ => _.innerText = relativeTimeFromDates(new Date(_.dateTime)));
</script>
</body>
</html>
Loading