Skip to content

Commit 38c63ff

Browse files
committed
don't include the shell api twice
1 parent 1965782 commit 38c63ff

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/mongodb-ts-autocomplete/scripts/extract-types.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
/* eslint-disable no-console */
22
import { promises as fs } from 'fs';
33
import path from 'path';
4-
import { api as ShellApiText } from '@mongosh/shell-api/api';
5-
6-
function replaceImports(code: string) {
7-
// This just makes it possible to work on mql.ts because then the
8-
// IDE finds the import.
9-
return code.replace(/'bson'/g, "'/bson.ts'");
10-
}
4+
import { replaceImports } from '../src/autocompleter';
115

126
async function loadSources(sources: Record<string, string>) {
137
const result: Record<string, string> = {};
@@ -25,7 +19,6 @@ async function run() {
2519
'/mql.ts': path.join(__dirname, '..', 'src', 'fixtures', 'mql.ts'),
2620
};
2721
const files = await loadSources(input);
28-
files['/shell-api.ts'] = replaceImports(ShellApiText);
2922
const code = `
3023
const files = ${JSON.stringify(files)};
3124
export default files;

packages/mongodb-ts-autocomplete/src/autocompleter.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Autocompleter from '@mongodb-js/ts-autocomplete';
22
import type { AutoCompletion } from '@mongodb-js/ts-autocomplete';
33
import autocompleteTypes from './fixtures/autocomplete-types';
4+
import { api as ShellApiText } from '@mongosh/shell-api/api';
45

56
import type { JSONSchema } from 'mongodb-schema';
67
import { toTypescriptTypeDefinition } from 'mongodb-schema';
@@ -13,6 +14,12 @@ import {
1314
import { CachingAutocompletionContext } from './autocompletion-context';
1415
import type { AutocompletionContext } from './autocompletion-context';
1516

17+
export function replaceImports(code: string) {
18+
// This just makes it possible to work on mql.ts because then the
19+
// IDE finds the import.
20+
return code.replace(/'bson'/g, "'/bson.ts'");
21+
}
22+
1623
type MongoDBAutocompleterOptions = {
1724
context: AutocompletionContext;
1825
};
@@ -159,7 +166,10 @@ export class MongoDBAutocompleter {
159166

160167
this.connectionSchemas = Object.create(null);
161168

162-
this.autocompleter.updateCode(autocompleteTypes);
169+
this.autocompleter.updateCode({
170+
...autocompleteTypes,
171+
'/shell-api.ts': replaceImports(ShellApiText),
172+
});
163173
}
164174

165175
addConnection(connectionId: string): ConnectionSchema {

0 commit comments

Comments
 (0)