Skip to content

Commit

Permalink
refactor: rename internalState to instanceState
Browse files Browse the repository at this point in the history
  • Loading branch information
alenakhineika committed Sep 14, 2021
1 parent d2a9664 commit 0447e29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/cli-repl/src/cli-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class CliRepl {
input: this.input,
vscodeDir: this.shellHomeDirectory.rcPath('.vscode'),
tmpDir: this.shellHomeDirectory.roamingPath('editor'),
internalState: this.mongoshRepl.runtimeState().internalState,
instanceState: this.mongoshRepl.runtimeState().instanceState,
makeMultilineJSIntoSingleLine: makeMultilineJSIntoSingleLine // TODO: move to its own package
});
editor.activate();
Expand Down
20 changes: 10 additions & 10 deletions packages/editor/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import spawn from 'cross-spawn';
import { v4 as uuidv4 } from 'uuid';

import type { ShellUserConfig, MongoshBus } from '@mongosh/types';
import { signatures, ShellPlugin, ShellInternalState, TypeSignature } from '@mongosh/shell-api';
import { signatures, ShellPlugin, ShellInstanceState, TypeSignature } from '@mongosh/shell-api';

export interface EditorOptions {
input: Readable;
vscodeDir: string,
tmpDir: string,
internalState: ShellInternalState;
instanceState: ShellInstanceState;
makeMultilineJSIntoSingleLine: any;
}

Expand All @@ -22,22 +22,22 @@ export class Editor implements ShellPlugin {
_tmpDir: string;
_tmpDocName: string;
_tmpDoc: string;
_internalState: ShellInternalState;
_instanceState: ShellInstanceState;
_makeMultilineJSIntoSingleLine: any;
load: (filename: string) => Promise<void>;
require: any;
config: { get<T extends keyof ShellUserConfig>(key: T): Promise<ShellUserConfig[T]> };
print: (...args: any[]) => Promise<void>;
npmArgv: string[];

constructor({ input, vscodeDir, tmpDir, internalState, makeMultilineJSIntoSingleLine }: EditorOptions) {
const { load, config, print, require } = internalState.context;
constructor({ input, vscodeDir, tmpDir, instanceState, makeMultilineJSIntoSingleLine }: EditorOptions) {
const { load, config, print, require } = instanceState.context;
this._input = input;
this._vscodeDir = vscodeDir;
this._tmpDir = tmpDir;
this._tmpDocName = `edit-${uuidv4()}`;
this._tmpDoc = '';
this._internalState = internalState;
this._instanceState = instanceState;
this._makeMultilineJSIntoSingleLine = makeMultilineJSIntoSingleLine;
this.load = load;
this.config = config;
Expand All @@ -53,7 +53,7 @@ export class Editor implements ShellPlugin {
};
wrapperFn.isDirectShellCommand = true;
wrapperFn.returnsPromise = true;
(internalState.shellApi as any).edit = internalState.context.edit = wrapperFn;
(instanceState.shellApi as any).edit = instanceState.context.edit = wrapperFn;
(signatures.ShellApi.attributes as any).edit = {
type: 'function',
returnsPromise: true,
Expand All @@ -62,7 +62,7 @@ export class Editor implements ShellPlugin {
}

activate(): void {
this._internalState.registerPlugin(this);
this._instanceState.registerPlugin(this);
}

// In the case of using VSCode as an external editor,
Expand Down Expand Up @@ -96,7 +96,7 @@ export class Editor implements ShellPlugin {

async getEditor(): Promise<string|null> {
// Check for an external editor in the mongosh configuration.
let editor: string | null = await this._internalState.shellApi.config.get('editor');
let editor: string | null = await this._instanceState.shellApi.config.get('editor');

// Check for an external editor in the environment variable.
if (!editor && process.env.EDITOR) {
Expand Down Expand Up @@ -178,7 +178,7 @@ export class Editor implements ShellPlugin {
}

get messageBus(): MongoshBus {
return this._internalState.messageBus;
return this._instanceState.messageBus;
}

transformError(err: Error): Error {
Expand Down

0 comments on commit 0447e29

Please sign in to comment.