Skip to content

Commit

Permalink
fix: lint:prettier error
Browse files Browse the repository at this point in the history
  • Loading branch information
xujingli committed Jan 25, 2024
1 parent 159479b commit f7d7263
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 12 deletions.
32 changes: 32 additions & 0 deletions .changeset/kind-geese-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
'@difizen/libro-docs': patch
'@difizen/libro-code-cell': patch
'@difizen/libro-code-editor': patch
'@difizen/libro-codemirror': patch
'@difizen/libro-cofine-editor': patch
'@difizen/libro-cofine-editor-contribution': patch
'@difizen/libro-cofine-editor-core': patch
'@difizen/libro-cofine-textmate': patch
'@difizen/libro-common': patch
'@difizen/libro-core': patch
'@difizen/libro-jupyter': patch
'@difizen/libro-kernel': patch
'@difizen/libro-l10n': patch
'@difizen/libro-lab': patch
'@difizen/libro-lsp': patch
'@difizen/libro-markdown': patch
'@difizen/libro-markdown-cell': patch
'@difizen/libro-output': patch
'@difizen/libro-prompt-cell': patch
'@difizen/libro-raw-cell': patch
'@difizen/libro-rendermime': patch
'@difizen/libro-search': patch
'@difizen/libro-search-code-cell': patch
'@difizen/libro-shared-model': patch
'@difizen/libro-terminal': patch
'@difizen/libro-toc': patch
'@difizen/libro-virtualized': patch
'@difizen/libro-widget': patch
---

Fix: Make Terminals opened from left panel same as the one you created, instead of creating a new terminal view.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CloseOutlined } from '@ant-design/icons';
import { TerminalCommands } from '@difizen/libro-terminal';
import { CommandRegistry, useInject } from '@difizen/mana-app';
import { message } from 'antd';
import React from 'react';

import {
Expand Down Expand Up @@ -58,7 +59,10 @@ export const LibroCollapseContent: React.FC<Props> = (props: Props) => {
e.stopPropagation();
e.preventDefault();
if (item.shutdown) {
item.shutdown();
item.shutdown().catch((error) => {
message.error(`shutdown ${props.type} failed`);
console.error(error);
});
}
}}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CaretDownOutlined, CaretRightOutlined } from '@ant-design/icons';
import { ViewContext } from '@difizen/mana-app';
import { Empty, Popconfirm } from 'antd';
import { Empty, message, Popconfirm } from 'antd';
import React, { useState } from 'react';

import type { SaveableTabView } from '../../index.js';
Expand Down Expand Up @@ -110,7 +110,10 @@ export const LibroCollapse: React.FC<Props> = (props: Props) => {
cancelText="取消"
onConfirm={() => {
if (props.shutdownAll) {
props.shutdownAll();
props.shutdownAll().catch((e) => {
message.error(`shutdown all ${props.type}s error`);
console.error(e);
});
}
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export const LibroKernelCollapseContentItem: React.FC<Props> = (props: Props) =>
<div className="libro-panel-collapse-item-label">{item.name}</div>
<div
className="libro-panel-collapse-item-close"
onClick={(e) => {
onClick={async (e) => {
if (item.shutdown) {
item.shutdown();
item.shutdown().catch((error) => {
console.error(error);
});
}
e.preventDefault();
e.stopPropagation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { LibroKernelManager, LibroSessionManager } from '@difizen/libro-kernel';
import type { ILanguageServerManager, TLanguageServerId } from '@difizen/libro-lsp';
import { ILSPDocumentConnectionManager } from '@difizen/libro-lsp';
import { TerminalManager } from '@difizen/libro-terminal';
import { TerminalCommands, TerminalManager } from '@difizen/libro-terminal';
import {
BaseView,
CommandRegistry,
inject,
singleton,
useInject,
Expand Down Expand Up @@ -36,6 +37,7 @@ const PanelRender: React.FC = () => {
terminalManager,
lspManager,
lspConnectionManager,
commandRegistry,
} = instance;

const [kernelItems, setKernelItems] = useState<
Expand All @@ -62,7 +64,7 @@ const PanelRender: React.FC = () => {
id: key,
name: `${key} (${session.spec.languages.join('/')})`,
shutdown: async () =>
lspConnectionManager.disconnectServer(key as TLanguageServerId),
await lspConnectionManager.disconnectServer(key as TLanguageServerId),
});
});

Expand Down Expand Up @@ -95,7 +97,7 @@ const PanelRender: React.FC = () => {
items.set(kernel.id, {
id: kernel.id,
name: kernel.name,
shutdown: async () => libroKernelManager.shutdown(kernel.id),
shutdown: async () => await libroKernelManager.shutdown(kernel.id),
notebooks: [
{ sessionId: session.id, name: session.name, path: session.path },
],
Expand All @@ -120,7 +122,13 @@ const PanelRender: React.FC = () => {
items.push({
id: 'terminal/' + terminal,
name: terminal,
shutdown: async () => terminalManager.shutdown(terminal),
shutdown: async () => {
await terminalManager.shutdown(terminal);
commandRegistry.executeCommand(
TerminalCommands['CloseTerminal'].id,
terminal,
);
},
});
}

Expand Down Expand Up @@ -154,18 +162,18 @@ const PanelRender: React.FC = () => {
items={kernelItems}
shutdownAll={async () => {
await libroKernelManager.shutdownAll();
libroSessionManager.refreshRunning();
await libroSessionManager.refreshRunning();
}}
/>
<LibroCollapse
type={LibroPanelCollapseItemType.TERMINAL}
items={terminalItems}
shutdownAll={() => terminalManager.shutdownAll()}
shutdownAll={async () => await terminalManager.shutdownAll()}
/>
<LibroCollapse
type={LibroPanelCollapseItemType.LSP}
items={lspItems}
shutdownAll={async () => lspConnectionManager.disconnectAllServers()}
shutdownAll={async () => await lspConnectionManager.disconnectAllServers()}
/>
</div>
);
Expand All @@ -185,13 +193,15 @@ export class KernelAndTerminalPanelView extends BaseView {
terminalManager: TerminalManager;
lspConnectionManager: ILSPDocumentConnectionManager;
lspManager: ILanguageServerManager;
commandRegistry: CommandRegistry;

constructor(
@inject(LibroKernelManager) libroKernelManager: LibroKernelManager,
@inject(LibroSessionManager) libroSessionManager: LibroSessionManager,
@inject(TerminalManager) terminalManager: TerminalManager,
@inject(ILSPDocumentConnectionManager)
lspDocumentConnectionManager: ILSPDocumentConnectionManager,
@inject(CommandRegistry) commandRegistry: CommandRegistry,
) {
super();
this.title.icon = <KernelAndTerminal />;
Expand All @@ -202,6 +212,7 @@ export class KernelAndTerminalPanelView extends BaseView {
this.terminalManager = terminalManager;
this.lspConnectionManager = lspDocumentConnectionManager;
this.lspManager = lspDocumentConnectionManager.languageServerManager;
this.commandRegistry = commandRegistry;
}

getAllOpenedTabView(): SaveableTabView {
Expand Down
19 changes: 19 additions & 0 deletions packages/libro-terminal/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const TerminalCommands: Record<string, Command & { keybind?: string }> =
label: '新建终端',
keybind: 'ctrl+`',
},
CloseTerminal: {
id: 'libro-terminal-close',
label: '关闭终端',
},
};

@singleton({ contrib: [CommandContribution, KeybindingContribution] })
Expand Down Expand Up @@ -55,5 +59,20 @@ export class TerminalCommandContribution
}
},
});
commands.registerCommand(TerminalCommands['CloseTerminal'], {
execute: async (name: string) => {
try {
const terminalView =
await this.viewManager.getOrCreateView<LibroTerminalView>(
LibroTerminalView,
this.manager.getTerminalArgs(name),
);

terminalView.dispose();
} catch (e) {
console.error(e);
}
},
});
}
}
9 changes: 9 additions & 0 deletions packages/libro-terminal/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class TerminalManager implements Disposable, Disposed {
protected _ready: Promise<void>;
protected _runningChanged = new Emitter<TerminalModel[]>();
protected _connectionFailure = new Emitter<Error>();

// 缓存创建terminal的参数
terminalOptionsCache = new Map();

// As an optimization, we unwrap the models to just store the names.

@prop()
Expand Down Expand Up @@ -295,6 +299,11 @@ export class TerminalManager implements Disposable, Disposed {

// 新建和打开一个已有Terminal,二者所需参数不一样
getTerminalArgs = (name?: string) => {
// 通过缓存值作为option创建终端
if (this.terminalOptionsCache.has(name)) {
return this.terminalOptionsCache.get(name);
}

if (name) {
return { name: name };
} else {
Expand Down
4 changes: 4 additions & 0 deletions packages/libro-terminal/src/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class LibroTerminalView extends BaseStatefulView {
override afterRestore() {
this.initConnection()
.then((connection) => {
this.terminalManager.terminalOptionsCache.set(connection.name, this.options);
this._isReady = true;
this.connection = connection;
this.onReadyEmitter.fire(true);
Expand Down Expand Up @@ -266,6 +267,9 @@ export class LibroTerminalView extends BaseStatefulView {
console.error(`Terminal not shut down: ${reason}`);
});
}

this.terminalManager.terminalOptionsCache.delete(this.name);

super.dispose();
}

Expand Down

0 comments on commit f7d7263

Please sign in to comment.