Skip to content

Commit

Permalink
Re-register native completion providers when LSP completion is disabl…
Browse files Browse the repository at this point in the history
…ed (#1036)

* Re-register native completion providers when LSP completion is disabled

* Disable, not disabled

* Update changelog, bump versions

* Fix test: `test` completion gets suggested from context

even when lsp is off (with type "Statement" in CM6)
  • Loading branch information
krassowski authored Jan 17, 2024
1 parent 00ef504 commit 1f1ddca
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 37 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## Changelog

### `@jupyter-lsp/jupyterlab-lsp 5.0.2`

- bug fixes:
- fix native JupyterLab completion not working when LSP completion plugin is disabled (#1036)

### `jupyter-lsp 2.2.2`

- bug fixes:
- address warning about renamed `extension_points` (#1035)
- fix compatibility with jupyter server 1.x

### `@jupyter-lsp/jupyterlab-lsp 5.0.1`

- bug fixes:
Expand Down
6 changes: 6 additions & 0 deletions atest/05_Features/Completion.robot
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Works When Kernel Is Idle
${content} = Get Cell Editor Content 1
Should Contain ${content} TabError

Does Not Break Native Completions When Disabled
Configure JupyterLab Plugin {"disable": true} plugin id=${COMPLETION PLUGIN ID}
Enter Cell Editor 1 line=2
Trigger Completer
Completer Should Suggest try

Filters Completions In Case Sensitive Mode
[Documentation] Completions filtering is case-sensitive when caseSensitive is true
Configure JupyterLab Plugin {"caseSensitive": true} plugin id=${COMPLETION PLUGIN ID}
Expand Down
2 changes: 1 addition & 1 deletion packages/jupyterlab-lsp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-lsp/jupyterlab-lsp",
"version": "5.0.1",
"version": "5.0.2",
"description": "Language Server Protocol integration for JupyterLab",
"keywords": [
"jupyter",
Expand Down
92 changes: 60 additions & 32 deletions packages/jupyterlab-lsp/src/features/completion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { ICompletionProviderManager } from '@jupyterlab/completer';
import {
ICompletionProviderManager,
ContextCompleterProvider,
KernelCompleterProvider
} from '@jupyterlab/completer';
import {
ILSPFeatureManager,
ILSPDocumentConnectionManager
Expand All @@ -24,6 +28,7 @@ import {
EnhancedKernelCompleterProvider
} from './overrides';
import { CompletionProvider } from './provider';
import { ICompletionFeature } from './tokens';

export const completionIcon = new LabIcon({
name: 'lsp:completion',
Expand Down Expand Up @@ -94,42 +99,65 @@ export namespace CompletionFeature {
export const id = PLUGIN_ID + ':completion';
}

export const COMPLETION_PLUGIN: JupyterFrontEndPlugin<void> = {
id: CompletionFeature.id,
requires: [
ILSPFeatureManager,
ISettingRegistry,
ICompletionProviderManager,
ILSPCompletionThemeManager,
IRenderMimeRegistry,
ILSPDocumentConnectionManager
],
export const COMPLETION_PLUGIN: JupyterFrontEndPlugin<ICompletionFeature | null> =
{
id: CompletionFeature.id,
requires: [
ILSPFeatureManager,
ISettingRegistry,
ICompletionProviderManager,
ILSPCompletionThemeManager,
IRenderMimeRegistry,
ILSPDocumentConnectionManager
],
autoStart: true,
activate: async (
app: JupyterFrontEnd,
featureManager: ILSPFeatureManager,
settingRegistry: ISettingRegistry,
completionProviderManager: ICompletionProviderManager,
iconsThemeManager: ILSPCompletionThemeManager,
renderMimeRegistry: IRenderMimeRegistry,
connectionManager: ILSPDocumentConnectionManager
): Promise<ICompletionFeature | null> => {
const settings = new FeatureSettings<LSPCompletionSettings>(
settingRegistry,
CompletionFeature.id
);
await settings.ready;
if (settings.composite.disable) {
return null;
}
const feature = new CompletionFeature({
settings,
connectionManager,
renderMimeRegistry,
iconsThemeManager,
completionProviderManager
});

featureManager.register(feature);
return { id: CompletionFeature.id };
}
};

export const COMPLETION_FALLBACK_PLUGIN: JupyterFrontEndPlugin<void> = {
id: CompletionFeature.id + '-fallback',
description:
'Plugin which restores the default completion provider when the LSP completion plugin is disabled',
requires: [ICompletionProviderManager],
optional: [ICompletionFeature],
autoStart: true,
activate: async (
app: JupyterFrontEnd,
featureManager: ILSPFeatureManager,
settingRegistry: ISettingRegistry,
completionProviderManager: ICompletionProviderManager,
iconsThemeManager: ILSPCompletionThemeManager,
renderMimeRegistry: IRenderMimeRegistry,
connectionManager: ILSPDocumentConnectionManager
completionFeature: ICompletionFeature | null
) => {
const settings = new FeatureSettings<LSPCompletionSettings>(
settingRegistry,
CompletionFeature.id
);
await settings.ready;
if (settings.composite.disable) {
return;
if (completionFeature == null) {
completionProviderManager.registerProvider(
new ContextCompleterProvider()
);
completionProviderManager.registerProvider(new KernelCompleterProvider());
}
const feature = new CompletionFeature({
settings,
connectionManager,
renderMimeRegistry,
iconsThemeManager,
completionProviderManager
});

featureManager.register(feature);
}
};
17 changes: 17 additions & 0 deletions packages/jupyterlab-lsp/src/features/completion/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Token } from '@lumino/coreutils';

import { PLUGIN_ID } from '../../tokens';

/**
* Token provided by the plugin which implements LSP completion.
* As of now no methods are exposed, but it still functions as
* an indicator for whether the LSP completion plugin is available,
* or whether it was disabled by the user (or failed to activate).
*/
export interface ICompletionFeature {
readonly id: string;
}

export const ICompletionFeature = new Token<ICompletionFeature>(
PLUGIN_ID + ':ICompletionFeature'
);
8 changes: 6 additions & 2 deletions packages/jupyterlab-lsp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import { LanguageServers } from './_plugin';
import { FILEEDITOR_ADAPTER_PLUGIN } from './adapters/fileeditor';
import { NOTEBOOK_ADAPTER_PLUGIN } from './adapters/notebook';
import { StatusButtonExtension } from './components/statusbar';
import { COMPLETION_PLUGIN } from './features/completion';
import {
COMPLETION_PLUGIN,
COMPLETION_FALLBACK_PLUGIN
} from './features/completion';
import { DIAGNOSTICS_PLUGIN } from './features/diagnostics';
import { HIGHLIGHTS_PLUGIN } from './features/highlights';
import { HOVER_PLUGIN } from './features/hover';
Expand Down Expand Up @@ -250,7 +253,8 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
FILEEDITOR_ADAPTER_PLUGIN,
plugin,
...DEFAULT_TRANSCLUSIONS,
...DEFAULT_FEATURES
...DEFAULT_FEATURES,
COMPLETION_FALLBACK_PLUGIN
];

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/metapackage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-lsp/jupyterlab-lsp-metapackage",
"version": "5.0.1",
"version": "5.0.2",
"description": "JupyterLab LSP - Meta Package. All of the packages used by JupyterLab LSP",
"homepage": "https://github.com/jupyter-lsp/jupyterlab-lsp",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion python_packages/jupyter_lsp/jupyter_lsp/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" single source of truth for jupyter_lsp version
"""
__version__ = "2.2.1"
__version__ = "2.2.2"

0 comments on commit 1f1ddca

Please sign in to comment.