Skip to content

Commit

Permalink
Merge pull request #147 from krassowski/fix/tidyverse
Browse files Browse the repository at this point in the history
Implement didSave, fixes #95
  • Loading branch information
krassowski authored Jan 11, 2020
2 parents ec31280 + caab501 commit c58be5a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## `lsp-ws-connection 0.3.1`

- added sendSaved() method (textDocument/didSave) (
[#147](https://github.com/krassowski/jupyterlab-lsp/pull/147)
)

## `@krassowski/jupyterlab-lsp 0.7.0-beta.1`

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

## `lsp-ws-connection 0.3.0`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export class LSPConnector extends DataConnector<
}

protected get _has_kernel(): boolean {
return this.options.session && this.options.session.kernel !== null;
return (
typeof this.options.session !== 'undefined' &&
this.options.session.kernel !== null
);
}

protected get _kernel_language(): string {
Expand Down
16 changes: 15 additions & 1 deletion packages/jupyterlab-lsp/src/adapters/jupyterlab/jl_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CodeJumper } from '@krassowski/jupyterlab_go_to_definition/lib/jumpers/
import { PositionConverter } from '../../converter';
import { CodeEditor } from '@jupyterlab/codeeditor';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { IDocumentWidget } from '@jupyterlab/docregistry';
import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';

import * as lsProtocol from 'vscode-languageserver-protocol';
import { FreeTooltip } from './components/free_tooltip';
Expand Down Expand Up @@ -125,6 +125,7 @@ export abstract class JupyterLabWidgetAdapter
) {
this.status_message = new StatusMessage();
this.widget.context.pathChanged.connect(this.reload_connection.bind(this));
this.widget.context.saveState.connect(this.on_save_state.bind(this));
this.invoke_command = invoke;
this.document_connected = new Signal(this);
this.adapters = new Map();
Expand Down Expand Up @@ -194,6 +195,19 @@ export abstract class JupyterLabWidgetAdapter
);
}

protected on_save_state(context: any, state: DocumentRegistry.SaveState) {
// ignore premature calls (before the editor was initialized)
if (typeof this.virtual_editor === 'undefined') {
return;
}

if (state === 'completed') {
for (let connection of this.connection_manager.connections.values()) {
connection.sendSaved();
}
}
}

abstract find_ce_editor(cm_editor: CodeMirror.Editor): CodeEditor.IEditor;

invoke_completer(kind: CompletionTriggerKind) {
Expand Down
19 changes: 18 additions & 1 deletion packages/lsp-ws-connection/src/ws-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class LspWsConnection extends events.EventEmitter
synchronization: {
dynamicRegistration: true,
willSave: false,
didSave: false,
didSave: true,
willSaveWaitUntil: false
},
completion: {
Expand Down Expand Up @@ -230,6 +230,23 @@ export class LspWsConnection extends events.EventEmitter
this.documentVersion++;
}

public sendSaved() {
if (!this.isConnected || !this.isInitialized) {
return;
}
const textDocumentChange: protocol.DidSaveTextDocumentParams = {
textDocument: {
uri: this.documentInfo.documentUri,
version: this.documentVersion
} as protocol.VersionedTextDocumentIdentifier,
text: this.documentInfo.documentText()
};
this.connection.sendNotification(
'textDocument/didSave',
textDocumentChange
);
}

public getHoverTooltip(location: IPosition) {
if (!this.isInitialized) {
return;
Expand Down

0 comments on commit c58be5a

Please sign in to comment.