Skip to content

Commit

Permalink
Solve the root cause of jupyter-lsp#310
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Aug 20, 2020
1 parent 4421ce7 commit 4e5b2ad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
47 changes: 30 additions & 17 deletions packages/jupyterlab-lsp/src/components/statusbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ import {
TextItem
} from '@jupyterlab/statusbar';

import {
LabIcon,
refreshIcon,
runningIcon,
stopIcon
} from '@jupyterlab/ui-components';
import { LabIcon, stopIcon } from '@jupyterlab/ui-components';
import { WidgetAdapter } from '../adapters/adapter';
import { collect_documents, VirtualDocument } from '../virtual/document';
import { LSPConnection } from '../connection';
import { DocumentConnectionManager } from '../connection_manager';
import { ILanguageServerManager, ILSPAdapterManager } from '../tokens';
import { IDocumentWidget } from '@jupyterlab/docregistry';
import { codeCheckIcon } from '../index';

interface IServerStatusProps {
server: SCHEMA.LanguageServerSession;
Expand Down Expand Up @@ -278,7 +274,12 @@ export class LSPStatus extends VDomRenderer<LSPStatus.Model> {
};
}

type StatusCode = 'waiting' | 'initializing' | 'initialized' | 'connecting';
type StatusCode =
| 'waiting'
| 'initializing'
| 'initialized'
| 'connecting'
| 'initialized_but_some_missing';

export interface IStatus {
connected_documents: Set<VirtualDocument>;
Expand All @@ -296,18 +297,21 @@ function collect_languages(virtual_document: VirtualDocument): Set<string> {
}

type StatusMap = Record<StatusCode, string>;
type StatusIcon = Record<StatusCode, LabIcon>;

const iconByStatus: StatusIcon = {
waiting: refreshIcon,
initialized: runningIcon,
initializing: refreshIcon,
connecting: refreshIcon
type StatusIconClass = Record<StatusCode, string>;

const classByStatus: StatusIconClass = {
waiting: 'jp-icon4',
initialized: 'jp-icon0',
initializing: 'jp-icon3',
initialized_but_some_missing: 'jp-icon1',
connecting: 'jp-icon3'
};

const shortMessageByStatus: StatusMap = {
waiting: 'Waiting...',
initialized: 'Fully initialized',
initialized_but_some_missing:
'Initialized (additional servers can be installed)',
initializing: 'Partially initialized',
connecting: 'Connecting...'
};
Expand Down Expand Up @@ -423,11 +427,17 @@ export namespace LSPStatus {
const detected_documents = this._connection_manager.documents;
let connected_documents = new Set<VirtualDocument>();
let initialized_documents = new Set<VirtualDocument>();
let absent_documents = new Set<VirtualDocument>();
// detected documents with LSP servers available
let documents_with_servers = new Set<VirtualDocument>();

detected_documents.forEach((document, id_path) => {
let connection = this._connection_manager.connections.get(id_path);
if (!connection) {
absent_documents.add(document);
return;
} else {
documents_with_servers.add(document);
}

if (connection.isConnected) {
Expand All @@ -450,10 +460,11 @@ export namespace LSPStatus {
let status: StatusCode;
if (detected_documents.size === 0) {
status = 'waiting';
// TODO: instead of detected documents, I should use "detected_documents_with_LSP_servers_available"
} else if (initialized_documents.size === detected_documents.size) {
status = 'initialized';
} else if (connected_documents.size === detected_documents.size) {
} else if (initialized_documents.size === documents_with_servers.size) {
status = 'initialized_but_some_missing';
} else if (connected_documents.size === documents_with_servers.size) {
status = 'initializing';
} else {
status = 'connecting';
Expand All @@ -472,7 +483,9 @@ export namespace LSPStatus {
if (!this.adapter) {
return stopIcon;
}
return iconByStatus[this.status.status];
return codeCheckIcon.bindprops({
className: classByStatus[this.status.status]
});
}

get short_message(): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/jupyterlab-lsp/src/connection_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class DocumentConnectionManager {
});

// lazily load 1) the underlying library (1.5mb) and/or 2) a live WebSocket-
// like connection: either already connected or potentiailly in the process
// like connection: either already connected or potentially in the process
// of connecting.
const connection = await Private.connection(
language,
Expand Down

0 comments on commit 4e5b2ad

Please sign in to comment.