Skip to content

Commit 00f2a4e

Browse files
committed
Implement jump to definitions and basic target selector
1 parent f4d42d1 commit 00f2a4e

File tree

6 files changed

+306
-111
lines changed

6 files changed

+306
-111
lines changed

packages/jupyterlab-lsp/src/connection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ export interface IClientResult {
129129
[Method.ClientRequest.DEFINITION]: AnyLocation;
130130
[Method.ClientRequest.DOCUMENT_HIGHLIGHT]: lsp.DocumentHighlight[];
131131
[Method.ClientRequest.DOCUMENT_SYMBOL]: lsp.DocumentSymbol[];
132-
[Method.ClientRequest.HOVER]: lsp.Hover;
132+
[Method.ClientRequest.HOVER]: lsp.Hover | null;
133133
[Method.ClientRequest.IMPLEMENTATION]: AnyLocation;
134134
[Method.ClientRequest.INITIALIZE]: lsp.InitializeResult;
135-
[Method.ClientRequest.REFERENCES]: Location[];
135+
[Method.ClientRequest.REFERENCES]: lsp.Location[] | null;
136136
[Method.ClientRequest.RENAME]: lsp.WorkspaceEdit;
137137
[Method.ClientRequest.SIGNATURE_HELP]: lsp.SignatureHelp;
138138
[Method.ClientRequest.TYPE_DEFINITION]: AnyLocation;

packages/jupyterlab-lsp/src/editor_integration/codemirror.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export abstract class CodeMirrorIntegration
9898
protected virtual_document: VirtualDocument;
9999
protected connection: LSPConnection;
100100

101+
/** @deprecated: use `setStatusMessage()` instead */
101102
protected status_message: StatusMessage;
102103
protected adapter: WidgetAdapter<IDocumentWidget>;
103104
protected console: ILSPLogConsole;
@@ -128,6 +129,17 @@ export abstract class CodeMirrorIntegration
128129
this.is_registered = false;
129130
}
130131

132+
/**
133+
* Set the text message and (optionally) the timeout to remove it.
134+
* @param message
135+
* @param timeout - number of ms to until the message is cleaned;
136+
* -1 if the message should stay up indefinitely;
137+
* defaults to 3000ms (3 seconds)
138+
*/
139+
setStatusMessage(message: string, timeout?: number): void {
140+
this.status_message.set(message, timeout);
141+
}
142+
131143
register(): void {
132144
// register editor handlers
133145
for (let [event_name, handler] of this.editor_handlers) {

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import {
2323
IEditorIntegrationOptions,
2424
IFeatureLabIntegration
2525
} from '../feature';
26-
import { IRootPosition, IVirtualPosition, is_equal } from '../positioning';
26+
import {
27+
IRootPosition,
28+
IVirtualPosition,
29+
ProtocolCoordinates,
30+
is_equal
31+
} from '../positioning';
2732
import { ILSPFeatureManager, PLUGIN_ID } from '../tokens';
2833
import { getModifierState } from '../utils';
2934
import { VirtualDocument } from '../virtual/document';
@@ -122,10 +127,12 @@ export class HoverCM extends CodeMirrorIntegration {
122127
private virtual_position: IVirtualPosition;
123128
protected cache: ResponseCache;
124129

125-
private debounced_get_hover: Throttler<Promise<lsProtocol.Hover | undefined>>;
130+
private debounced_get_hover: Throttler<
131+
Promise<lsProtocol.Hover | undefined | null>
132+
>;
126133
private tooltip: FreeTooltip;
127134
private _previousHoverRequest: Promise<
128-
Promise<lsProtocol.Hover | undefined>
135+
Promise<lsProtocol.Hover | undefined | null>
129136
> | null = null;
130137

131138
constructor(options: IEditorIntegrationOptions) {
@@ -154,13 +161,7 @@ export class HoverCM extends CodeMirrorIntegration {
154161
return false;
155162
}
156163
let range = cache_item.response.range!;
157-
return (
158-
line >= range.start.line &&
159-
line <= range.end.line &&
160-
// need to be non-overlapping see https://github.com/jupyter-lsp/jupyterlab-lsp/issues/628
161-
(line != range.start.line || ch > range.start.character) &&
162-
(line != range.end.line || ch <= range.end.character)
163-
);
164+
return ProtocolCoordinates.isWithinRange({ line, character: ch }, range);
164165
});
165166
if (matching_items.length > 1) {
166167
this.console.warn(
@@ -250,10 +251,13 @@ export class HoverCM extends CodeMirrorIntegration {
250251
}
251252

252253
protected create_throttler() {
253-
return new Throttler<Promise<lsProtocol.Hover | undefined>>(this.on_hover, {
254-
limit: this.settings.composite.throttlerDelay,
255-
edge: 'trailing'
256-
});
254+
return new Throttler<Promise<lsProtocol.Hover | undefined | null>>(
255+
this.on_hover,
256+
{
257+
limit: this.settings.composite.throttlerDelay,
258+
edge: 'trailing'
259+
}
260+
);
257261
}
258262

259263
afterChange(change: IEditorChange, root_position: IRootPosition) {

0 commit comments

Comments
 (0)