-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add jupyter_suggestions_rtc package (#12)
- Loading branch information
1 parent
df7595a
commit d59519e
Showing
41 changed files
with
2,364 additions
and
762 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
{ | ||
"npmClient": "yarn", | ||
"npmClient": "jlpm", | ||
"version": "independent", | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
"packages": ["packages/*", "python/jupyter_suggestions_core"] | ||
"packages": [ | ||
"packages/*", | ||
"python/jupyter_suggestions_core", | ||
"python/jupyter_suggestions_rtc" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Cell, ICellModel } from '@jupyterlab/cells'; | ||
import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook'; | ||
import { ISignal, Signal } from '@lumino/signaling'; | ||
|
||
import { | ||
IAllSuggestionData, | ||
ISuggestionChange, | ||
ISuggestionData, | ||
ISuggestionsManager | ||
} from './types'; | ||
|
||
export abstract class BaseSuggestionsManager implements ISuggestionsManager { | ||
constructor(options: BaseSuggestionsManager.IOptions) { | ||
this._tracker = options.tracker; | ||
this._tracker.widgetAdded.connect(this._notebookAdded, this); | ||
} | ||
|
||
name = 'Base Suggestion Manager'; | ||
get isDisposed(): boolean { | ||
return this._isDisposed; | ||
} | ||
|
||
get suggestionChanged(): ISignal<ISuggestionsManager, ISuggestionChange> { | ||
return this._suggestionChanged; | ||
} | ||
dispose(): void { | ||
if (this._isDisposed) { | ||
return; | ||
} | ||
this._tracker.widgetAdded.disconnect(this._notebookAdded); | ||
Signal.clearData(this); | ||
this._isDisposed = true; | ||
} | ||
|
||
abstract sourceLiveUpdate: boolean; | ||
|
||
abstract getAllSuggestions( | ||
notebook: NotebookPanel | ||
): Promise<IAllSuggestionData | undefined>; | ||
|
||
async getSuggestion(options: { | ||
notebookPath: string; | ||
cellId: string; | ||
suggestionId: string; | ||
}): Promise<ISuggestionData | undefined> { | ||
const { notebookPath, cellId, suggestionId } = options; | ||
if (this._suggestionsMap.has(notebookPath)) { | ||
const nbSuggestions = this._suggestionsMap.get(notebookPath); | ||
if (nbSuggestions && nbSuggestions.has(cellId)) { | ||
return nbSuggestions.get(cellId)![suggestionId]; | ||
} | ||
} | ||
} | ||
abstract addSuggestion(options: { | ||
notebook: NotebookPanel; | ||
cell: Cell<ICellModel>; | ||
}): Promise<string>; | ||
|
||
abstract acceptSuggestion(options: { | ||
notebook: NotebookPanel; | ||
cellId: string; | ||
suggestionId: string; | ||
}): Promise<boolean>; | ||
|
||
abstract deleteSuggestion(options: { | ||
notebook: NotebookPanel; | ||
cellId: string; | ||
suggestionId: string; | ||
}): Promise<void>; | ||
|
||
abstract updateSuggestion(options: { | ||
notebook: NotebookPanel; | ||
cellId: string; | ||
suggestionId: string; | ||
newSource: string; | ||
}): Promise<void>; | ||
|
||
protected _suggestionsMap = new Map<string, IAllSuggestionData>(); | ||
|
||
protected _notebookAdded(tracker: INotebookTracker, panel: NotebookPanel) { | ||
panel.disposed.connect(p => { | ||
const localPath = p.context.localPath; | ||
if (this._suggestionsMap.has(localPath)) { | ||
this._suggestionsMap.delete(localPath); | ||
} | ||
}); | ||
} | ||
|
||
protected _suggestionChanged = new Signal< | ||
ISuggestionsManager, | ||
ISuggestionChange | ||
>(this); | ||
protected _isDisposed = false; | ||
protected _tracker: INotebookTracker; | ||
} | ||
|
||
export namespace BaseSuggestionsManager { | ||
export interface IOptions { | ||
tracker: INotebookTracker; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.