style: Cleaned up #partial switches.

This commit is contained in:
Spencer Brower
2026-07-30 11:12:20 -04:00
parent 25551a4fb6
commit 4d2fdf284d
4 changed files with 14 additions and 5 deletions
+1
View File
@@ -302,3 +302,4 @@ write_value :: proc(b: ^strings.Builder, a: any, escape: bool) {
strings.write_string(b, s[start:])
}
}
+7 -2
View File
@@ -78,9 +78,11 @@ Node :: struct {
// 1 for leaf nodes, 1 + len(children) for container nodes (whose children
// are stored contiguously after them in the array).
node_span :: proc(n: Node) -> int {
#partial switch n.kind {
switch n.kind {
case .Section, .Inverted, .Parent, .Block:
return 1 + len(n.children)
case .Text, .Variable, .Unescaped, .Partial:
fallthrough
case:
return 1
}
@@ -374,7 +376,7 @@ parse_section :: proc(
deindent_blocks :: proc(nodes: []Node, allocator := context.allocator) {
i := 0
for i < len(nodes) {
#partial switch nodes[i].kind {
switch nodes[i].kind {
case .Block:
if len(nodes[i].children) > 0 {
children := nodes[i].children
@@ -401,6 +403,8 @@ deindent_blocks :: proc(nodes: []Node, allocator := context.allocator) {
if len(nodes[i].children) > 0 {
deindent_blocks(nodes[i].children, allocator)
}
case .Text, .Variable, .Unescaped, .Partial:
// Do nothing
}
i += node_span(nodes[i])
}
@@ -981,3 +985,4 @@ warn_context_depth :: proc(current: Template, node: Node) {
diag := format_error(path, current.source, node.pos, msg, "", colorize = should_colorize())
log.warnf("%s", diag)
}
+3 -1
View File
@@ -269,7 +269,7 @@ compile_query :: proc(
if query == nil {
tok := extract_query_token(transmute([]byte)query_src, err_offset)
cause := fmt.tprintf("query error at byte %d (type %v)", err_offset, err_type)
#partial switch err_type {
switch err_type {
case .NodeType:
if tok != "" {
cause = fmt.tprintf(
@@ -295,6 +295,7 @@ compile_query :: proc(
cause = fmt.tprintf("query has an illegal pattern structure at byte %d", err_offset)
case .Language:
cause = "grammar language is null (broken grammar .so)"
case .None:
}
log.errorf("treesitter: %s query failed: %s", lang, cause)
@@ -458,3 +459,4 @@ helix_version_from_path :: proc(path: string) -> string {
if end <= start do return ""
return path[start:end]
}
+3 -2
View File
@@ -49,7 +49,7 @@ mount_recursive :: proc(vfs: ^VFS, current_dir: string, target_prefix: string) {
defer os.file_info_slice_delete(entries, context.allocator)
for entry in entries {
#partial switch entry.type {
switch entry.type {
case .Regular:
virtual := fmt.tprintf("%s/%s", target_prefix, entry.name)
vfs.files[virtual] = VFS_Entry {
@@ -58,7 +58,7 @@ mount_recursive :: proc(vfs: ^VFS, current_dir: string, target_prefix: string) {
case .Directory:
sub_prefix := fmt.tprintf("%s/%s", target_prefix, entry.name)
mount_recursive(vfs, entry.fullpath, sub_prefix)
case:
case .Undetermined, .Symlink, .Named_Pipe, .Socket, .Block_Device, .Character_Device:
}
}
}
@@ -109,3 +109,4 @@ vfs_entry_data :: proc(entry: VFS_Entry) -> ([]byte, bool) {
}
return data, true
}