Skip to content

Commit

Permalink
fix: shutdown lsp sever
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanba committed Jan 24, 2024
1 parent 2cd7e6f commit 7ad0439
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LibroKernelManager, LibroSessionManager } from '@difizen/libro-kernel';
import { DocumentConnectionManager } from '@difizen/libro-lsp';
import type { ILanguageServerManager } from '@difizen/libro-lsp';
import type { ILSPDocumentConnectionManager } from '@difizen/libro-lsp';
import { DocumentConnectionManager } from '@difizen/libro-lsp';
import { ILSPDocumentConnectionManager } from '@difizen/libro-lsp';
import { TerminalManager } from '@difizen/libro-terminal';
import {
BaseView,
Expand Down Expand Up @@ -31,8 +31,13 @@ const PanelRender: React.FC = () => {
const instance = useInject<KernelAndTerminalPanelView>(ViewInstance);
const openedTabView = instance.getAllOpenedTabView();

const { libroKernelManager, libroSessionManager, terminalManager, lspManager } =
instance;
const {
libroKernelManager,
libroSessionManager,
terminalManager,
lspManager,
lspConnectionManager,
} = instance;

const [kernelItems, setKernelItems] = useState<
LibroPanelCollapseKernelItem[] | undefined
Expand All @@ -57,7 +62,7 @@ const PanelRender: React.FC = () => {
items.push({
id: key,
name: `${key} (${session.spec.languages.join('/')})`,
shutdown: async () => lspManager.shutdown(key),
shutdown: async () => lspConnectionManager.disconnectServer(key),
});
});

Expand Down Expand Up @@ -160,7 +165,7 @@ const PanelRender: React.FC = () => {
<LibroCollapse
type={LibroPanelCollapseItemType.LSP}
items={lspItems}
shutdownAll={() => lspManager.shutdownAll()}
shutdownAll={() => lspConnectionManager.disconnectAllServers()}
/>
</div>
);
Expand All @@ -178,13 +183,14 @@ export class KernelAndTerminalPanelView extends BaseView {
libroKernelManager: LibroKernelManager;
libroSessionManager: LibroSessionManager;
terminalManager: TerminalManager;
lspConnectionManager: ILSPDocumentConnectionManager;
lspManager: ILanguageServerManager;

constructor(
@inject(LibroKernelManager) libroKernelManager: LibroKernelManager,
@inject(LibroSessionManager) libroSessionManager: LibroSessionManager,
@inject(TerminalManager) terminalManager: TerminalManager,
@inject(DocumentConnectionManager)
@inject(ILSPDocumentConnectionManager)
lspDocumentConnectionManager: ILSPDocumentConnectionManager,
) {
super();
Expand All @@ -194,6 +200,7 @@ export class KernelAndTerminalPanelView extends BaseView {
this.libroKernelManager = libroKernelManager;
this.libroSessionManager = libroSessionManager;
this.terminalManager = terminalManager;
this.lspConnectionManager = lspDocumentConnectionManager;
this.lspManager = lspDocumentConnectionManager.languageServerManager;
}

Expand Down
12 changes: 11 additions & 1 deletion packages/libro-lsp/src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,24 @@ export class DocumentConnectionManager implements ILSPDocumentConnectionManager

private _connections: Map<TLanguageServerId, LSPConnection> = new Map();

protected disconnectServer(languageServerId: TLanguageServerId): void {
disconnectServer(languageServerId: TLanguageServerId): void {
const connection = this._connections.get(languageServerId);
if (connection) {
connection.close();
this._connections.delete(languageServerId);
this.languageServerManager.refreshRunning();
}
}

disconnectAllServers(): void {
this.connections.forEach((connection, languageServerId) => {
connection.close();
this._connections.delete(languageServerId as TLanguageServerId);
});

this.languageServerManager.refreshRunning();
}

/**
* Return (or create and initialize) the WebSocket associated with the language
*/
Expand Down
11 changes: 1 addition & 10 deletions packages/libro-lsp/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,7 @@ export class LanguageServerManager implements ILanguageServerManager {
}

async refreshRunning() {
// TODO: refreshRunning
}

async shutdownAll() {
// TODO: shutdownAll
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async shutdown(key: string) {
// TODO: shutdown
this.fetchSessions();
}

/**
Expand Down

0 comments on commit 7ad0439

Please sign in to comment.