Skip to content

Commit

Permalink
Add jupyter_suggestions_rtc package (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc authored Dec 13, 2024
1 parent df7595a commit d59519e
Show file tree
Hide file tree
Showing 41 changed files with 2,364 additions and 762 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@ jobs:
- name: Build the extension
run: |
set -eux
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8
jlpm dev
jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "jupyter-suggestions.*OK"
jupyter labextension list 2>&1 | grep -ie "suggestions.*OK"
python -m jupyterlab.browser_check
- name: Package the extension
run: |
set -eux
pip install hatch
yarn build:packages
jlpm build:packages
- name: Upload extension packages
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -79,7 +83,7 @@ jobs:
jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "jupyter-suggestions.*OK"
jupyter labextension list 2>&1 | grep -ie "suggestions.*OK"
python -m jupyterlab.browser_check --no-browser-test
check_links:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ dmypy.json

# Yarn cache
.yarn/

python/jupyter_suggestions_rtc/jupyter_suggestions_rtc/labextension
python/jupyter_suggestions_rtc/jupyter_suggestions_rtc/_version.py
8 changes: 6 additions & 2 deletions lerna.json
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"
]
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@jupyter/jupyter-suggestions-root",
"name": "@jupyter/suggestions-root",
"version": "0.1.0",
"private": true,
"description": "A JupyterLab extension for suggesting changes.",
Expand All @@ -25,7 +25,8 @@
},
"workspaces": [
"packages/*",
"python/jupyter_suggestions_core"
"python/jupyter_suggestions_core",
"python/jupyter_suggestions_rtc"
],
"scripts": {
"build": "lerna run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/base/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@jupyter/jupyter-suggestions-base",
"name": "@jupyter/suggestions-base",
"version": "0.1.0",
"description": "Base components of jupyter-suggestions extension",
"keywords": [
Expand Down
101 changes: 101 additions & 0 deletions packages/base/src/baseSuggestionsManager.ts
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;
}
}
1 change: 1 addition & 0 deletions packages/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './suggestionsPanel';
export * from './icons';
export * from './tokens';
export * from './localSuggestionsManager';
export * from './baseSuggestionsManager';
export * from './registry';
Loading

0 comments on commit d59519e

Please sign in to comment.