summaryrefslogtreecommitdiff
path: root/ted.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-10-19 10:45:34 -0400
committerpommicket <pommicket@gmail.com>2023-10-19 10:45:34 -0400
commit69d702f2076930b8cc88c73420fc849eb4b807ce (patch)
tree41547166457ba5b0710f077f98eba3ae37872404 /ted.c
parent30f37caf7d9facf7698d01ef77d7da93e7316103 (diff)
editorconfig seems to be working
Diffstat (limited to 'ted.c')
-rw-r--r--ted.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/ted.c b/ted.c
index b704187..2d09574 100644
--- a/ted.c
+++ b/ted.c
@@ -238,6 +238,7 @@ static int applicable_configs_cmp(void *context, const void *av, const void *bv)
void ted_compute_settings(Ted *ted, const char *path, Language language, Settings *settings) {
settings_free(settings);
+ u32 root_editorconfig = 0;
if (path && *path) {
// check for .editorconfig
char editorconfig[2048];
@@ -249,11 +250,27 @@ void ted_compute_settings(Ted *ted, const char *path, Language language, Setting
config_read(ted, editorconfig, CONFIG_EDITORCONFIG);
}
}
+
+ // find root editorconfig
+ for (u32 i = 0; i < arr_len(ted->all_configs); i++) {
+ Config *cfg = &ted->all_configs[i];
+ if (cfg->format != CONFIG_EDITORCONFIG) continue;
+ if (!cfg->is_editorconfig_root) continue;
+ char dirname[4096];
+ strbuf_cpy(dirname, rc_str(cfg->source, ""));
+ path_dirname(dirname);
+ if (str_has_path_prefix(path, dirname))
+ root_editorconfig = max_u32(root_editorconfig, (u32)rc_str_len(cfg->source));
+ }
}
u32 *applicable_configs = NULL;
for (u32 i = 0; i < arr_len(ted->all_configs); i++) {
Config *cfg = &ted->all_configs[i];
+ if (cfg->format == CONFIG_EDITORCONFIG && rc_str_len(cfg->source) < root_editorconfig) {
+ // ignore this since there's a root .editorconfig closer to `path`.
+ continue;
+ }
if (config_applies_to(cfg, path, language)) {
arr_add(applicable_configs, i);
}