Skip to content

Commit

Permalink
Port highlights feature, improve hover, WIP syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jul 8, 2023
1 parent bc723da commit da7ab8f
Show file tree
Hide file tree
Showing 13 changed files with 703 additions and 483 deletions.
5 changes: 5 additions & 0 deletions packages/jupyterlab-lsp/src/command_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ export class ContextAssembler {
top: number,
adapter: WidgetLSPAdapter<any>
): IRootPosition | null {
// TODO: this relies on the editor under the cursor being the active editor;
// this may not be the case. Instead we should find editor from DOM and then
// have a magic way of transforming editor instances into CodeEditor and Document.Editor
// a naive way is to iterate all the editors in adapter (=cells) and see which one matches
// but the predicate is expensive and fallible in windowed notebook.
const editorAccessor = adapter.activeEditor;

if (!editorAccessor) {
Expand Down
39 changes: 38 additions & 1 deletion packages/jupyterlab-lsp/src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ export class PositionConverter {
}
}

/** TODO should it be wrapped into an object? */
/** TODO should it be wrapped into an object? Where should these live? */

export interface IEditorRange {
start: IEditorPosition;
end: IEditorPosition;
editor: CodeEditor.IEditor;
}

export function documentAtRootPosition(
adapter: WidgetLSPAdapter<any>,
Expand Down Expand Up @@ -116,3 +122,34 @@ export function editorPositionToRootPosition(
}
return adapter.virtualDocument.transformFromEditorToRoot(editor, position);
}

export function rangeToEditorRange(
adapter: WidgetLSPAdapter<any>,
range: lsProtocol.Range,
editor: CodeEditor.IEditor | null
): IEditorRange {
let start = PositionConverter.lsp_to_cm(range.start) as IVirtualPosition;
let end = PositionConverter.lsp_to_cm(range.end) as IVirtualPosition;

let startInRoot = virtualPositionToRootPosition(adapter, start);
if (!startInRoot) {
throw Error('Could not determine position in root');
}

if (editor == null) {
let editorAccessor = editorAtRootPosition(adapter, startInRoot);
const candidate = editorAccessor.getEditor();
if (!candidate) {
throw Error('Editor could not be accessed');
}
editor = candidate;
}

const document = documentAtRootPosition(adapter, startInRoot);

return {
start: document.transformVirtualToEditor(start)!,
end: document.transformVirtualToEditor(end)!,
editor: editor
};
}
8 changes: 0 additions & 8 deletions packages/jupyterlab-lsp/src/editor_integration/codemirror.ts

This file was deleted.

Loading

0 comments on commit da7ab8f

Please sign in to comment.