Change argument ordering for ‘scope_variables’

Generally we should always provide a base environment, since the scoped variables are format strings. The filtering scope selector is however optional, and we do not have one when executing commands outside an fi;e/editor context.
This commit is contained in:
Allan Odgaard
2013-05-11 19:37:18 +07:00
parent 5eaa0a9d94
commit 8b3f05485d
8 changed files with 18 additions and 16 deletions

View File

@@ -43,7 +43,7 @@ OAK_DEBUG_VAR(AppController_Commands);
{
std::map<std::string, std::string> map = oak::basic_environment();
map << item->bundle_variables();
map = bundles::scope_variables(scope::context_t(), map);
map = bundles::scope_variables(map);
map = variables_for_path(NULL_STR, scope::scope_t(), map);
document::run(parse_command(item), ng::buffer_t(), ng::ranges_t(), document::document_ptr(), map);
}

View File

@@ -821,7 +821,7 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
{
std::map<std::string, std::string> map = oak::basic_environment();
map << [self variables] << item->bundle_variables();
map = bundles::scope_variables(scope::context_t(), map);
map = bundles::scope_variables(map);
map = variables_for_path(to_s((NSString*)[self.selectedPaths firstObject]), scope::scope_t(), map);
document::run(parse_command(item), ng::buffer_t(), ng::ranges_t(), [self.selectedPaths count] == 1 ? document::create(map["TM_SELECTED_FILE"]) : document::document_ptr(), map);
}

View File

@@ -1125,7 +1125,7 @@ doScroll:
if([self.delegate respondsToSelector:@selector(variables)])
res << [self.delegate variables];
res = bundles::scope_variables([self scopeContext], res);
res = bundles::scope_variables(res, [self scopeContext]);
res = variables_for_path(document->path(), [self scopeContext].right, res);
return res;
}

View File

@@ -123,7 +123,7 @@ namespace bundles
return res;
}
std::map<std::string, std::string> scope_variables (scope::context_t const& scope, std::map<std::string, std::string> const& base)
std::map<std::string, std::string> scope_variables (std::map<std::string, std::string> const& base, scope::context_t const& scope)
{
std::map<std::string, std::string> res = base;
std::vector<item_ptr> const& items = query(kFieldSettingName, "shellVariables", scope, kItemTypeSettings, oak::uuid_t(), false);

View File

@@ -22,7 +22,7 @@ namespace bundles
PUBLIC bool missing_requirement (item_ptr const& item, std::map<std::string, std::string>& environment, required_command_t* failedRequirement);
PUBLIC std::map<std::string, std::string> scope_variables (scope::context_t const& scope, std::map<std::string, std::string> const& base = std::map<std::string, std::string>());
PUBLIC std::map<std::string, std::string> scope_variables (std::map<std::string, std::string> const& base, scope::context_t const& scope = scope::context_t());
PUBLIC plist::any_t value_for_setting (std::string const& setting, scope::context_t const& scope, item_ptr* match = NULL);
PUBLIC std::vector<item_ptr> grammars_for_path (std::string const& path);

View File

@@ -131,24 +131,26 @@ public:
void test_environment_format_strings ()
{
TS_ASSERT_EQUALS(bundles::scope_variables("")["TEST"], "foo");
TS_ASSERT_EQUALS(bundles::scope_variables("source.c++")["TEST"], "foo:bar");
TS_ASSERT_EQUALS(bundles::scope_variables("source.any")["TM_COMMENT_STYLE"], "Base Environment");
TS_ASSERT_EQUALS(bundles::scope_variables("source.ruby")["TM_COMMENT_STYLE"], "Ruby Environment");
std::map<std::string, std::string> base;
TS_ASSERT_EQUALS(bundles::scope_variables("text.plain")["PATH"], "/usr/bin:/bin:/sbin");
TS_ASSERT_EQUALS(bundles::scope_variables("text.tex")["PATH"], "/usr/bin:/bin:/sbin:/usr/texbin");
TS_ASSERT_EQUALS(bundles::scope_variables(base, "")["TEST"], "foo");
TS_ASSERT_EQUALS(bundles::scope_variables(base, "source.c++")["TEST"], "foo:bar");
TS_ASSERT_EQUALS(bundles::scope_variables(base, "source.any")["TM_COMMENT_STYLE"], "Base Environment");
TS_ASSERT_EQUALS(bundles::scope_variables(base, "source.ruby")["TM_COMMENT_STYLE"], "Ruby Environment");
TS_ASSERT_EQUALS(bundles::scope_variables(base, "text.plain")["PATH"], "/usr/bin:/bin:/sbin");
TS_ASSERT_EQUALS(bundles::scope_variables(base, "text.tex")["PATH"], "/usr/bin:/bin:/sbin:/usr/texbin");
}
void test_v1_variable_shadowing ()
{
std::map<std::string, std::string> baseEnv = bundles::scope_variables("");
auto baseEnv = bundles::scope_variables(std::map<std::string, std::string>(), "");
TS_ASSERT_EQUALS(baseEnv["TM_COMMENT_START"], "/*");
TS_ASSERT_EQUALS(baseEnv["TM_COMMENT_STOP"], "*/");
TS_ASSERT_EQUALS(baseEnv["TM_COMMENT_START_2"], "//");
TS_ASSERT(baseEnv.find("TM_COMMENT_STOP_2") == baseEnv.end());
std::map<std::string, std::string> rubyEnv = bundles::scope_variables("source.ruby");
std::map<std::string, std::string> rubyEnv = bundles::scope_variables(std::map<std::string, std::string>(), "source.ruby");
TS_ASSERT_EQUALS(rubyEnv["TM_COMMENT_START"], "# ");
TS_ASSERT(rubyEnv.find("TM_COMMENT_STOP") == rubyEnv.end());
TS_ASSERT_EQUALS(rubyEnv["TM_COMMENT_START_2"], "==begin");
@@ -173,7 +175,7 @@ public:
void test_require ()
{
TS_ASSERT_EQUALS(bundles::scope_variables("text")["DialogPath"], jail.path("Bundles/Dialog.tmbundle/Support/bin"));
TS_ASSERT_EQUALS(bundles::scope_variables(std::map<std::string, std::string>(), "text")["DialogPath"], jail.path("Bundles/Dialog.tmbundle/Support/bin"));
}
void test_wrappers ()

View File

@@ -80,7 +80,7 @@ namespace ng
env << editor_variables(scopeAttributes) << item->bundle_variables();
if(_document)
env << _document->document_variables();
env = bundles::scope_variables(this->scope(scopeAttributes), env);
env = bundles::scope_variables(env, this->scope(scopeAttributes));
env = variables_for_path(_document ? _document->path() : path::home(), this->scope(scopeAttributes).right, env);
env["TM_CURRENT_WORD"] = prefix;

View File

@@ -151,7 +151,7 @@ namespace filter
void run (bundles::item_ptr filter, std::string const& path, io::bytes_ptr content, callback_ptr context)
{
std::map<std::string, std::string> variables = file::path_variables(path);
command::runner_ptr runner = command::runner(parse_command(filter), ng::buffer_t(), ng::ranges_t(), bundles::scope_variables(file::path_attributes(path), variables << filter->bundle_variables()), command::delegate_ptr(new event_delegate_t(content, context)));
command::runner_ptr runner = command::runner(parse_command(filter), ng::buffer_t(), ng::ranges_t(), bundles::scope_variables(variables << filter->bundle_variables(), file::path_attributes(path)), command::delegate_ptr(new event_delegate_t(content, context)));
runner->launch();
}