Skip to content

Commit 42ad522

Browse files
authored
Deprecate the 'Build Workspace Symbols' command when jediEnabled = false (#2419)
- Deprecate the 'Build Workspace Symbols' command only when the new Python Language Server is active - expose deprecation information registration to support this - Move deprecated info for this command into the new `languageServer.ts` - Complete DI-ification of featureDeprecationManager, is now an injected module
1 parent 3ab005e commit 42ad522

11 files changed

Lines changed: 268 additions & 97 deletions

File tree

news/3 Code Health/2267.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate command 'Python: Build Workspace Symbols' when using the language server.

src/client/activation/languageServer.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ import {
1111
Disposable, LanguageClient, LanguageClientOptions,
1212
ProvideCompletionItemsSignature, ServerOptions
1313
} from 'vscode-languageclient';
14-
import { IApplicationShell, ICommandManager, IWorkspaceService } from '../common/application/types';
14+
import {
15+
IApplicationShell, ICommandManager, IWorkspaceService
16+
} from '../common/application/types';
1517
import { PythonSettings } from '../common/configSettings';
18+
// tslint:disable-next-line:ordered-imports
1619
import { isTestExecution, STANDARD_OUTPUT_CHANNEL } from '../common/constants';
1720
import { createDeferred, Deferred } from '../common/helpers';
1821
import { IFileSystem, IPlatformService } from '../common/platform/types';
1922
import { StopWatch } from '../common/stopWatch';
2023
import {
21-
BANNER_NAME_LS_SURVEY, IConfigurationService, IExtensionContext, ILogger,
22-
IOutputChannel, IPythonExtensionBanner, IPythonSettings
24+
BANNER_NAME_LS_SURVEY, DeprecatedFeatureInfo, IConfigurationService,
25+
IExtensionContext, IFeatureDeprecationManager, ILogger, IOutputChannel,
26+
IPythonExtensionBanner, IPythonSettings
2327
} from '../common/types';
2428
import { IServiceContainer } from '../ioc/types';
2529
import {
@@ -41,6 +45,12 @@ const dotNetCommand = 'dotnet';
4145
const languageClientName = 'Python Tools';
4246
const languageServerFolder = 'languageServer';
4347
const loadExtensionCommand = 'python._loadLanguageServerExtension';
48+
const buildSymbolsCmdDeprecatedInfo: DeprecatedFeatureInfo = {
49+
doNotDisplayPromptStateKey: 'SHOW_DEPRECATED_FEATURE_PROMPT_BUILD_WORKSPACE_SYMBOLS',
50+
message: 'The command \'Python: Build Workspace Symbols\' is deprecated when using the Python Language Server. The Python Language Server builds symbols in the workspace in the background.',
51+
moreInfoUrl: 'https://github.com/Microsoft/vscode-python/issues/2267#issuecomment-408996859',
52+
commands: ['python.buildWorkspaceSymbols']
53+
};
4454

4555
@injectable()
4656
export class LanguageServerExtensionActivator implements IExtensionActivator {
@@ -73,6 +83,8 @@ export class LanguageServerExtensionActivator implements IExtensionActivator {
7383
this.fs = this.services.get<IFileSystem>(IFileSystem);
7484
this.platformData = new PlatformData(services.get<IPlatformService>(IPlatformService), this.fs);
7585
this.workspace = this.services.get<IWorkspaceService>(IWorkspaceService);
86+
const deprecationManager: IFeatureDeprecationManager =
87+
this.services.get<IFeatureDeprecationManager>(IFeatureDeprecationManager);
7688

7789
// Currently only a single root. Multi-root support is future.
7890
this.root = this.workspace && this.workspace.hasWorkspaceFolders
@@ -92,6 +104,8 @@ export class LanguageServerExtensionActivator implements IExtensionActivator {
92104
}
93105
));
94106

107+
deprecationManager.registerDeprecation(buildSymbolsCmdDeprecatedInfo);
108+
95109
this.surveyBanner = services.get<IPythonExtensionBanner>(IPythonExtensionBanner, BANNER_NAME_LS_SURVEY);
96110

97111
(this.configuration.getSettings() as PythonSettings).addListener('change', this.onSettingsChanged.bind(this));
Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { commands, Disposable, window, workspace, WorkspaceConfiguration } from 'vscode';
4+
import { inject, injectable } from 'inversify';
5+
import { Disposable, WorkspaceConfiguration } from 'vscode';
6+
import {
7+
IApplicationShell, ICommandManager, IWorkspaceService
8+
} from './application/types';
59
import { launch } from './net/browser';
6-
import { IPersistentStateFactory } from './types';
10+
import {
11+
DeprecatedFeatureInfo, DeprecatedSettingAndValue,
12+
IFeatureDeprecationManager, IPersistentStateFactory
13+
} from './types';
714

8-
type deprecatedFeatureInfo = {
9-
doNotDisplayPromptStateKey: string;
10-
message: string;
11-
moreInfoUrl: string;
12-
commands?: string[];
13-
setting?: deprecatedSettingAndValue;
14-
};
15-
16-
type deprecatedSettingAndValue = {
17-
setting: string;
18-
values?: {}[];
19-
};
20-
21-
const deprecatedFeatures: deprecatedFeatureInfo[] = [
15+
const deprecatedFeatures: DeprecatedFeatureInfo[] = [
2216
{
2317
doNotDisplayPromptStateKey: 'SHOW_DEPRECATED_FEATURE_PROMPT_FORMAT_ON_SAVE',
2418
message: 'The setting \'python.formatting.formatOnSave\' is deprecated, please use \'editor.formatOnSave\'.',
@@ -33,64 +27,43 @@ const deprecatedFeatures: deprecatedFeatureInfo[] = [
3327
}
3428
];
3529

36-
export interface IFeatureDeprecationManager extends Disposable {
37-
initialize(): void;
38-
}
39-
30+
@injectable()
4031
export class FeatureDeprecationManager implements IFeatureDeprecationManager {
4132
private disposables: Disposable[] = [];
42-
constructor(private persistentStateFactory: IPersistentStateFactory, private jupyterExtensionInstalled: boolean) { }
33+
constructor(
34+
@inject(IPersistentStateFactory) private persistentStateFactory: IPersistentStateFactory,
35+
@inject(ICommandManager) private cmdMgr: ICommandManager,
36+
@inject(IWorkspaceService) private workspace: IWorkspaceService,
37+
@inject(IApplicationShell) private appShell: IApplicationShell
38+
) { }
39+
4340
public dispose() {
4441
this.disposables.forEach(disposable => disposable.dispose());
4542
}
43+
4644
public initialize() {
4745
deprecatedFeatures.forEach(this.registerDeprecation.bind(this));
4846
}
49-
private registerDeprecation(deprecatedInfo: deprecatedFeatureInfo) {
47+
48+
public registerDeprecation(deprecatedInfo: DeprecatedFeatureInfo): void {
5049
if (Array.isArray(deprecatedInfo.commands)) {
5150
deprecatedInfo.commands.forEach(cmd => {
52-
this.disposables.push(commands.registerCommand(cmd, () => this.notifyDeprecation(deprecatedInfo), this));
51+
this.disposables.push(this.cmdMgr.registerCommand(cmd, () => this.notifyDeprecation(deprecatedInfo), this));
5352
});
5453
}
5554
if (deprecatedInfo.setting) {
5655
this.checkAndNotifyDeprecatedSetting(deprecatedInfo);
5756
}
5857
}
59-
private checkAndNotifyDeprecatedSetting(deprecatedInfo: deprecatedFeatureInfo) {
60-
let notify = false;
61-
if (Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length > 0) {
62-
workspace.workspaceFolders.forEach(workspaceFolder => {
63-
if (notify) {
64-
return;
65-
}
66-
notify = this.isDeprecatedSettingAndValueUsed(workspace.getConfiguration('python', workspaceFolder.uri), deprecatedInfo.setting!);
67-
});
68-
} else {
69-
notify = this.isDeprecatedSettingAndValueUsed(workspace.getConfiguration('python'), deprecatedInfo.setting!);
70-
}
7158

72-
if (notify) {
73-
this.notifyDeprecation(deprecatedInfo)
74-
.catch(ex => console.error('Python Extension: notifyDeprecation', ex));
75-
}
76-
}
77-
private isDeprecatedSettingAndValueUsed(pythonConfig: WorkspaceConfiguration, deprecatedSetting: deprecatedSettingAndValue) {
78-
if (!pythonConfig.has(deprecatedSetting.setting)) {
79-
return false;
80-
}
81-
if (!Array.isArray(deprecatedSetting.values) || deprecatedSetting.values.length === 0) {
82-
return true;
83-
}
84-
return deprecatedSetting.values.indexOf(pythonConfig.get(deprecatedSetting.setting)!) >= 0;
85-
}
86-
private async notifyDeprecation(deprecatedInfo: deprecatedFeatureInfo) {
59+
private async notifyDeprecation(deprecatedInfo: DeprecatedFeatureInfo): Promise<void> {
8760
const notificationPromptEnabled = this.persistentStateFactory.createGlobalPersistentState(deprecatedInfo.doNotDisplayPromptStateKey, true);
8861
if (!notificationPromptEnabled.value) {
8962
return;
9063
}
9164
const moreInfo = 'Learn more';
9265
const doNotShowAgain = 'Never show again';
93-
const option = await window.showInformationMessage(deprecatedInfo.message, moreInfo, doNotShowAgain);
66+
const option = await this.appShell.showInformationMessage(deprecatedInfo.message, moreInfo, doNotShowAgain);
9467
if (!option) {
9568
return;
9669
}
@@ -107,5 +80,35 @@ export class FeatureDeprecationManager implements IFeatureDeprecationManager {
10780
throw new Error('Selected option not supported.');
10881
}
10982
}
83+
return;
84+
}
85+
86+
private checkAndNotifyDeprecatedSetting(deprecatedInfo: DeprecatedFeatureInfo) {
87+
let notify = false;
88+
if (Array.isArray(this.workspace.workspaceFolders) && this.workspace.workspaceFolders.length > 0) {
89+
this.workspace.workspaceFolders.forEach(workspaceFolder => {
90+
if (notify) {
91+
return;
92+
}
93+
notify = this.isDeprecatedSettingAndValueUsed(this.workspace.getConfiguration('python', workspaceFolder.uri), deprecatedInfo.setting!);
94+
});
95+
} else {
96+
notify = this.isDeprecatedSettingAndValueUsed(this.workspace.getConfiguration('python'), deprecatedInfo.setting!);
97+
}
98+
99+
if (notify) {
100+
this.notifyDeprecation(deprecatedInfo)
101+
.catch(ex => console.error('Python Extension: notifyDeprecation', ex));
102+
}
103+
}
104+
105+
private isDeprecatedSettingAndValueUsed(pythonConfig: WorkspaceConfiguration, deprecatedSetting: DeprecatedSettingAndValue) {
106+
if (!pythonConfig.has(deprecatedSetting.setting)) {
107+
return false;
108+
}
109+
if (!Array.isArray(deprecatedSetting.values) || deprecatedSetting.values.length === 0) {
110+
return true;
111+
}
112+
return deprecatedSetting.values.indexOf(pythonConfig.get(deprecatedSetting.setting)!) >= 0;
110113
}
111114
}

src/client/common/serviceRegistry.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import { CommandManager } from './application/commandManager';
88
import { DebugService } from './application/debugService';
99
import { DocumentManager } from './application/documentManager';
1010
import { TerminalManager } from './application/terminalManager';
11-
import { IApplicationEnvironment, IApplicationShell, ICommandManager, IDebugService, IDocumentManager, ITerminalManager, IWorkspaceService } from './application/types';
11+
import {
12+
IApplicationEnvironment, IApplicationShell, ICommandManager,
13+
IDebugService, IDocumentManager, ITerminalManager, IWorkspaceService
14+
} from './application/types';
1215
import { WorkspaceService } from './application/workspace';
1316
import { ConfigurationService } from './configuration/service';
17+
import { FeatureDeprecationManager } from './featureDeprecationManager';
1418
import { ProductInstaller } from './installer/productInstaller';
1519
import { Logger } from './logger';
1620
import { BrowserService } from './net/browser';
@@ -19,11 +23,21 @@ import { IS_64_BIT, IS_WINDOWS } from './platform/constants';
1923
import { PathUtils } from './platform/pathUtils';
2024
import { CurrentProcess } from './process/currentProcess';
2125
import { Bash } from './terminal/environmentActivationProviders/bash';
22-
import { CommandPromptAndPowerShell } from './terminal/environmentActivationProviders/commandPrompt';
26+
import {
27+
CommandPromptAndPowerShell
28+
} from './terminal/environmentActivationProviders/commandPrompt';
2329
import { TerminalServiceFactory } from './terminal/factory';
2430
import { TerminalHelper } from './terminal/helper';
25-
import { ITerminalActivationCommandProvider, ITerminalHelper, ITerminalServiceFactory } from './terminal/types';
26-
import { IBrowserService, IConfigurationService, ICurrentProcess, IInstaller, ILogger, IPathUtils, IPersistentStateFactory, IRandom, Is64Bit, IsWindows } from './types';
31+
import {
32+
ITerminalActivationCommandProvider,
33+
ITerminalHelper, ITerminalServiceFactory
34+
} from './terminal/types';
35+
import {
36+
IBrowserService, IConfigurationService, ICurrentProcess,
37+
IFeatureDeprecationManager, IInstaller, ILogger,
38+
IPathUtils, IPersistentStateFactory,
39+
IRandom, Is64Bit, IsWindows
40+
} from './types';
2741
import { Random } from './utils';
2842

2943
export function registerTypes(serviceManager: IServiceManager) {
@@ -48,6 +62,9 @@ export function registerTypes(serviceManager: IServiceManager) {
4862
serviceManager.addSingleton<IBrowserService>(IBrowserService, BrowserService);
4963

5064
serviceManager.addSingleton<ITerminalHelper>(ITerminalHelper, TerminalHelper);
51-
serviceManager.addSingleton<ITerminalActivationCommandProvider>(ITerminalActivationCommandProvider, Bash, 'bashCShellFish');
52-
serviceManager.addSingleton<ITerminalActivationCommandProvider>(ITerminalActivationCommandProvider, CommandPromptAndPowerShell, 'commandPromptAndPowerShell');
65+
serviceManager.addSingleton<ITerminalActivationCommandProvider>(
66+
ITerminalActivationCommandProvider, Bash, 'bashCShellFish');
67+
serviceManager.addSingleton<ITerminalActivationCommandProvider>(
68+
ITerminalActivationCommandProvider, CommandPromptAndPowerShell, 'commandPromptAndPowerShell');
69+
serviceManager.addSingleton<IFeatureDeprecationManager>(IFeatureDeprecationManager, FeatureDeprecationManager);
5370
}

src/client/common/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,23 @@ export interface IPythonExtensionBanner {
283283
}
284284
export const BANNER_NAME_LS_SURVEY: string = 'LSSurveyBanner';
285285
export const BANNER_NAME_PROPOSE_LS: string = 'ProposeLS';
286+
287+
export type DeprecatedSettingAndValue = {
288+
setting: string;
289+
values?: {}[];
290+
};
291+
292+
export type DeprecatedFeatureInfo = {
293+
doNotDisplayPromptStateKey: string;
294+
message: string;
295+
moreInfoUrl: string;
296+
commands?: string[];
297+
setting?: DeprecatedSettingAndValue;
298+
};
299+
300+
export const IFeatureDeprecationManager = Symbol('IFeatureDeprecationManager');
301+
302+
export interface IFeatureDeprecationManager extends Disposable {
303+
initialize(): void;
304+
registerDeprecation(deprecatedInfo: DeprecatedFeatureInfo): void;
305+
}

src/client/extension.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ import { IApplicationDiagnostics } from './application/types';
1818
import { IWorkspaceService } from './common/application/types';
1919
import { PythonSettings } from './common/configSettings';
2020
import { PYTHON, PYTHON_LANGUAGE, STANDARD_OUTPUT_CHANNEL } from './common/constants';
21-
import { FeatureDeprecationManager } from './common/featureDeprecationManager';
2221
import { createDeferred } from './common/helpers';
2322
import { PythonInstaller } from './common/installer/pythonInstallation';
2423
import { registerTypes as installerRegisterTypes } from './common/installer/serviceRegistry';
2524
import { registerTypes as platformRegisterTypes } from './common/platform/serviceRegistry';
2625
import { registerTypes as processRegisterTypes } from './common/process/serviceRegistry';
2726
import { registerTypes as commonRegisterTypes } from './common/serviceRegistry';
2827
import { ITerminalHelper } from './common/terminal/types';
29-
import { GLOBAL_MEMENTO, IConfigurationService, IDisposableRegistry,
30-
IExtensionContext, ILogger, IMemento, IOutputChannel,
31-
IPersistentStateFactory, WORKSPACE_MEMENTO } from './common/types';
28+
import {
29+
GLOBAL_MEMENTO, IConfigurationService, IDisposableRegistry,
30+
IExtensionContext, IFeatureDeprecationManager, ILogger,
31+
IMemento, IOutputChannel, WORKSPACE_MEMENTO
32+
} from './common/types';
3233
import { registerTypes as variableRegisterTypes } from './common/variables/serviceRegistry';
3334
import { AttachRequestArguments, LaunchRequestArguments } from './debugger/Common/Contracts';
3435
import { BaseConfigurationProvider } from './debugger/configProviders/baseProvider';
@@ -141,10 +142,9 @@ export async function activate(context: ExtensionContext) {
141142
context.subscriptions.push(languages.registerOnTypeFormattingEditProvider(PYTHON, new BlockFormatProviders(), ':'));
142143
context.subscriptions.push(languages.registerOnTypeFormattingEditProvider(PYTHON, new OnEnterFormatter(), '\n'));
143144

144-
const persistentStateFactory = serviceManager.get<IPersistentStateFactory>(IPersistentStateFactory);
145-
const deprecationMgr = new FeatureDeprecationManager(persistentStateFactory, !!jupyterExtension);
145+
const deprecationMgr = serviceContainer.get<IFeatureDeprecationManager>(IFeatureDeprecationManager);
146146
deprecationMgr.initialize();
147-
context.subscriptions.push(new FeatureDeprecationManager(persistentStateFactory, !!jupyterExtension));
147+
context.subscriptions.push(deprecationMgr);
148148

149149
context.subscriptions.push(serviceContainer.get<IInterpreterSelector>(IInterpreterSelector));
150150
context.subscriptions.push(activateUpdateSparkLibraryProvider());

0 commit comments

Comments
 (0)