Skip to content

Commit 118b5e1

Browse files
committed
html: add support for self-closing tags under <svg>
1 parent 8585d86 commit 118b5e1

8 files changed

Lines changed: 122 additions & 54 deletions

File tree

build.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@ pub fn build(b: *std.Build) !void {
3434
.root_source_file = b.path("src/cli.zig"),
3535
.target = target,
3636
.optimize = optimize,
37+
.single_threaded = true,
3738
});
3839

40+
const verbose_logging = b.option(bool, "log", "Enable verbose logging also in release modes") orelse false;
41+
const scopes = b.option([]const []const u8, "scope", "Enable this scope (all scopes are enabled when none is specified through this option), can be used multiple times") orelse &[0][]const u8{};
42+
const options = b.addOptions();
43+
options.addOption(bool, "verbose_logging", verbose_logging);
44+
options.addOption([]const []const u8, "enabled_scopes", scopes);
45+
3946
const folders = b.dependency("known-folders", .{});
4047
const lsp = b.dependency("zig-lsp-kit", .{});
4148

@@ -45,6 +52,7 @@ pub fn build(b: *std.Build) !void {
4552
folders.module("known-folders"),
4653
);
4754
super_cli.root_module.addImport("lsp", lsp.module("lsp"));
55+
super_cli.root_module.addOptions("build_options", options);
4856

4957
const run_exe = b.addRunArtifact(super_cli);
5058
if (b.args) |args| run_exe.addArgs(args);
@@ -66,6 +74,7 @@ pub fn build(b: *std.Build) !void {
6674
folders.module("known-folders"),
6775
);
6876
super_cli_check.root_module.addImport("lsp", lsp.module("lsp"));
77+
super_cli_check.root_module.addOptions("build_options", options);
6978

7079
const check = b.step("check", "Check if Super compiles");
7180
check.dependOn(&super_cli_check.step);
@@ -105,6 +114,7 @@ pub fn build(b: *std.Build) !void {
105114
folders.module("known-folders"),
106115
);
107116
super_exe_release.root_module.addImport("lsp", lsp.module("lsp"));
117+
super_exe_release.root_module.addOptions("build_options", options);
108118

109119
const target_output = b.addInstallArtifact(super_exe_release, .{
110120
.dest_dir = .{
@@ -133,6 +143,7 @@ pub fn build(b: *std.Build) !void {
133143

134144
super_wasm_lsp.root_module.addImport("super", super);
135145
super_wasm_lsp.root_module.addImport("lsp", lsp.module("lsp"));
146+
super_wasm_lsp.root_module.addOptions("build_options", options);
136147

137148
const wasm = b.step("wasm", "Generate WASM Build of the LSP for VSCode");
138149
const target_output = b.addInstallArtifact(super_wasm_lsp, .{

src/Ast.zig

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ pub fn init(
515515
const html_node_idx = cursor.idx;
516516
const depth = cursor.depth;
517517

518-
switch (html_node.tag) {
518+
switch (html_node.kind) {
519519
.element,
520520
.element_void,
521521
.element_self_closing,
@@ -699,6 +699,9 @@ const Parser = struct {
699699
const block_context = block_mode and depth == 1;
700700
if (block_context) tmp_result.kind = .block;
701701

702+
// used to detect when a block is missing an id
703+
var seen_id_attr = false;
704+
702705
var start_tag = elem.startTag(p.src, .superhtml);
703706
const tag_name = start_tag.name_span;
704707

@@ -858,9 +861,6 @@ const Parser = struct {
858861
.root, .extend, .super_block, .super => unreachable,
859862
}
860863

861-
var attrs_seen = std.StringHashMap(Span).init(gpa);
862-
defer attrs_seen.deinit();
863-
864864
var last_attr_end = tag_name.end;
865865
var scripted_attrs_span: Node.ScriptedAttrsSpan = .{
866866
.start = @intCast(p.scripted_attrs.items.len),
@@ -963,6 +963,7 @@ const Parser = struct {
963963
}
964964

965965
tmp_result.id_template_parentid = attr;
966+
seen_id_attr = true;
966967

967968
continue;
968969
}
@@ -1489,8 +1490,7 @@ const Parser = struct {
14891490
else => {},
14901491
}
14911492

1492-
// TODO: see if the error reporting order makes sense
1493-
if (tmp_result.kind.role() == .block and !attrs_seen.contains("id")) {
1493+
if (tmp_result.kind.role() == .block and !seen_id_attr) {
14941494
try p.errors.append(gpa, .{
14951495
.kind = .block_missing_id,
14961496
.main_location = tag_name,
@@ -1520,9 +1520,8 @@ const Parser = struct {
15201520
// having inserted the node in the tree. anything that
15211521
// can be tested sooner should go in self.buildNode().
15221522
//
1523-
// NOTE: We can only validate constraints *upwards* with regards
1524-
// to the SuperTree.
1525-
1523+
// NOTE: We can only validate constraints *upwards*, as the
1524+
// rest of the tree has not yet been built.
15261525
switch (node.kind.role()) {
15271526
.root => unreachable,
15281527
.element => {},

src/cli.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
3+
const build_options = @import("build_options");
34
const super = @import("super");
45
const logging = @import("cli/logging.zig");
56
const fmt_exe = @import("cli/fmt.zig");
@@ -13,6 +14,10 @@ pub const known_folders_config = .{
1314
};
1415

1516
pub const std_options: std.Options = .{
17+
.log_level = if (build_options.verbose_logging)
18+
.debug
19+
else
20+
std.log.default_level,
1621
.logFn = logging.logFn,
1722
};
1823

src/cli/logging.zig

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
3+
const build_options = @import("build_options");
34
const folders = @import("known-folders");
45

56
pub var log_file: ?std.fs.File = switch (builtin.target.os.tag) {
67
.linux, .macos => std.io.getStdErr(),
78
else => null,
89
};
910

11+
// const enabled_scopes = blk: {
12+
// const len = build_options.enabled_scopes.len;
13+
// const scopes: [len]@Type(.EnumLiteral) = undefined;
14+
// for (build_options.enabled_scopes, &scopes) |s, *e| {
15+
// e.* = @Type()
16+
// }
17+
// };
18+
1019
pub fn logFn(
1120
comptime level: std.log.Level,
1221
comptime scope: @Type(.EnumLiteral),
1322
comptime format: []const u8,
1423
args: anytype,
1524
) void {
16-
// if (scope != .ws and scope != .network) return;
25+
if (build_options.enabled_scopes.len > 0) {
26+
inline for (build_options.enabled_scopes) |es| {
27+
if (comptime std.mem.eql(u8, es, @tagName(scope))) {
28+
break;
29+
}
30+
} else return;
31+
}
1732

1833
const l = log_file orelse return;
1934
const scope_prefix = "(" ++ @tagName(scope) ++ "): ";

src/cli/lsp.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ pub const Handler = struct {
277277

278278
const doc = self.files.getPtr(request.textDocument.uri) orelse return null;
279279

280+
if (doc.html.errors.len != 0) {
281+
return null;
282+
}
283+
280284
log.debug("format!!", .{});
281285

282286
var buf = std.ArrayList(u8).init(self.gpa);

0 commit comments

Comments
 (0)