Skip to content

Commit

Permalink
Implement jump to definitions and basic target selector
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jan 1, 2022
1 parent f4d42d1 commit 00f2a4e
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 111 deletions.
4 changes: 2 additions & 2 deletions packages/jupyterlab-lsp/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ export interface IClientResult {
[Method.ClientRequest.DEFINITION]: AnyLocation;
[Method.ClientRequest.DOCUMENT_HIGHLIGHT]: lsp.DocumentHighlight[];
[Method.ClientRequest.DOCUMENT_SYMBOL]: lsp.DocumentSymbol[];
[Method.ClientRequest.HOVER]: lsp.Hover;
[Method.ClientRequest.HOVER]: lsp.Hover | null;
[Method.ClientRequest.IMPLEMENTATION]: AnyLocation;
[Method.ClientRequest.INITIALIZE]: lsp.InitializeResult;
[Method.ClientRequest.REFERENCES]: Location[];
[Method.ClientRequest.REFERENCES]: lsp.Location[] | null;
[Method.ClientRequest.RENAME]: lsp.WorkspaceEdit;
[Method.ClientRequest.SIGNATURE_HELP]: lsp.SignatureHelp;
[Method.ClientRequest.TYPE_DEFINITION]: AnyLocation;
Expand Down
12 changes: 12 additions & 0 deletions packages/jupyterlab-lsp/src/editor_integration/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export abstract class CodeMirrorIntegration
protected virtual_document: VirtualDocument;
protected connection: LSPConnection;

/** @deprecated: use `setStatusMessage()` instead */
protected status_message: StatusMessage;
protected adapter: WidgetAdapter<IDocumentWidget>;
protected console: ILSPLogConsole;
Expand Down Expand Up @@ -128,6 +129,17 @@ export abstract class CodeMirrorIntegration
this.is_registered = false;
}

/**
* Set the text message and (optionally) the timeout to remove it.
* @param message
* @param timeout - number of ms to until the message is cleaned;
* -1 if the message should stay up indefinitely;
* defaults to 3000ms (3 seconds)
*/
setStatusMessage(message: string, timeout?: number): void {
this.status_message.set(message, timeout);
}

register(): void {
// register editor handlers
for (let [event_name, handler] of this.editor_handlers) {
Expand Down
32 changes: 18 additions & 14 deletions packages/jupyterlab-lsp/src/features/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import {
IEditorIntegrationOptions,
IFeatureLabIntegration
} from '../feature';
import { IRootPosition, IVirtualPosition, is_equal } from '../positioning';
import {
IRootPosition,
IVirtualPosition,
ProtocolCoordinates,
is_equal
} from '../positioning';
import { ILSPFeatureManager, PLUGIN_ID } from '../tokens';
import { getModifierState } from '../utils';
import { VirtualDocument } from '../virtual/document';
Expand Down Expand Up @@ -122,10 +127,12 @@ export class HoverCM extends CodeMirrorIntegration {
private virtual_position: IVirtualPosition;
protected cache: ResponseCache;

private debounced_get_hover: Throttler<Promise<lsProtocol.Hover | undefined>>;
private debounced_get_hover: Throttler<
Promise<lsProtocol.Hover | undefined | null>
>;
private tooltip: FreeTooltip;
private _previousHoverRequest: Promise<
Promise<lsProtocol.Hover | undefined>
Promise<lsProtocol.Hover | undefined | null>
> | null = null;

constructor(options: IEditorIntegrationOptions) {
Expand Down Expand Up @@ -154,13 +161,7 @@ export class HoverCM extends CodeMirrorIntegration {
return false;
}
let range = cache_item.response.range!;
return (
line >= range.start.line &&
line <= range.end.line &&
// need to be non-overlapping see https://github.com/jupyter-lsp/jupyterlab-lsp/issues/628
(line != range.start.line || ch > range.start.character) &&
(line != range.end.line || ch <= range.end.character)
);
return ProtocolCoordinates.isWithinRange({ line, character: ch }, range);
});
if (matching_items.length > 1) {
this.console.warn(
Expand Down Expand Up @@ -250,10 +251,13 @@ export class HoverCM extends CodeMirrorIntegration {
}

protected create_throttler() {
return new Throttler<Promise<lsProtocol.Hover | undefined>>(this.on_hover, {
limit: this.settings.composite.throttlerDelay,
edge: 'trailing'
});
return new Throttler<Promise<lsProtocol.Hover | undefined | null>>(
this.on_hover,
{
limit: this.settings.composite.throttlerDelay,
edge: 'trailing'
}
);
}

afterChange(change: IEditorChange, root_position: IRootPosition) {
Expand Down
Loading

0 comments on commit 00f2a4e

Please sign in to comment.