@@ -80,7 +80,8 @@ get_config_dir_mtime(const std::filesystem::path& path,
8080 return retval;
8181 }
8282
83- for (const auto & sib : std::filesystem::directory_iterator (parent)) {
83+ for (const auto & sib : std::filesystem::directory_iterator (parent, ec))
84+ {
8485 if (!sib.is_directory ()) {
8586 continue ;
8687 }
@@ -110,7 +111,7 @@ static std::optional<std::string>
110111get_impl (const std::filesystem::path& path)
111112{
112113 const auto & cfg = injector::get<const config&>();
113- std::vector<std::tuple<time64_t , bool , const impl*>> candidates;
114+ std::vector<std::tuple<time64_t , bool , bool , const impl*>> candidates;
114115
115116 log_debug (" editor impl count: %zu" , cfg.c_impls .size ());
116117 for (const auto & [name, impl] : cfg.c_impls ) {
@@ -127,25 +128,60 @@ get_impl(const std::filesystem::path& path)
127128 .ignore_error ()
128129 .has_value ()
129130 : false ;
131+ auto disfavors = impl.i_disfavors .pp_value
132+ ? impl.i_disfavors .pp_value ->find_in (path.string ())
133+ .ignore_error ()
134+ .has_value ()
135+ : false ;
136+ auto config_dir_mtime
137+ = get_config_dir_mtime (path, impl.i_config_dir );
138+ log_info (" config-dir-mtime: %llu, prefers: %s, disfavors: %s" ,
139+ config_dir_mtime,
140+ prefers ? " yes" : " no" ,
141+ disfavors ? " yes" : " no" );
130142 candidates.emplace_back (
131- get_config_dir_mtime (path, impl. i_config_dir ), prefers , &impl);
143+ config_dir_mtime, prefers, disfavors , &impl);
132144 }
133145 }
134146
135147 std::sort (candidates.begin (),
136148 candidates.end (),
137149 [](const auto & lhs, const auto & rhs) {
138- const auto & [lmtime, lprefers, limpl] = lhs;
139- const auto & [rmtime, rprefers, rimpl] = rhs;
150+ const auto & [lmtime, lprefers, ldisfavors, limpl] = lhs;
151+ const auto & [rmtime, rprefers, rdisfavors, rimpl] = rhs;
152+
153+ if (lmtime > rmtime) {
154+ return true ;
155+ }
156+
157+ if (lmtime < rmtime) {
158+ return false ;
159+ }
160+
161+ if (lprefers && !rprefers) {
162+ return true ;
163+ }
164+
165+ if (!lprefers && rprefers) {
166+ return false ;
167+ }
168+
169+ if (ldisfavors && !rdisfavors) {
170+ return false ;
171+ }
172+
173+ if (!ldisfavors && rdisfavors) {
174+ return true ;
175+ }
140176
141- return lmtime > rmtime || (lmtime == rmtime && lprefers) ;
177+ return limpl-> i_command < rimpl-> i_command ;
142178 });
143179
144180 if (candidates.empty ()) {
145181 return std::nullopt ;
146182 }
147183
148- return std::get<2 >(candidates.front ())->i_command ;
184+ return std::get<3 >(candidates.front ())->i_command ;
149185}
150186
151187Result<void , std::string>
0 commit comments