File path settings now rank higher than scope settings

A file setting like “src/*.cc” is arguably more specific (and thus more local) than targeting the scope “source.c++”, so it makes sense that the file settings rank higher than scope settings.

Some users also find it natural to target file extensions over scopes, but as TM will store some learned settings with a scope selector, it would previously lead to confusion, when a user was unable to e.g. change tab size for “*.php” (because TM had a learned setting for “source.php”).
This commit is contained in:
Allan Odgaard
2013-12-14 12:56:55 +07:00
parent 7d91fd8322
commit 45db36234c
2 changed files with 30 additions and 1 deletions

View File

@@ -186,7 +186,7 @@ namespace
if(section->scope_selector.does_match(scope, &rank))
orderScopeMatches.emplace(rank, section);
}
else if(!section->has_file_glob || section->file_glob.does_match(path == NULL_STR ? directory : path))
else if(!section->has_file_glob)
{
iterate(pair, section->variables)
expand_variable(pair->first, pair->second, variables);
@@ -200,6 +200,18 @@ namespace
expand_variable(pair->first, pair->second, variables);
}
citerate(file, paths(directory))
{
citerate(section, sections(*file))
{
if(section->has_file_glob && section->file_glob.does_match(path == NULL_STR ? directory : path))
{
iterate(pair, section->variables)
expand_variable(pair->first, pair->second, variables);
}
}
}
pthread_mutex_unlock(&mutex);
variables.erase("CWD");

View File

@@ -24,3 +24,20 @@ void test_scope_selector_ranking ()
OAK_ASSERT_EQ(settings_for_path(jail.path("foo/bar/file"), "text.markup").get("mySetting"), "6");
OAK_ASSERT_EQ(settings_for_path(jail.path("foo/bar/file"), "text.markup.html").get("mySetting"), "8");
}
void test_glob_and_scope_selector_ranking ()
{
test::jail_t jail;
jail.set_content(".tm_properties", "mySetting = 1\n[ text ]\nmySetting = 2\n");
jail.set_content("local/.tm_properties", "mySetting = 3\n[ text ]\nmySetting = 4\n[ *.txt ]\nmySetting = 5\n");
OAK_ASSERT_EQ(settings_for_path(jail.path("file.foo") ).get("mySetting"), "1");
OAK_ASSERT_EQ(settings_for_path(jail.path("file.txt") ).get("mySetting"), "1");
OAK_ASSERT_EQ(settings_for_path(jail.path("file.foo"), "text").get("mySetting"), "2");
OAK_ASSERT_EQ(settings_for_path(jail.path("file.txt"), "text").get("mySetting"), "2");
OAK_ASSERT_EQ(settings_for_path(jail.path("local/file.foo") ).get("mySetting"), "3");
OAK_ASSERT_EQ(settings_for_path(jail.path("local/file.txt") ).get("mySetting"), "5");
OAK_ASSERT_EQ(settings_for_path(jail.path("local/file.foo"), "text").get("mySetting"), "4");
OAK_ASSERT_EQ(settings_for_path(jail.path("local/file.txt"), "text").get("mySetting"), "5");
}