Skip to content

Commit 09c2f94

Browse files
committed
Frontend driven indexing
1 parent 3ae8e38 commit 09c2f94

File tree

4 files changed

+262
-124
lines changed

4 files changed

+262
-124
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"@jupyterlab/docmanager": "^4.2.5",
6363
"@jupyterlab/filebrowser": "^4.2.5",
6464
"@jupyterlab/services": "^7.2.5",
65-
"@jupyterlab/settingregistry": "^4.2.5"
65+
"@jupyterlab/settingregistry": "^4.2.5",
66+
"minimatch": "^10.0.1"
6667
},
6768
"devDependencies": {
6869
"@jupyterlab/builder": "^4.0.0",

src/index.ts

Lines changed: 11 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -3,124 +3,12 @@ import {
33
JupyterFrontEndPlugin
44
} from '@jupyterlab/application';
55
import { ICommandPalette, ModalCommandPalette } from '@jupyterlab/apputils';
6-
import { URLExt, PathExt } from '@jupyterlab/coreutils';
6+
import { PathExt } from '@jupyterlab/coreutils';
77
import { IDocumentManager } from '@jupyterlab/docmanager';
8-
import { ServerConnection } from '@jupyterlab/services';
98
import { ISettingRegistry } from '@jupyterlab/settingregistry';
10-
import { FileBrowser, IDefaultFileBrowser } from '@jupyterlab/filebrowser';
9+
import { IDefaultFileBrowser } from '@jupyterlab/filebrowser';
1110
import { CommandRegistry } from '@lumino/commands';
12-
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
13-
import { Message } from '@lumino/messaging';
14-
import { ISignal, Signal } from '@lumino/signaling';
15-
import { CommandPalette } from '@lumino/widgets';
16-
17-
/** Structure of the JSON response from the server */
18-
interface IQuickOpenResponse {
19-
readonly contents: { [key: string]: string[] };
20-
readonly scanSeconds: number;
21-
}
22-
23-
/** Makes a HTTP request for the server-side quick open scan */
24-
async function fetchContents(
25-
path: string,
26-
excludes: string[]
27-
): Promise<IQuickOpenResponse> {
28-
const query = excludes
29-
.map(exclude => {
30-
return 'excludes=' + encodeURIComponent(exclude);
31-
})
32-
.join('&');
33-
34-
const settings = ServerConnection.makeSettings();
35-
const fullUrl =
36-
URLExt.join(settings.baseUrl, 'jupyterlab-quickopen', 'api', 'files') +
37-
'?' +
38-
query +
39-
'&path=' +
40-
path;
41-
const response = await ServerConnection.makeRequest(
42-
fullUrl,
43-
{ method: 'GET' },
44-
settings
45-
);
46-
if (response.status !== 200) {
47-
throw new ServerConnection.ResponseError(response);
48-
}
49-
return await response.json();
50-
}
51-
52-
/**
53-
* Shows files nested under directories in the root notebooks directory configured on the server.
54-
*/
55-
class QuickOpenWidget extends CommandPalette {
56-
private _pathSelected = new Signal<this, string>(this);
57-
private _settings: ReadonlyPartialJSONObject;
58-
private _fileBrowser: FileBrowser;
59-
60-
constructor(
61-
defaultBrowser: IDefaultFileBrowser,
62-
settings: ReadonlyPartialJSONObject,
63-
options: CommandPalette.IOptions
64-
) {
65-
super(options);
66-
67-
this.id = 'jupyterlab-quickopen';
68-
this.title.iconClass = 'jp-SideBar-tabIcon jp-SearchIcon';
69-
this.title.caption = 'Quick Open';
70-
71-
this._settings = settings;
72-
this._fileBrowser = defaultBrowser;
73-
}
74-
75-
/** Signal when a selected path is activated. */
76-
get pathSelected(): ISignal<this, string> {
77-
return this._pathSelected;
78-
}
79-
80-
/** Current extension settings */
81-
set settings(settings: ReadonlyPartialJSONObject) {
82-
this._settings = settings;
83-
}
84-
85-
/**
86-
* Refreshes the widget with the paths of files on the server.
87-
*/
88-
protected async onActivateRequest(msg: Message): Promise<void> {
89-
super.onActivateRequest(msg);
90-
91-
// Fetch the current contents from the server
92-
const path = this._settings.relativeSearch
93-
? this._fileBrowser.model.path
94-
: '';
95-
const response = await fetchContents(
96-
path,
97-
this._settings.excludes as string[]
98-
);
99-
100-
// Remove all paths from the view
101-
this.clearItems();
102-
103-
for (const category in response.contents) {
104-
for (const fn of response.contents[category]) {
105-
// Creates commands that are relative file paths on the server
106-
const command = `${category}/${fn}`;
107-
if (!this.commands.hasCommand(command)) {
108-
// Only add the command to the registry if it does not yet exist TODO: Track disposables
109-
// and remove
110-
this.commands.addCommand(command, {
111-
label: fn,
112-
execute: () => {
113-
// Emit a selection signal
114-
this._pathSelected.emit(command);
115-
}
116-
});
117-
}
118-
// Make the file visible under its parent directory heading
119-
this.addItem({ command, category });
120-
}
121-
}
122-
}
123-
}
11+
import { QuickOpenWidget } from './quickopen';
12412

12513
/**
12614
* Initialization data for the jupyterlab-quickopen extension.
@@ -141,18 +29,18 @@ const extension: JupyterFrontEndPlugin<void> = {
14129
settingRegistry: ISettingRegistry,
14230
defaultFileBrowser: IDefaultFileBrowser
14331
) => {
144-
console.log(`Activated extension: ${extension.id}`);
14532
const commands: CommandRegistry = new CommandRegistry();
14633
const settings: ISettingRegistry.ISettings = await settingRegistry.load(
14734
extension.id
14835
);
149-
const widget: QuickOpenWidget = new QuickOpenWidget(
150-
defaultFileBrowser,
151-
settings.composite,
152-
{
153-
commands
154-
}
155-
);
36+
const widget: QuickOpenWidget = new QuickOpenWidget({
37+
defaultBrowser: defaultFileBrowser,
38+
settings: settings.composite,
39+
commandPaletteOptions: { commands },
40+
contents: app.serviceManager.contents,
41+
// TODO: remove
42+
useServer: false
43+
});
15644

15745
// Listen for path selection signals and show the selected files in the appropriate
15846
// editor/viewer

0 commit comments

Comments
 (0)