fix: don't error loop if the configured file type parser is not found

This commit is contained in:
CJ van den Berg 2025-07-14 17:38:20 +02:00
parent 1ea3575d61
commit a540d2bf36
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -179,9 +179,9 @@ fn guess_first_line(content: []const u8) ?@This() {
return null;
}
pub fn create_syntax(file_type_config: @This(), allocator: std.mem.Allocator, query_cache: *syntax.QueryCache) !*syntax {
pub fn create_syntax(file_type_config: @This(), allocator: std.mem.Allocator, query_cache: *syntax.QueryCache) !?*syntax {
return syntax.create(
syntax.FileType.get_by_name_static(file_type_config.parser orelse file_type_config.name) orelse return error.FileTypeNotFound,
syntax.FileType.get_by_name_static(file_type_config.parser orelse file_type_config.name) orelse return null,
allocator,
query_cache,
);
@ -192,7 +192,7 @@ pub fn create_syntax_guess_file_type(
content: []const u8,
file_path: ?[]const u8,
query_cache: *syntax.QueryCache,
) !*syntax {
) !?*syntax {
const file_type = guess(file_path, content) orelse return error.NotFound;
return create_syntax(file_type, allocator, query_cache);
}