Skip to content

Commit 7679546

Browse files
authored
Merge pull request #990 from krassowski/rc2
Restore re-use of unused standalone connections
2 parents d5782eb + 406c43e commit 7679546

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### `@jupyter-lsp/jupyterlab-lsp 5.0.0-rc.1`
4+
5+
- restore re-use of unused standalone connections
6+
37
### `@jupyter-lsp/jupyterlab-lsp 5.0.0-rc.0`
48

59
- fixes diagnostics not showing up in text editor in certain circumstances

packages/jupyterlab-lsp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jupyter-lsp/jupyterlab-lsp",
3-
"version": "5.0.0-rc.0",
3+
"version": "5.0.0-rc.1",
44
"description": "Language Server Protocol integration for JupyterLab",
55
"keywords": [
66
"jupyter",

packages/jupyterlab-lsp/src/virtual/document.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type {
44
IVirtualPosition,
55
IRootPosition,
66
Document,
7-
ForeignDocumentsMap
7+
ForeignDocumentsMap,
8+
IForeignCodeExtractor
89
} from '@jupyterlab/lsp';
910
import { VirtualDocument as VirtualDocumentBase } from '@jupyterlab/lsp';
1011

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

3842
// TODO: this could be moved out
@@ -202,4 +206,38 @@ export class VirtualDocument extends VirtualDocumentBase {
202206
}
203207
return [...maps.values()];
204208
}
209+
210+
/**
211+
* Get the foreign document that can be opened with the input extractor.
212+
*/
213+
private _chooseForeignDocument(
214+
extractor: IForeignCodeExtractor
215+
): VirtualDocumentBase {
216+
let foreignDocument: VirtualDocumentBase;
217+
// if not standalone, try to append to existing document
218+
let foreignExists = this.foreignDocuments.has(extractor.language);
219+
if (!extractor.standalone && foreignExists) {
220+
foreignDocument = this.foreignDocuments.get(extractor.language)!;
221+
} else {
222+
// if standalone, try to re-use existing connection to the server
223+
let unusedStandalone = this.unusedStandaloneDocuments.get(
224+
extractor.language
225+
);
226+
if (extractor.standalone && unusedStandalone.length > 0) {
227+
foreignDocument = unusedStandalone.pop()!;
228+
this.unusedDocuments.delete(foreignDocument);
229+
} else {
230+
// if (previous document does not exists) or (extractor produces standalone documents
231+
// and no old standalone document could be reused): create a new document
232+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
233+
// @ts-ignore
234+
foreignDocument = this.openForeign(
235+
extractor.language,
236+
extractor.standalone,
237+
extractor.fileExtension
238+
);
239+
}
240+
}
241+
return foreignDocument;
242+
}
205243
}

packages/metapackage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jupyter-lsp/jupyterlab-lsp-metapackage",
3-
"version": "5.0.0-rc.0",
3+
"version": "5.0.0-rc.1",
44
"description": "JupyterLab LSP - Meta Package. All of the packages used by JupyterLab LSP",
55
"homepage": "https://github.com/jupyter-lsp/jupyterlab-lsp",
66
"bugs": {

0 commit comments

Comments
 (0)