Skip to content

Commit

Permalink
Enable feature based on version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
debonte committed Jul 21, 2022
1 parent 1b6707f commit b069e0a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/client/activation/node/analysisOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class NodeLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
experimentationSupport: true,
trustedWorkspaceSupport: true,
lspNotebooksSupport: this.lspNotebooksExperiment.isInNotebooksExperiment(),
lspInteractiveWindowSupport: this.lspNotebooksExperiment.isInNotebooksExperimentWithInteractiveWindowSupport(),
} as unknown) as LanguageClientOptions;
}
}
33 changes: 33 additions & 0 deletions src/client/activation/node/lspNotebooksExperiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class LspNotebooksExperiment implements IExtensionSingleActivationService

private isInExperiment: boolean | undefined;

private supportsInteractiveWindow: boolean | undefined;

constructor(
@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer,
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
Expand Down Expand Up @@ -60,6 +62,10 @@ export class LspNotebooksExperiment implements IExtensionSingleActivationService
return this.isInExperiment ?? false;
}

public isInNotebooksExperimentWithInteractiveWindowSupport(): boolean {
return this.supportsInteractiveWindow ?? false;
}

private updateExperimentSupport(): void {
const wasInExperiment = this.isInExperiment;
const isInTreatmentGroup = this.configurationService.getSettings().pylanceLspNotebooksEnabled;
Expand Down Expand Up @@ -87,6 +93,18 @@ export class LspNotebooksExperiment implements IExtensionSingleActivationService
sendTelemetryEvent(EventName.PYTHON_EXPERIMENTS_LSP_NOTEBOOKS);
}

this.supportsInteractiveWindow = false;
if (!this.isInExperiment) {
traceLog(`LSP Notebooks interactive window support is disabled -- not in LSP Notebooks experiment`);
} else if (!LspNotebooksExperiment.jupyterSupportsLspInteractiveWindow()) {
traceLog(`LSP Notebooks interactive window support is disabled -- Jupyter is not new enough`);
} else if (!LspNotebooksExperiment.pylanceSupportsLspInteractiveWindow()) {
traceLog(`LSP Notebooks interactive window support is disabled -- Pylance is not new enough`);
} else {
this.supportsInteractiveWindow = true;
traceLog(`LSP Notebooks interactive window support is enabled`);
}

// Our "in experiment" status can only change from false to true. That's possible if Pylance
// or Jupyter is installed after Python is activated. A true to false transition would require
// either Pylance or Jupyter to be uninstalled or downgraded after Python activated, and that
Expand Down Expand Up @@ -114,6 +132,21 @@ export class LspNotebooksExperiment implements IExtensionSingleActivationService
);
}

private static jupyterSupportsLspInteractiveWindow(): boolean {
const jupyterVersion = extensions.getExtension(JUPYTER_EXTENSION_ID)?.packageJSON.version;
return (
jupyterVersion && (semver.gt(jupyterVersion, '2022.7.1002041057') || semver.patch(jupyterVersion) === 100)
);
}

private static pylanceSupportsLspInteractiveWindow(): boolean {
const pylanceVersion = extensions.getExtension(PYLANCE_EXTENSION_ID)?.packageJSON.version;
return (
pylanceVersion &&
(semver.gte(pylanceVersion, '2022.7.41') || semver.prerelease(pylanceVersion)?.includes('dev'))
);
}

private async waitForJupyterToRegisterPythonPathFunction(): Promise<void> {
const jupyterExtensionIntegration = this.serviceContainer.get<JupyterExtensionIntegration>(
JupyterExtensionIntegration,
Expand Down

0 comments on commit b069e0a

Please sign in to comment.