Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source-aware completions and more completer settings #549

Merged
merged 7 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- features:

- adds `%%bigquery` IPython cell magic support for BigQuery ([#553], thanks @julioyildo)
- completions filtering can be set to case-insensitive in settings ([#549])
- completions filtering can hide exact matches ([#549])
- the extra information displayed next to the completion label now can include 'detail' (usually module/package of origin), and can be customized in settings ([#549])

- bug fixes:

Expand All @@ -18,6 +21,7 @@

[#544]: https://github.com/krassowski/jupyterlab-lsp/pull/544
[#547]: https://github.com/krassowski/jupyterlab-lsp/pull/547
[#549]: https://github.com/krassowski/jupyterlab-lsp/pull/549
[#553]: https://github.com/krassowski/jupyterlab-lsp/pull/553
[#560]: https://github.com/krassowski/jupyterlab-lsp/pull/560
[#562]: https://github.com/krassowski/jupyterlab-lsp/pull/562
Expand Down
19 changes: 19 additions & 0 deletions packages/jupyterlab-lsp/schema/completion.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@
"default": false,
"description": "In case of ties when sorting completions, should the kernel completions receive higher priority than the language server completions?"
},
"caseSensitive": {
"title": "Case-sensitive filtering",
"default": true,
"type": "boolean",
"description": "Should completion filtering be case-sensitive?"
},
"includePerfectMatches": {
"title": "Include perfect matches",
"default": true,
"type": "boolean",
"description": "Should perfect matches be included in the completion suggestions list?"
},
"labelExtra": {
"title": "Text to display next to completion label",
"default": "auto",
"type": "string",
"enum": ["detail", "type", "source", "auto"],
"description": "What to display next to the completion label, one of: 'detail', 'type', 'source', 'auto'. The default 'auto' will display whichever information is available."
},
"typesMap": {
"title": "Mapping of custom kernel types to valid completion kind names",
"description": "Mapping used for icon selection. The kernel types (keys) are case-insensitive. Accepted values are the names of CompletionItemKind and 'Kernel' literal. The defaults aim to provide good initial experience for Julia, Python and R kernels.",
Expand Down
75 changes: 69 additions & 6 deletions packages/jupyterlab-lsp/src/features/completion/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { IDocumentConnectionData } from '../../connection_manager';
import { ILSPAdapterManager, ILSPLogConsole } from '../../tokens';
import { NotebookAdapter } from '../../adapters/notebook/notebook';
import { ILSPCompletionThemeManager } from '@krassowski/completion-theme/lib/types';
import { LSPCompletionRenderer } from './renderer';
import { ICompletionData, LSPCompletionRenderer } from './renderer';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { LSPCompleterModel } from './model';
import { LazyCompletionItem } from './item';
Expand Down Expand Up @@ -105,19 +105,44 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
console: console.scope('renderer')
});
this.renderer.activeChanged.connect(this.active_completion_changed, this);
this.renderer.itemShown.connect(this.resolve_and_update, this);
adapterManager.adapterChanged.connect(this.swap_adapter, this);
settings.changed.connect(() => {
completionThemeManager.set_theme(this.settings.composite.theme);
completionThemeManager.set_icons_overrides(
this.settings.composite.typesMap
);
if (this.current_completion_handler) {
this.model.settings.caseSensitive = this.settings.composite.caseSensitive;
this.model.settings.includePerfectMatches = this.settings.composite.includePerfectMatches;
}
});
}

protected fetchDocumentation(item: LazyCompletionItem): void {
if (!item) {
return;
}
item
.resolve()
.then(resolvedCompletionItem => {
this.set_doc_panel_placeholder(false);
if (resolvedCompletionItem === null) {
return;
}
this.refresh_doc_panel(item);
})
.catch(e => {
this.set_doc_panel_placeholder(false);
console.warn(e);
});
}

active_completion_changed(
renderer: LSPCompletionRenderer,
item: LazyCompletionItem
active_completion: ICompletionData
) {
let { item } = active_completion;
if (!item.supportsResolution()) {
if (item.isDocumentationMarkdown) {
// TODO: remove once https://github.com/jupyterlab/jupyterlab/pull/9663 is merged and released
Expand All @@ -128,7 +153,7 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {

if (item.needsResolution()) {
this.set_doc_panel_placeholder(true);
item.fetchDocumentation();
this.fetchDocumentation(item);
} else if (item.isResolved()) {
this.refresh_doc_panel(item);
}
Expand All @@ -139,11 +164,46 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {

if (index - 1 >= 0) {
const previous = items[index - 1] as LazyCompletionItem;
previous?.self?.fetchDocumentation();
this.resolve_and_update_from_item(previous?.self);
}
if (index + 1 < items.length) {
const next = items[index + 1] as LazyCompletionItem;
next?.self?.fetchDocumentation();
this.resolve_and_update_from_item(next?.self);
}
}

private resolve_and_update_from_item(item: LazyCompletionItem) {
if (!item) {
return;
}
this.resolve_and_update(this.renderer, {
item: item,
element: item.element
});
}

private resolve_and_update(
renderer: LSPCompletionRenderer,
active_completion: ICompletionData
) {
let { item, element } = active_completion;
if (!item.supportsResolution()) {
this.renderer.updateExtraInfo(item, element);
return;
}

if (item.isResolved()) {
this.renderer.updateExtraInfo(item, element);
} else {
// supportsResolution as otherwise would short-circuit above
item
.resolve()
.then(resolvedCompletionItem => {
this.renderer.updateExtraInfo(item, element);
})
.catch(e => {
this.console.warn(e);
});
}
}

Expand Down Expand Up @@ -195,7 +255,10 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
) as CompletionHandler;
let completer = this.completer;
completer.addClass('lsp-completer');
completer.model = new LSPCompleterModel();
completer.model = new LSPCompleterModel({
caseSensitive: this.settings.composite.caseSensitive,
includePerfectMatches: this.settings.composite.includePerfectMatches
});
}

protected get completer() {
Expand Down
Loading