allow files with only preprocessor directives
This commit is contained in:
parent
f5694d1d37
commit
353f62e15e
6 changed files with 27 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ zig-out
|
|||
zig-cache
|
||||
stderr.log
|
||||
__pycache__
|
||||
.venv
|
||||
|
|
1
justfile
1
justfile
|
@ -14,6 +14,7 @@ run *ARGS:
|
|||
zig build run --summary none {{flags}} -- {{ARGS}}
|
||||
|
||||
watch *ARGS:
|
||||
#!/usr/bin/bash
|
||||
watchexec -e zig,py,vert,frag,comp -c -- "just ${*@Q} && echo ok"
|
||||
|
||||
test:
|
||||
|
|
|
@ -690,7 +690,7 @@ fn findIncludedDocuments(
|
|||
const directive = parse.parsePreprocessorDirective(line) orelse continue;
|
||||
switch (directive) {
|
||||
.include => |include| {
|
||||
var include_path = line[include.path.start..include.path.end];
|
||||
const include_path = line[include.path.start..include.path.end];
|
||||
|
||||
const is_relative = !std.fs.path.isAbsolute(include_path);
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ fn Writer(comptime ChildWriter: type) type {
|
|||
self.preceded_by_space = last == ' ' or last == '\n';
|
||||
}
|
||||
|
||||
fn emitLeadingTokens(self: *Self, until: u32) !void {
|
||||
fn emitLeadingTokens(self: *Self, until: usize) !void {
|
||||
while (self.last_emit < until) {
|
||||
if (self.last_ignored >= self.ignored_tokens.len) break;
|
||||
|
||||
|
@ -180,6 +180,7 @@ fn formatNode(tree: parse.Tree, current: usize, writer: anytype) !void {
|
|||
for (children.start..children.end) |child| {
|
||||
try formatNode(tree, child, writer);
|
||||
}
|
||||
try writer.emitLeadingTokens(writer.source.len);
|
||||
try writer.emitLeadingWhitespace(writer.source.len, .{ .min = 1, .max = 1 });
|
||||
},
|
||||
|
||||
|
@ -617,6 +618,26 @@ test "format array declaration" {
|
|||
);
|
||||
}
|
||||
|
||||
test "format only preprocessor" {
|
||||
try expectIsFormatted(
|
||||
\\#version 330
|
||||
\\
|
||||
);
|
||||
try expectIsFormatted(
|
||||
\\#version 330
|
||||
\\#define FOO
|
||||
\\#define BAR
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "format only comments" {
|
||||
try expectIsFormatted(
|
||||
\\// hello world
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
fn expectIsFormatted(source: []const u8) !void {
|
||||
try expectFormat(source, source);
|
||||
}
|
||||
|
|
|
@ -787,7 +787,7 @@ pub const Dispatch = struct {
|
|||
return state.success(request.id, null);
|
||||
}
|
||||
|
||||
var locations = try state.allocator.alloc(lsp.Location, references.items.len);
|
||||
const locations = try state.allocator.alloc(lsp.Location, references.items.len);
|
||||
defer state.allocator.free(locations);
|
||||
|
||||
for (references.items, locations) |reference, *location| {
|
||||
|
|
|
@ -260,7 +260,7 @@ pub fn Extractor(comptime expected_tag: Tag, comptime T: type) type {
|
|||
pub fn extract(tree: Tree, node: u32, _: void) @This() {
|
||||
var matches = MatchFields{};
|
||||
|
||||
var children = tree.children(node);
|
||||
const children = tree.children(node);
|
||||
var current = children.start;
|
||||
|
||||
inline for (fields) |field| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue