Skip to content

Commit a3a4d97

Browse files
committed
remove the check from here, we'll add it to mongodb-ts-autocomplete
1 parent b25507b commit a3a4d97

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

packages/cli-repl/src/mongosh-repl.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ import { Script, createContext, runInContext } from 'vm';
4949
import { installPasteSupport } from './repl-paste-support';
5050
import util from 'util';
5151

52-
import type {
53-
AutocompletionContext,
54-
MongoDBAutocompleter,
55-
} from '@mongodb-js/mongodb-ts-autocomplete';
52+
import type { MongoDBAutocompleter } from '@mongodb-js/mongodb-ts-autocomplete';
5653

5754
declare const __non_webpack_require__: any;
5855

@@ -143,23 +140,6 @@ function transformAutocompleteResults(
143140
return [results.map((result) => result.result), line];
144141
}
145142

146-
function hasActiveConnection(
147-
autocompletionContext: AutocompletionContext
148-
): boolean {
149-
try {
150-
// mongodb-ts-autocomplete uses this to find the active connection. If it
151-
// errors, then it means that (at least right now) it is not possible for us
152-
// to determine the active connection.
153-
autocompletionContext.currentDatabaseAndConnection();
154-
return true;
155-
} catch (err: any) {
156-
if (err.name === 'MongoshInvalidInputError') {
157-
return false;
158-
}
159-
throw err;
160-
}
161-
}
162-
163143
/**
164144
* An instance of a `mongosh` REPL, without any of the actual I/O.
165145
* Specifically, code called by this class should not do any
@@ -460,7 +440,6 @@ class MongoshNodeRepl implements EvaluationListener {
460440

461441
const origReplCompleter = promisify(repl.completer.bind(repl)); // repl.completer is callback-style
462442

463-
let autocompletionContext: AutocompletionContext;
464443
let newMongoshCompleter: MongoDBAutocompleter | undefined;
465444
let oldMongoshCompleter: (
466445
line: string
@@ -496,17 +475,13 @@ class MongoshNodeRepl implements EvaluationListener {
496475
'@mongodb-js/mongodb-ts-autocomplete'
497476
);
498477

499-
autocompletionContext = instanceState.getAutocompletionContext();
478+
const autocompletionContext =
479+
instanceState.getAutocompletionContext();
500480
newMongoshCompleter = new MongoDBAutocompleter({
501481
context: autocompletionContext,
502482
});
503483
}
504484

505-
// mongodb-ts-autocomplete requires a connection and a schema
506-
if (!hasActiveConnection(autocompletionContext)) {
507-
return [[], text];
508-
}
509-
510485
const results = await newMongoshCompleter.autocomplete(text);
511486
const transformed = transformAutocompleteResults(text, results);
512487
return transformed;

0 commit comments

Comments
 (0)