|
@@ -25,7 +25,7 @@ import { IDisposable } from '@lumino/disposable';
|
|
|
|
|
|
import { Signal } from '@lumino/signaling';
|
|
|
|
|
|
-import { murmur2 } from 'murmurhash-js';
|
|
|
+import { IDebuggerParametersMixer } from './parameters-mixer';
|
|
|
|
|
|
/**
|
|
|
* A class to find instances of code editors across notebook, console and files widgets
|
|
@@ -41,6 +41,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
|
|
|
this._notebookTracker = options.notebookTracker;
|
|
|
this._consoleTracker = options.consoleTracker;
|
|
|
this._editorTracker = options.editorTracker;
|
|
|
+ this._parametersMixer = options.parametersMixer;
|
|
|
this._readOnlyEditorTracker = new WidgetTracker<
|
|
|
MainAreaWidget<CodeEditorWrapper>
|
|
|
>({
|
|
@@ -64,42 +65,6 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
|
|
|
Signal.clearData(this);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Computes an id based on the given code.
|
|
|
- *
|
|
|
- * @param code The source code.
|
|
|
- */
|
|
|
- public getCodeId(code: string): string {
|
|
|
- return this._tmpFilePrefix + this._hashMethod(code) + this._tmpFileSuffix;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Set the hash parameters for the current session.
|
|
|
- *
|
|
|
- * @param method The hash method.
|
|
|
- * @param seed The seed for the hash method.
|
|
|
- */
|
|
|
- public setHashParameters(method: string, seed: number): void {
|
|
|
- if (method === 'Murmur2') {
|
|
|
- this._hashMethod = (code: string): string => {
|
|
|
- return murmur2(code, seed).toString();
|
|
|
- };
|
|
|
- } else {
|
|
|
- throw new Error('hash method not supported ' + method);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Set the parameters used for the temporary files (e.g. cells).
|
|
|
- *
|
|
|
- * @param prefix The prefix used for the temporary files.
|
|
|
- * @param suffix The suffix used for the temporary files.
|
|
|
- */
|
|
|
- public setTmpFileParameters(prefix: string, suffix: string): void {
|
|
|
- this._tmpFilePrefix = prefix;
|
|
|
- this._tmpFileSuffix = suffix;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Find the editor for a source matching the current debug session
|
|
|
* by iterating through all the widgets in each of the notebook,
|
|
@@ -154,7 +119,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
|
|
|
cells.forEach((cell, i) => {
|
|
|
// check the event is for the correct cell
|
|
|
const code = cell.model.value.text;
|
|
|
- const cellId = this.getCodeId(code);
|
|
|
+ const cellId = this._parametersMixer.getCodeId(code);
|
|
|
if (source !== cellId) {
|
|
|
return;
|
|
|
}
|
|
@@ -196,7 +161,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
|
|
|
const cells = consoleWidget.console.cells;
|
|
|
each(cells, cell => {
|
|
|
const code = cell.model.value.text;
|
|
|
- const codeId = this.getCodeId(code);
|
|
|
+ const codeId = this._parametersMixer.getCodeId(code);
|
|
|
if (source !== codeId) {
|
|
|
return;
|
|
|
}
|
|
@@ -238,7 +203,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
|
|
|
}
|
|
|
|
|
|
const code = editor.model.value.text;
|
|
|
- const codeId = this.getCodeId(code);
|
|
|
+ const codeId = this._parametersMixer.getCodeId(code);
|
|
|
if (source !== codeId) {
|
|
|
return;
|
|
|
}
|
|
@@ -270,7 +235,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
|
|
|
}
|
|
|
|
|
|
const code = editor.model.value.text;
|
|
|
- const codeId = this.getCodeId(code);
|
|
|
+ const codeId = this._parametersMixer.getCodeId(code);
|
|
|
if (widget.title.caption !== source && source !== codeId) {
|
|
|
return;
|
|
|
}
|
|
@@ -289,10 +254,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
|
|
|
private _notebookTracker: INotebookTracker | null;
|
|
|
private _consoleTracker: IConsoleTracker | null;
|
|
|
private _editorTracker: IEditorTracker | null;
|
|
|
-
|
|
|
- private _hashMethod: (code: string) => string;
|
|
|
- private _tmpFilePrefix: string;
|
|
|
- private _tmpFileSuffix: string;
|
|
|
+ private _parametersMixer: IDebuggerParametersMixer;
|
|
|
}
|
|
|
/**
|
|
|
* A namespace for editor finder statics.
|
|
@@ -326,6 +288,11 @@ export namespace EditorFinder {
|
|
|
* The application shell.
|
|
|
*/
|
|
|
shell: JupyterFrontEnd.IShell;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The instance of parameters mixer with hash method.
|
|
|
+ */
|
|
|
+ parametersMixer: IDebuggerParametersMixer;
|
|
|
}
|
|
|
/**
|
|
|
* A token for a editor finder handler find method plugin
|
|
@@ -344,8 +311,4 @@ export interface IDebuggerEditorFinder {
|
|
|
source: string,
|
|
|
focus: boolean
|
|
|
): IIterator<CodeEditor.IEditor>;
|
|
|
-
|
|
|
- setHashParameters(method: string, seed: number): void;
|
|
|
- setTmpFileParameters(prefix: string, suffix: string): void;
|
|
|
- getCodeId(code: string): string;
|
|
|
}
|