Skip to content

Commit

Permalink
Merge pull request #990 from krassowski/rc2
Browse files Browse the repository at this point in the history
Restore re-use of unused standalone connections
  • Loading branch information
krassowski authored Oct 1, 2023
2 parents d5782eb + 406c43e commit 7679546
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### `@jupyter-lsp/jupyterlab-lsp 5.0.0-rc.1`

- restore re-use of unused standalone connections

### `@jupyter-lsp/jupyterlab-lsp 5.0.0-rc.0`

- fixes diagnostics not showing up in text editor in certain circumstances
Expand Down
2 changes: 1 addition & 1 deletion packages/jupyterlab-lsp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-lsp/jupyterlab-lsp",
"version": "5.0.0-rc.0",
"version": "5.0.0-rc.1",
"description": "Language Server Protocol integration for JupyterLab",
"keywords": [
"jupyter",
Expand Down
40 changes: 39 additions & 1 deletion packages/jupyterlab-lsp/src/virtual/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type {
IVirtualPosition,
IRootPosition,
Document,
ForeignDocumentsMap
ForeignDocumentsMap,
IForeignCodeExtractor
} from '@jupyterlab/lsp';
import { VirtualDocument as VirtualDocumentBase } from '@jupyterlab/lsp';

Expand Down Expand Up @@ -33,6 +34,9 @@ export class VirtualDocument extends VirtualDocumentBase {
this.lineMagicsOverrides = new ReversibleOverridesMap(
overrides ? overrides.line : []
);
// override private `chooseForeignDocument` as a workaround for
// https://github.com/jupyter-lsp/jupyterlab-lsp/issues/959
this['chooseForeignDocument'] = this._chooseForeignDocument;
}

// TODO: this could be moved out
Expand Down Expand Up @@ -202,4 +206,38 @@ export class VirtualDocument extends VirtualDocumentBase {
}
return [...maps.values()];
}

/**
* Get the foreign document that can be opened with the input extractor.
*/
private _chooseForeignDocument(
extractor: IForeignCodeExtractor
): VirtualDocumentBase {
let foreignDocument: VirtualDocumentBase;
// if not standalone, try to append to existing document
let foreignExists = this.foreignDocuments.has(extractor.language);
if (!extractor.standalone && foreignExists) {
foreignDocument = this.foreignDocuments.get(extractor.language)!;
} else {
// if standalone, try to re-use existing connection to the server
let unusedStandalone = this.unusedStandaloneDocuments.get(
extractor.language
);
if (extractor.standalone && unusedStandalone.length > 0) {
foreignDocument = unusedStandalone.pop()!;
this.unusedDocuments.delete(foreignDocument);
} else {
// if (previous document does not exists) or (extractor produces standalone documents
// and no old standalone document could be reused): create a new document
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
foreignDocument = this.openForeign(
extractor.language,
extractor.standalone,
extractor.fileExtension
);
}
}
return foreignDocument;
}
}
2 changes: 1 addition & 1 deletion packages/metapackage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-lsp/jupyterlab-lsp-metapackage",
"version": "5.0.0-rc.0",
"version": "5.0.0-rc.1",
"description": "JupyterLab LSP - Meta Package. All of the packages used by JupyterLab LSP",
"homepage": "https://github.com/jupyter-lsp/jupyterlab-lsp",
"bugs": {
Expand Down

0 comments on commit 7679546

Please sign in to comment.