-
Notifications
You must be signed in to change notification settings - Fork 76
feat: port autocomplete direct commands and browser-runtime-core to the new autocomplete MONGOSH-2205 MONGOSH-2035 MONGOSH-2206 #2464
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
Conversation
getDatabaseCompletions: (dbName: string) => string[] | Promise<string[]>; | ||
} | ||
|
||
export type NewShellCommandAutocompleteParameters = Pick< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know how obvious it is from the diff, but this is just new types everywhere ShellCommand* was with that now the legacy type. We'll have to just clean this up when we remove the old autocompleter.
Again: open to suggestions for how to rather do this.
async function showCompleter( | ||
params: ShellCommandAutocompleteParameters, | ||
// eslint-disable-next-line no-control-regex | ||
const CONTROL_CHAR_REGEXP = /[\x00-\x1F\x7F-\x9F]/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now the third copy of this regex..
418b8a0
to
a0b44cb
Compare
|
||
return dbNames.filter( | ||
(name) => | ||
name.toLowerCase().startsWith(prefix) && !CONTROL_CHAR_REGEXP.test(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For use we'd probably want to be a bit stricter and only allow alphanumeric names, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied this from what we had, but I can change it.
This essentially reuses (as in makes a copy of) the existing direct shell command autocompleter and then ports it to use the new AutocompleteContext vs the old AutocompleteParams. Unfortunately it meant more duplicate types and props between the old and new than I'd really like, but this way at least means we can have the feature flag and keep the old way around for now. But I'm open to suggestion.
I also fixed up the code that initialises the autocompleter and uses it, moving to packages/autocomplete in the process. This way the common code can be reused between the cli and browser repls. It lives in packages/autocomplete. The idea is we'd remove the old autocomplete code from there and keep this new wrapper.
Then to validate that the above design works I ported usage of autocomplete in browser-runtime-core to do the same thing we do in cli-repl. I ported its tests too, so you can do:
I also narrowed some types along the way just to make porting tests a bit easier without requiring all of ShellInstanceState, for example.