Skip to content

Commit 3db3846

Browse files
committed
Merge branch 'master' into krassowski-patch-1
2 parents 85032b2 + 6fdbfb7 commit 3db3846

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
## CHANGELOG
22

3+
### `@krassowski/jupyterlab-lsp 2.0.8` (unreleased)
4+
5+
- bug fixes
6+
7+
- custom cell syntax highlighting is now properly removed when no longer needed ([#387])
8+
9+
[#387]: https://github.com/krassowski/jupyterlab-lsp/issues/387
10+
311
### `@krassowski/jupyterlab-lsp 2.0.7` (2020-09-18)
412

513
- bug fixes

atest/05_Features/Completion.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ VSCode Dark Theme Works
149149
Configure JupyterLab Plugin {"theme": "vscode"} plugin id=${COMPLETION PLUGIN ID}
150150
Capture Page Screenshot 01-configured.png
151151
Open ${file} in ${MENU NOTEBOOK}
152-
Enter Cell Editor 1 line=2
153152
Wait Until Fully Initialized
153+
Enter Cell Editor 1 line=2
154154
Trigger Completer
155155
Capture Page Screenshot 02-completions-shown.png
156156
Completer Should Suggest TabError

atest/05_Features/Syntax_highlighting.robot

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,29 @@ Highlighing Mode Works For Multiple Documents
2424
${mode} = Get Mode Of A Cell 6
2525
should be equal ${mode['name']} javascript
2626

27+
Highlighting Mode Changes Back And Forth After Edits
28+
${mode} = Get Mode Of A Cell 2
29+
should be equal ${mode['name']} markdown
30+
Enter Cell Editor 2 line=1
31+
Press Keys None BACKSPACE
32+
Capture Page Screenshot backapse.png
33+
wait until keyword succeeds 5x 2s Mode Of A Cell Should Equal 2 ipython
34+
Enter Cell Editor 2 line=1
35+
Press Keys None n
36+
wait until keyword succeeds 5x 2s Mode Of A Cell Should Equal 2 markdown
37+
2738
*** Keywords ***
2839
Get Mode Of A Cell
29-
[Arguments] ${cell_nr}
30-
Click Element css:.jp-Cell:nth-child(${cell_nr})
31-
Wait Until Page Contains Element css:.jp-Cell:nth-child(${cell_nr}) .CodeMirror-focused
32-
${mode} = Execute JavaScript return document.querySelector('.jp-Cell:nth-child(${cell_nr}) .CodeMirror').CodeMirror.getMode()
40+
[Arguments] ${cell_number}
41+
Click Element css:.jp-Cell:nth-child(${cell_number})
42+
Wait Until Page Contains Element css:.jp-Cell:nth-child(${cell_number}) .CodeMirror-focused
43+
${mode} = Execute JavaScript return document.querySelector('.jp-Cell:nth-child(${cell_number}) .CodeMirror').CodeMirror.getMode()
3344
[Return] ${mode}
3445

3546
Setup Highlighting Test
3647
Setup Notebook Python Syntax highlighting.ipynb
48+
49+
Mode Of A Cell Should Equal
50+
[Arguments] ${cell_number} ${expected_mode}
51+
${mode} = Get Mode Of A Cell ${cell_number}
52+
should be equal ${mode['name']} ${expected_mode}

packages/jupyterlab-lsp/src/features/syntax_highlighting.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ const FEATURE_ID = PLUGIN_ID + ':syntax_highlighting';
2929
export class CMSyntaxHighlighting extends CodeMirrorIntegration {
3030
lab_integration: SyntaxLabIntegration;
3131
settings: IFeatureSettings<LSPSyntaxHighlightingSettings>;
32+
editors_with_active_highlight: Set<CodeMirrorEditor>;
3233

3334
constructor(options: IEditorIntegrationOptions) {
3435
super(options);
3536
this.virtual_document.changed.connect(this.update_mode.bind(this), this);
37+
this.editors_with_active_highlight = new Set();
3638
}
3739

3840
private get_mode(language: string) {
@@ -52,10 +54,12 @@ export class CMSyntaxHighlighting extends CodeMirrorIntegration {
5254

5355
update_mode() {
5456
let root = this.virtual_document;
57+
let editors_with_current_highlight = new Set<CodeMirrorEditor>();
58+
5559
for (let map of root.foreign_document_maps) {
5660
for (let [range, block] of map.entries()) {
57-
let ce_editor = block.editor;
58-
let editor = (ce_editor as CodeMirrorEditor).editor;
61+
let ce_editor = block.editor as CodeMirrorEditor;
62+
let editor = ce_editor.editor;
5963
let lines = editor.getValue('\n');
6064
let total_area = lines.concat('').length;
6165

@@ -75,13 +79,24 @@ export class CMSyntaxHighlighting extends CodeMirrorIntegration {
7579

7680
// change the mode if the majority of the code is the foreign code
7781
if (coverage > this.settings.composite.foreignCodeThreshold) {
82+
editors_with_current_highlight.add(ce_editor);
7883
let old_mode = editor.getOption('mode');
7984
if (old_mode != mode.mime) {
8085
editor.setOption('mode', mode.mime);
8186
}
8287
}
8388
}
8489
}
90+
91+
if (editors_with_current_highlight != this.editors_with_active_highlight) {
92+
for (let ce_editor of this.editors_with_active_highlight) {
93+
if (!editors_with_current_highlight.has(ce_editor)) {
94+
ce_editor.editor.setOption('mode', ce_editor.model.mimeType);
95+
}
96+
}
97+
}
98+
99+
this.editors_with_active_highlight = editors_with_current_highlight;
85100
}
86101
}
87102

0 commit comments

Comments
 (0)