Skip to content

[repl] Don't autocomplete globals after "import " #4608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions py/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print
++str;
}

// after "import", suggest built-in modules
static const char import_str[] = "import ";
if (len >= 7 && !memcmp(org_str, import_str, 7)) {
obj = MP_OBJ_NULL;
}

// look for matches
size_t match_len;
qstr q_first, q_last;
Expand All @@ -291,19 +297,12 @@ size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print
if (q_first == 0) {
// If there're no better alternatives, and if it's first word
// in the line, try to complete "import".
static const char import_str[] = "import ";
if (s_start == org_str && s_len > 0) {
if (memcmp(s_start, import_str, s_len) == 0) {
*compl_str = import_str + s_len;
return sizeof(import_str) - 1 - s_len;
}
}
// after "import", suggest built-in modules
if (len >= 7 && !memcmp(org_str, import_str, 7)) {
obj = NULL;
match_str = find_completions(
s_start, s_len, obj, &match_len, &q_first, &q_last);
}
if (q_first == 0) {
*compl_str = " ";
return s_len ? 0 : 4;
Expand Down