Skip to content

Commit

Permalink
feat(lab): add kernel/terminal/lsp panel
Browse files Browse the repository at this point in the history
  • Loading branch information
xujingli committed Jan 25, 2024
1 parent 50071f5 commit f5a3184
Show file tree
Hide file tree
Showing 53 changed files with 1,228 additions and 70 deletions.
4 changes: 2 additions & 2 deletions apps/docs/.dumi/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "/"
}
"rootDir": "/",
},
}
4 changes: 2 additions & 2 deletions apps/docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src"],
}
4 changes: 2 additions & 2 deletions packages/libro-code-cell/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src"],
}
4 changes: 2 additions & 2 deletions packages/libro-code-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src"],
}
7 changes: 3 additions & 4 deletions packages/libro-codemirror/src/auto-complete/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,9 @@ export class CompletionState {
const sources =
conf.override ||
state
.languageDataAt<CompletionSource | readonly (string | Completion)[]>(
'autocomplete',
cur(state),
)
.languageDataAt<
CompletionSource | readonly (string | Completion)[]
>('autocomplete', cur(state))
.map(asSource);
let active: readonly ActiveSource[] = sources.map((source) => {
const value =
Expand Down
4 changes: 2 additions & 2 deletions packages/libro-codemirror/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src"],
}
4 changes: 2 additions & 2 deletions packages/libro-cofine-editor-contribution/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src", "typings"]
"include": ["src", "typings"],
}
4 changes: 2 additions & 2 deletions packages/libro-cofine-editor-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": ".",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src", "typings", "package.json"]
"include": ["src", "typings", "package.json"],
}
4 changes: 2 additions & 2 deletions packages/libro-cofine-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src", "typings"]
"include": ["src", "typings"],
}
4 changes: 2 additions & 2 deletions packages/libro-cofine-textmate/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src", "typings"]
"include": ["src", "typings"],
}
4 changes: 2 additions & 2 deletions packages/libro-common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src"],
}
4 changes: 2 additions & 2 deletions packages/libro-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src"],
}
2 changes: 1 addition & 1 deletion packages/libro-jupyter/src/file/file-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class FileView extends FileTreeView {
opener.open(treeNode.uri, {
viewOptions: {
name: treeNode.fileStat.name,
fileSize: treeNode.fileStat.size,
// fileSize: treeNode.fileStat.size,
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/libro-jupyter/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src"],
}
52 changes: 51 additions & 1 deletion packages/libro-kernel/src/kernel/libro-kernel-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
KernelStatus,
KernelConnectionOptions,
IKernelModel,
KernelMeta,
} from './libro-kernel-protocol.js';
import {
LibroKernelFactory,
Expand All @@ -31,6 +32,9 @@ export class LibroKernelManager {
@prop()
kernelMap = new Map<KernelId, LibroKernel>();

@prop()
private _models = new Map<string, KernelMeta>();

protected _pollModels: Poll;
protected _isReady = false;
protected _ready: Promise<void>;
Expand All @@ -49,6 +53,10 @@ export class LibroKernelManager {
return this.kernelMap.get(kernelId);
}

get runningKernels(): Map<string, KernelMeta> {
return this._models;
}

constructor(@inject(ServerManager) serverManager: ServerManager) {
this.serverManager = serverManager;

Expand Down Expand Up @@ -114,6 +122,22 @@ export class LibroKernelManager {
await this.refreshRunning();
}

/**
* Shut down all kernels.
*/
async shutdownAll(): Promise<void> {
// Update the list of models to make sure our list is current.
await this.refreshRunning();

// Shut down all models.
await Promise.all(
[...this._models.keys()].map((id) => this.kernelRestAPI.shutdownKernel(id)),
);

// Update the list of models to clear out our state.
await this.refreshRunning();
}

async connectToKernel(options: KernelConnectionOptions) {
const kernelConnection = this.kernelConnectionFactory(options);
this.startKernel(kernelConnection);
Expand Down Expand Up @@ -180,8 +204,10 @@ export class LibroKernelManager {
* Execute a request to the server to poll running kernels and update state.
*/
protected async requestRunning(): Promise<void> {
let models: KernelMeta[];

try {
await this.kernelRestAPI.listRunning();
models = await this.kernelRestAPI.listRunning();
} catch (err: any) {
// Handle network errors, as well as cases where we are on a
// JupyterHub and the server is not running. JupyterHub returns a
Expand All @@ -195,5 +221,29 @@ export class LibroKernelManager {
}
throw err;
}

if (
this._models.size === models.length &&
models.every((model) => {
const existing = this._models.get(model.id);
if (!existing) {
return false;
}
return (
existing.connections === model.connections &&
existing.execution_state === model.execution_state &&
existing.last_activity === model.last_activity &&
existing.name === model.name &&
existing.reason === model.reason &&
existing.traceback === model.traceback
);
})
) {
// Identical models list (presuming models does not contain duplicate
// ids), so just return
return;
}

this._models = new Map(models.map((x) => [x.id, x]));
}
}
2 changes: 2 additions & 0 deletions packages/libro-kernel/src/kernel/libro-kernel-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface KernelMeta {
last_activity: string;
execution_state: KernelStatus;
connections: number;
readonly reason?: string;
readonly traceback?: string;
}

export const KernelMetaOption = Symbol('KernelMetaOption');
Expand Down
28 changes: 28 additions & 0 deletions packages/libro-kernel/src/session/libro-session-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ export class LibroSessionManager {
protected _ready: Promise<void>;
protected _isReady = false;
protected storageService: StorageService;

@prop()
protected _models: Map<string, SessionIModel>;

protected _sessionConnections: Map<string, IKernelConnection>; // sessionId -> kernelConnection

get running(): Map<string, SessionIModel> {
return this._models;
}

constructor(
@inject(LibroKernelManager) kernelManager: LibroKernelManager,
@inject(ServerManager) serverManager: ServerManager,
Expand Down Expand Up @@ -117,6 +124,27 @@ export class LibroSessionManager {
throw err;
}

if (
this._models.size === models.length &&
models.every((model) => {
const existing = this._models.get(model.id);
if (!existing) {
return false;
}
return (
existing.kernel?.id === model.kernel?.id &&
existing.kernel?.name === model.kernel?.name &&
existing.name === model.name &&
existing.path === model.path &&
existing.type === model.type
);
})
) {
// Identical models list (presuming models does not contain duplicate
// ids), so just return
return;
}

this._models = new Map(models.map((x) => [x.id, x]));

for (const [sessionId, kc] of this._sessionConnections) {
Expand Down
4 changes: 2 additions & 2 deletions packages/libro-kernel/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src"],
}
4 changes: 2 additions & 2 deletions packages/libro-l10n/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "es",
"declarationDir": "es"
"declarationDir": "es",
},
"types": ["jest"],
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src"],
}
1 change: 1 addition & 0 deletions packages/libro-lab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@difizen/libro-kernel": "^0.1.14",
"@difizen/libro-prompt-cell": "^0.1.14",
"@difizen/libro-terminal": "^0.1.14",
"@difizen/libro-lsp": "^0.1.14",
"@difizen/libro-toc": "^0.1.14",
"@difizen/libro-cofine-editor-core": "^0.1.14",
"@difizen/mana-app": "latest",
Expand Down
Loading

0 comments on commit f5a3184

Please sign in to comment.