Skip to content

Commit 77c63f1

Browse files
authored
Remove Pylance auto-indent experiment code (#21088)
1 parent 9bb5a44 commit 77c63f1

File tree

3 files changed

+5
-92
lines changed

3 files changed

+5
-92
lines changed
Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { ConfigurationTarget, extensions, WorkspaceConfiguration } from 'vscode';
54
import { LanguageClientOptions } from 'vscode-languageclient';
6-
import * as semver from 'semver';
75
import { IWorkspaceService } from '../../common/application/types';
8-
import { PYLANCE_EXTENSION_ID } from '../../common/constants';
9-
import { IExperimentService } from '../../common/types';
106

117
import { LanguageServerAnalysisOptionsBase } from '../common/analysisOptions';
128
import { ILanguageServerOutputChannel } from '../types';
13-
import { traceWarn } from '../../logging';
14-
15-
const EDITOR_CONFIG_SECTION = 'editor';
16-
const FORMAT_ON_TYPE_CONFIG_SETTING = 'formatOnType';
179

1810
export class NodeLanguageServerAnalysisOptions extends LanguageServerAnalysisOptionsBase {
1911
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
20-
constructor(
21-
lsOutputChannel: ILanguageServerOutputChannel,
22-
workspace: IWorkspaceService,
23-
private readonly experimentService: IExperimentService,
24-
) {
12+
constructor(lsOutputChannel: ILanguageServerOutputChannel, workspace: IWorkspaceService) {
2513
super(lsOutputChannel, workspace);
2614
}
2715

@@ -34,72 +22,6 @@ export class NodeLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
3422
return ({
3523
experimentationSupport: true,
3624
trustedWorkspaceSupport: true,
37-
autoIndentSupport: await this.isAutoIndentEnabled(),
3825
} as unknown) as LanguageClientOptions;
3926
}
40-
41-
private async isAutoIndentEnabled() {
42-
let editorConfig = this.getPythonSpecificEditorSection();
43-
44-
// Only explicitly enable formatOnType for those who are in the experiment
45-
// but have not explicitly given a value for the setting
46-
if (!NodeLanguageServerAnalysisOptions.isConfigSettingSetByUser(editorConfig, FORMAT_ON_TYPE_CONFIG_SETTING)) {
47-
const inExperiment = await this.isInAutoIndentExperiment();
48-
if (inExperiment) {
49-
await NodeLanguageServerAnalysisOptions.setPythonSpecificFormatOnType(editorConfig, true);
50-
51-
// Refresh our view of the config settings.
52-
editorConfig = this.getPythonSpecificEditorSection();
53-
}
54-
}
55-
56-
const formatOnTypeEffectiveValue = editorConfig.get(FORMAT_ON_TYPE_CONFIG_SETTING);
57-
58-
return formatOnTypeEffectiveValue;
59-
}
60-
61-
private static isConfigSettingSetByUser(configuration: WorkspaceConfiguration, setting: string): boolean {
62-
const inspect = configuration.inspect(setting);
63-
if (inspect === undefined) {
64-
return false;
65-
}
66-
67-
return (
68-
inspect.globalValue !== undefined ||
69-
inspect.workspaceValue !== undefined ||
70-
inspect.workspaceFolderValue !== undefined ||
71-
inspect.globalLanguageValue !== undefined ||
72-
inspect.workspaceLanguageValue !== undefined ||
73-
inspect.workspaceFolderLanguageValue !== undefined
74-
);
75-
}
76-
77-
private async isInAutoIndentExperiment(): Promise<boolean> {
78-
if (await this.experimentService.inExperiment('pylanceAutoIndent')) {
79-
return true;
80-
}
81-
82-
const pylanceVersion = extensions.getExtension(PYLANCE_EXTENSION_ID)?.packageJSON.version as string;
83-
return pylanceVersion !== undefined && semver.prerelease(pylanceVersion)?.includes('dev') === true;
84-
}
85-
86-
private getPythonSpecificEditorSection() {
87-
return this.workspace.getConfiguration(EDITOR_CONFIG_SECTION, undefined, /* languageSpecific */ true);
88-
}
89-
90-
private static async setPythonSpecificFormatOnType(
91-
editorConfig: WorkspaceConfiguration,
92-
value: boolean | undefined,
93-
) {
94-
try {
95-
await editorConfig.update(
96-
FORMAT_ON_TYPE_CONFIG_SETTING,
97-
value,
98-
ConfigurationTarget.Global,
99-
/* overrideInLanguage */ true,
100-
);
101-
} catch (ex) {
102-
traceWarn(`Failed to set formatOnType to ${value}`);
103-
}
104-
}
10527
}

src/client/languageServer/pylanceLSExtensionManager.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ export class PylanceLSExtensionManager implements IDisposable, ILanguageServerEx
4949
private readonly extensions: IExtensions,
5050
readonly applicationShell: IApplicationShell,
5151
) {
52-
this.analysisOptions = new NodeLanguageServerAnalysisOptions(
53-
outputChannel,
54-
workspaceService,
55-
experimentService,
56-
);
52+
this.analysisOptions = new NodeLanguageServerAnalysisOptions(outputChannel, workspaceService);
5753
this.clientFactory = new NodeLanguageClientFactory(fileSystem, extensions);
5854
this.serverProxy = new NodeLanguageServerProxy(
5955
this.clientFactory,

src/test/activation/node/analysisOptions.unit.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// Licensed under the MIT License.
33
import { assert, expect } from 'chai';
44
import * as typemoq from 'typemoq';
5-
import { WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
5+
import { WorkspaceFolder } from 'vscode';
66
import { DocumentFilter } from 'vscode-languageclient/node';
77

88
import { NodeLanguageServerAnalysisOptions } from '../../../client/activation/node/analysisOptions';
99
import { ILanguageServerOutputChannel } from '../../../client/activation/types';
1010
import { IWorkspaceService } from '../../../client/common/application/types';
1111
import { PYTHON, PYTHON_LANGUAGE } from '../../../client/common/constants';
12-
import { IExperimentService, ILogOutputChannel } from '../../../client/common/types';
12+
import { ILogOutputChannel } from '../../../client/common/types';
1313

1414
suite('Pylance Language Server - Analysis Options', () => {
1515
class TestClass extends NodeLanguageServerAnalysisOptions {
@@ -31,19 +31,14 @@ suite('Pylance Language Server - Analysis Options', () => {
3131
let outputChannel: ILogOutputChannel;
3232
let lsOutputChannel: typemoq.IMock<ILanguageServerOutputChannel>;
3333
let workspace: typemoq.IMock<IWorkspaceService>;
34-
let experimentService: IExperimentService;
3534

3635
setup(() => {
3736
outputChannel = typemoq.Mock.ofType<ILogOutputChannel>().object;
3837
workspace = typemoq.Mock.ofType<IWorkspaceService>();
3938
workspace.setup((w) => w.isVirtualWorkspace).returns(() => false);
40-
const workspaceConfig = typemoq.Mock.ofType<WorkspaceConfiguration>();
41-
workspace.setup((w) => w.getConfiguration('editor', undefined, true)).returns(() => workspaceConfig.object);
42-
workspaceConfig.setup((w) => w.get('formatOnType')).returns(() => true);
4339
lsOutputChannel = typemoq.Mock.ofType<ILanguageServerOutputChannel>();
4440
lsOutputChannel.setup((l) => l.channel).returns(() => outputChannel);
45-
experimentService = typemoq.Mock.ofType<IExperimentService>().object;
46-
analysisOptions = new TestClass(lsOutputChannel.object, workspace.object, experimentService);
41+
analysisOptions = new TestClass(lsOutputChannel.object, workspace.object);
4742
});
4843

4944
test('Workspace folder is undefined', () => {

0 commit comments

Comments
 (0)