Skip to content

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

Merged
merged 5 commits into from
Jun 6, 2025

Conversation

lerouxb
Copy link
Contributor

@lerouxb lerouxb commented Jun 3, 2025

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:

~/mongo/mongosh/packages/browser-runtime-core % USE_NEW_AUTOCOMPLETE=true npm test

I also narrowed some types along the way just to make porting tests a bit easier without requiring all of ShellInstanceState, for example.

getDatabaseCompletions: (dbName: string) => string[] | Promise<string[]>;
}

export type NewShellCommandAutocompleteParameters = Pick<
Copy link
Contributor Author

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;
Copy link
Contributor Author

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..

@lerouxb lerouxb force-pushed the direct-commands branch 3 times, most recently from 418b8a0 to a0b44cb Compare June 3, 2025 16:40
@lerouxb lerouxb force-pushed the direct-commands branch from a0b44cb to 052118d Compare June 4, 2025 10:22
@lerouxb lerouxb force-pushed the direct-commands branch from e6eb06f to 86bb781 Compare June 4, 2025 11:30
@lerouxb lerouxb changed the title feat: port autocomplete direct commands and browser-runtime-core to the new autocomplete MONGOSH-2205 MONGOSH-2035 feat: port autocomplete direct commands and browser-runtime-core to the new autocomplete MONGOSH-2205 MONGOSH-2035 MONGOSH-2206 Jun 4, 2025

return dbNames.filter(
(name) =>
name.toLowerCase().startsWith(prefix) && !CONTROL_CHAR_REGEXP.test(name)
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@lerouxb lerouxb merged commit 82bdf25 into main Jun 6, 2025
118 of 124 checks passed
@lerouxb lerouxb deleted the direct-commands branch June 6, 2025 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants