Skip to content

Commit c58be5a

Browse files
authored
Merge pull request #147 from krassowski/fix/tidyverse
Implement didSave, fixes #95
2 parents ec31280 + caab501 commit c58be5a

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

CHANGELOG.md

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

3+
## `lsp-ws-connection 0.3.1`
4+
5+
- added sendSaved() method (textDocument/didSave) (
6+
[#147](https://github.com/krassowski/jupyterlab-lsp/pull/147)
7+
)
8+
39
## `@krassowski/jupyterlab-lsp 0.7.0-beta.1`
410

511
- features
@@ -44,6 +50,11 @@
4450
will now correctly substitute the incomplete token (
4551
[#143](https://github.com/krassowski/jupyterlab-lsp/pull/143)
4652
)
53+
- `didSave()` is emitted on file save, enabling the workaround
54+
used by R language server to lazily load `library(tidyverse)` (
55+
[#95](https://github.com/krassowski/jupyterlab-lsp/pull/95),
56+
[#147](https://github.com/krassowski/jupyterlab-lsp/pull/147),
57+
)
4758

4859
## `lsp-ws-connection 0.3.0`
4960

packages/jupyterlab-lsp/src/adapters/jupyterlab/components/completion.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export class LSPConnector extends DataConnector<
6868
}
6969

7070
protected get _has_kernel(): boolean {
71-
return this.options.session && this.options.session.kernel !== null;
71+
return (
72+
typeof this.options.session !== 'undefined' &&
73+
this.options.session.kernel !== null
74+
);
7275
}
7376

7477
protected get _kernel_language(): string {

packages/jupyterlab-lsp/src/adapters/jupyterlab/jl_adapter.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CodeJumper } from '@krassowski/jupyterlab_go_to_definition/lib/jumpers/
66
import { PositionConverter } from '../../converter';
77
import { CodeEditor } from '@jupyterlab/codeeditor';
88
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
9-
import { IDocumentWidget } from '@jupyterlab/docregistry';
9+
import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
1010

1111
import * as lsProtocol from 'vscode-languageserver-protocol';
1212
import { FreeTooltip } from './components/free_tooltip';
@@ -125,6 +125,7 @@ export abstract class JupyterLabWidgetAdapter
125125
) {
126126
this.status_message = new StatusMessage();
127127
this.widget.context.pathChanged.connect(this.reload_connection.bind(this));
128+
this.widget.context.saveState.connect(this.on_save_state.bind(this));
128129
this.invoke_command = invoke;
129130
this.document_connected = new Signal(this);
130131
this.adapters = new Map();
@@ -194,6 +195,19 @@ export abstract class JupyterLabWidgetAdapter
194195
);
195196
}
196197

198+
protected on_save_state(context: any, state: DocumentRegistry.SaveState) {
199+
// ignore premature calls (before the editor was initialized)
200+
if (typeof this.virtual_editor === 'undefined') {
201+
return;
202+
}
203+
204+
if (state === 'completed') {
205+
for (let connection of this.connection_manager.connections.values()) {
206+
connection.sendSaved();
207+
}
208+
}
209+
}
210+
197211
abstract find_ce_editor(cm_editor: CodeMirror.Editor): CodeEditor.IEditor;
198212

199213
invoke_completer(kind: CompletionTriggerKind) {

packages/lsp-ws-connection/src/ws-connection.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class LspWsConnection extends events.EventEmitter
139139
synchronization: {
140140
dynamicRegistration: true,
141141
willSave: false,
142-
didSave: false,
142+
didSave: true,
143143
willSaveWaitUntil: false
144144
},
145145
completion: {
@@ -230,6 +230,23 @@ export class LspWsConnection extends events.EventEmitter
230230
this.documentVersion++;
231231
}
232232

233+
public sendSaved() {
234+
if (!this.isConnected || !this.isInitialized) {
235+
return;
236+
}
237+
const textDocumentChange: protocol.DidSaveTextDocumentParams = {
238+
textDocument: {
239+
uri: this.documentInfo.documentUri,
240+
version: this.documentVersion
241+
} as protocol.VersionedTextDocumentIdentifier,
242+
text: this.documentInfo.documentText()
243+
};
244+
this.connection.sendNotification(
245+
'textDocument/didSave',
246+
textDocumentChange
247+
);
248+
}
249+
233250
public getHoverTooltip(location: IPosition) {
234251
if (!this.isInitialized) {
235252
return;

0 commit comments

Comments
 (0)