feat: port list_languages command to use configurable file types

This commit is contained in:
CJ van den Berg 2025-07-14 13:26:40 +02:00
parent 6df9391b50
commit 53c9523617
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -1,5 +1,6 @@
const std = @import("std");
const syntax = @import("syntax");
const file_type_config = @import("file_type_config");
const builtin = @import("builtin");
const RGB = @import("color").RGB;
@ -16,7 +17,8 @@ pub fn list(allocator: std.mem.Allocator, writer: anytype, tty_config: std.io.tt
var max_formatter_len: usize = 0;
var max_extensions_len: usize = 0;
for (syntax.FileType.file_types) |file_type| {
for (syntax.FileType.static_file_types) |static_file_type| {
const file_type = try file_type_config.get(static_file_type.name) orelse unreachable;
max_language_len = @max(max_language_len, file_type.name.len);
max_langserver_len = @max(max_langserver_len, args_string_length(file_type.language_server));
max_formatter_len = @max(max_formatter_len, args_string_length(file_type.formatter));
@ -31,10 +33,11 @@ pub fn list(allocator: std.mem.Allocator, writer: anytype, tty_config: std.io.tt
try tty_config.setColor(writer, .reset);
try writer.writeAll("\n");
for (syntax.FileType.file_types) |file_type| {
for (syntax.FileType.static_file_types) |static_file_type| {
const file_type = try file_type_config.get(static_file_type.name) orelse unreachable;
try writer.writeAll(" ");
try setColorRgb(writer, file_type.color);
try writer.writeAll(file_type.icon);
try setColorRgb(writer, file_type.color orelse static_file_type.color);
try writer.writeAll(file_type.icon orelse static_file_type.icon);
try tty_config.setColor(writer, .reset);
try writer.writeAll(" ");
try write_string(writer, file_type.name, max_language_len + 1);