Skip to content

Commit

Permalink
fix: shutdown lsp sever
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanba authored and xujingli committed Jan 25, 2024
1 parent f5a3184 commit a02c8c5
Show file tree
Hide file tree
Showing 35 changed files with 94 additions and 84 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"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build": "nx run-many --target=build",
"lint": "nx run-many --target=lint:prettier,lint",
"lint:prettier": "prettier --check --ignore-unknown .",
"prettier": "prettier --ignore-unknown . --write",
"lint-staged": "lint-staged",
"test": "nx run-many --target=test",
"ci:setup": "nx run-many --target=setup",
Expand Down
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: 4 additions & 3 deletions packages/libro-codemirror/src/auto-complete/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ 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"]
}
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"]
}
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"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 type { ILanguageServerManager, TLanguageServerId } from '@difizen/libro-lsp';
import { ILSPDocumentConnectionManager } from '@difizen/libro-lsp';
import { TerminalManager } from '@difizen/libro-terminal';
import {
BaseView,
Expand Down Expand Up @@ -31,8 +30,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 +61,8 @@ const PanelRender: React.FC = () => {
items.push({
id: key,
name: `${key} (${session.spec.languages.join('/')})`,
shutdown: async () => lspManager.shutdown(key),
shutdown: async () =>
lspConnectionManager.disconnectServer(key as TLanguageServerId),
});
});

Expand Down Expand Up @@ -160,7 +165,7 @@ const PanelRender: React.FC = () => {
<LibroCollapse
type={LibroPanelCollapseItemType.LSP}
items={lspItems}
shutdownAll={() => lspManager.shutdownAll()}
shutdownAll={async () => 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
4 changes: 2 additions & 2 deletions packages/libro-lab/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"]
}
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
8 changes: 4 additions & 4 deletions packages/libro-lsp/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ export type TLanguageId = string;
// export const ILanguageServerManager = Symbol('ILanguageServerManager');

export interface ILanguageServerManager extends Disposable {
shutdownAll: () => Promise<void>;

shutdown: (key: string) => Promise<void>;

refreshRunning: () => Promise<void>;

/**
Expand Down Expand Up @@ -364,6 +360,10 @@ export const ILSPDocumentConnectionManager = Symbol('ILSPDocumentConnectionManag
* The LSP connection state manager
*/
export interface ILSPDocumentConnectionManager {
disconnectServer: (languageServerId: TLanguageServerId) => void;

disconnectAllServers: () => void;

/**
* The mapping of document uri to the connection to language server.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/libro-lsp/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-markdown-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-markdown/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-output/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-prompt-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"]
}
Loading

0 comments on commit a02c8c5

Please sign in to comment.