Complete.cpp docs omissions

Missed a few. Add back an assert we didn't intend to remove
This commit is contained in:
Aaron Gyes 2016-08-16 18:23:10 -07:00
parent 9daffc7080
commit 6f53709b65
2 changed files with 34 additions and 24 deletions

View file

@ -2374,11 +2374,14 @@ static int builtin_exit(parser_t &parser, io_streams_t &streams, wchar_t **argv)
return (int)ec;
}
/// The cd builtin. Changes the current directory to the one specified or to $HOME if none is
/// specified. The directory can be relative to any directory in the CDPATH variable.
/// The cd builtin. Changes the current directory to the one specified or to $HOME if none is
/// specified. The directory can be relative to any directory in the CDPATH variable.
static int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
env_var_t dir_in;
wcstring dir;
int res = STATUS_BUILTIN_OK;
if (argv[1] == NULL) {
dir_in = env_get_string(L"HOME");
@ -2414,16 +2417,15 @@ static int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
streams.err.append(parser.current_line());
}
return STATUS_BUILTIN_ERROR;
}
if (wchdir(dir) != 0) {
res = 1;
} else if (wchdir(dir) != 0) {
struct stat buffer;
int status;
status = wstat(dir, &buffer);
if (!status && S_ISDIR(buffer.st_mode)) {
streams.err.append_format(_(L"%ls: Permission denied: '%ls'\n"), argv[0], dir.c_str());
} else {
streams.err.append_format(_(L"%ls: '%ls' is not a directory\n"), argv[0], dir.c_str());
}
@ -2432,14 +2434,13 @@ static int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
streams.err.append(parser.current_line());
}
return STATUS_BUILTIN_ERROR;
res = 1;
} else if (!env_set_pwd()) {
res = 1;
streams.err.append_format(_(L"%ls: Could not set PWD variable\n"), argv[0]);
}
if (!env_set_pwd()) {
streams.err.append_format(_(L"%ls: Could not set PWD variable\n"), argv[0]);
return STATUS_BUILTIN_ERROR;
} else
return STATUS_BUILTIN_OK;
return res;
}
/// Implementation of the builtin count command, used to count the number of arguments sent to it.

View file

@ -64,7 +64,7 @@ static const wcstring &C_(const wcstring &s) { return s; }
static void complete_load(const wcstring &name, bool reload);
// Testing apparatus.
/// Testing apparatus.
const wcstring_list_t *s_override_variable_names = NULL;
void complete_set_variable_names(const wcstring_list_t *names) {
@ -123,7 +123,7 @@ typedef struct complete_entry_opt {
}
} complete_entry_opt_t;
// Last value used in the order field of completion_entry_t.
/// Last value used in the order field of completion_entry_t.
static unsigned int kCompleteOrder = 0;
/// Struct describing a command completion.
@ -169,7 +169,7 @@ struct completion_entry_set_comparer {
typedef std::set<completion_entry_t, completion_entry_set_comparer> completion_entry_set_t;
static completion_entry_set_t completion_set;
// Comparison function to sort completions by their order field.
/// Comparison function to sort completions by their order field.
static bool compare_completions_by_order(const completion_entry_t *p1,
const completion_entry_t *p2) {
return p1->order < p2->order;
@ -190,8 +190,8 @@ const option_list_t &completion_entry_t::get_options() const {
completion_t::~completion_t() {}
// Clear the COMPLETE_AUTO_SPACE flag, and set COMPLETE_NO_SPACE appropriately depending on the
// suffix of the string.
/// Clear the COMPLETE_AUTO_SPACE flag, and set COMPLETE_NO_SPACE appropriately depending on the
/// suffix of the string.
static complete_flags_t resolve_auto_space(const wcstring &comp, complete_flags_t flags) {
complete_flags_t new_flags = flags;
if (flags & COMPLETE_AUTO_SPACE) {
@ -374,6 +374,8 @@ void append_completion(std::vector<completion_t> *completions, const wcstring &c
// Nasty hack for #1241 - since the constructor needs the completion string to resolve
// AUTO_SPACE, and we aren't providing it with the completion, we have to do the resolution
// ourselves. We should get this resolving out of the constructor.
assert(completions != NULL);
const wcstring empty;
completions->push_back(completion_t(empty, empty, match, resolve_auto_space(comp, flags)));
completion_t *last = &completions->back();
@ -692,15 +694,21 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool
}
}
/// Evaluate the argument list (as supplied by complete -a) and insert any return matching
/// completions. Matching is done using \c copy_strings_with_prefix, meaning the completion may
/// contain wildcards. Logically, this is not always the right thing to do, but I have yet to come
/// Evaluate the argument list (as supplied by complete -a) and insert any
/// return matching completions. Matching is done using @c
/// copy_strings_with_prefix, meaning the completion may contain wildcards.
/// Logically, this is not always the right thing to do, but I have yet to come
/// up with a case where this matters.
///
/// \param str The string to complete.
/// \param args The list of option arguments to be evaluated.
/// \param desc Description of the completion
/// \param flags The list into which the results will be inserted
/// @param str
/// The string to complete.
/// @param args
/// The list of option arguments to be evaluated.
/// @param desc
/// Description of the completion
/// @param flags
/// The list into which the results will be inserted
///
void completer_t::complete_from_args(const wcstring &str, const wcstring &args,
const wcstring &desc, complete_flags_t flags) {
bool is_autosuggest = (this->type() == COMPLETE_AUTOSUGGEST);
@ -829,6 +837,7 @@ static void complete_load(const wcstring &name, bool reload) {
/// Performed on main thread, from background thread. Return type is ignored.
static int complete_load_no_reload(wcstring *name) {
assert(name != NULL);
ASSERT_IS_MAIN_THREAD();
complete_load(*name, false);
return 0;
@ -1540,7 +1549,7 @@ wcstring complete_print() {
return out;
}
// Completion "wrapper" support. The map goes from wrapping-command to wrapped-command-list.
/// Completion "wrapper" support. The map goes from wrapping-command to wrapped-command-list.
static pthread_mutex_t wrapper_lock = PTHREAD_MUTEX_INITIALIZER;
typedef std::map<wcstring, wcstring_list_t> wrapper_map_t;
static wrapper_map_t &wrap_map() {
@ -1554,7 +1563,7 @@ static wrapper_map_t &wrap_map() {
return *wrapper_map;
}
// Add a new target that is wrapped by command. Example: __fish_sgrep (command) wraps grep (target).
/// Add a new target that is wrapped by command. Example: __fish_sgrep (command) wraps grep (target).
bool complete_add_wrapper(const wcstring &command, const wcstring &new_target) {
if (command.empty() || new_target.empty()) {
return false;