Skip to content

Commit 0437e42

Browse files
authored
Fix issue with extension prompt being shown to users after install (#20187)
Fixes #20157 Cherry picking from main
1 parent 5b2cd46 commit 0437e42

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

src/client/linters/linterManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { Bandit } from './bandit';
1313
import { Flake8 } from './flake8';
1414
import { LinterInfo } from './linterInfo';
1515
import { MyPy } from './mypy';
16-
import { Flake8ExtensionPrompt } from './prompts/flake8Prompt';
17-
import { PylintExtensionPrompt } from './prompts/pylintPrompt';
16+
import { getOrCreateFlake8Prompt } from './prompts/flake8Prompt';
17+
import { getOrCreatePylintPrompt } from './prompts/pylintPrompt';
1818
import { Prospector } from './prospector';
1919
import { Pycodestyle } from './pycodestyle';
2020
import { PyDocStyle } from './pydocstyle';
@@ -112,9 +112,9 @@ export class LinterManager implements ILinterManager {
112112
case Product.bandit:
113113
return new Bandit(serviceContainer);
114114
case Product.flake8:
115-
return new Flake8(serviceContainer, new Flake8ExtensionPrompt(serviceContainer));
115+
return new Flake8(serviceContainer, getOrCreateFlake8Prompt(serviceContainer));
116116
case Product.pylint:
117-
return new Pylint(serviceContainer, new PylintExtensionPrompt(serviceContainer));
117+
return new Pylint(serviceContainer, getOrCreatePylintPrompt(serviceContainer));
118118
case Product.mypy:
119119
return new MyPy(serviceContainer);
120120
case Product.prospector:

src/client/linters/prompts/common.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
import * as fs from 'fs-extra';
5+
import * as path from 'path';
46
import { ShowToolsExtensionPrompt } from '../../common/experiments/groups';
57
import { IExperimentService, IExtensions, IPersistentState, IPersistentStateFactory } from '../../common/types';
68
import { IServiceContainer } from '../../ioc/types';
9+
import { traceLog } from '../../logging';
10+
11+
function isExtensionInstalledButDisabled(extensions: IExtensions, extensionId: string): boolean {
12+
// When debugging the python extension this `extensionPath` below will point to your repo.
13+
// If you are debugging this feature then set the `extensionPath` to right location after
14+
// the next line.
15+
const pythonExt = extensions.getExtension('ms-python.python');
16+
if (pythonExt) {
17+
let found = false;
18+
traceLog(`Extension search path: ${path.dirname(pythonExt.extensionPath)}`);
19+
fs.readdirSync(path.dirname(pythonExt.extensionPath), { withFileTypes: false }).forEach((s) => {
20+
if (s.toString().startsWith(extensionId)) {
21+
found = true;
22+
}
23+
});
24+
return found;
25+
}
26+
return false;
27+
}
728

829
export function isExtensionInstalled(serviceContainer: IServiceContainer, extensionId: string): boolean {
930
const extensions: IExtensions = serviceContainer.get<IExtensions>(IExtensions);
1031
const extension = extensions.getExtension(extensionId);
32+
if (!extension) {
33+
// The extension you are looking for might be disabled.
34+
return isExtensionInstalledButDisabled(extensions, extensionId);
35+
}
1136
return extension !== undefined;
1237
}
1338

src/client/linters/prompts/flake8Prompt.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,11 @@ export class Flake8ExtensionPrompt implements IToolsExtensionPrompt {
6161
return false;
6262
}
6363
}
64+
65+
let _prompt: IToolsExtensionPrompt | undefined;
66+
export function getOrCreateFlake8Prompt(serviceContainer: IServiceContainer): IToolsExtensionPrompt {
67+
if (!_prompt) {
68+
_prompt = new Flake8ExtensionPrompt(serviceContainer);
69+
}
70+
return _prompt;
71+
}

src/client/linters/prompts/pylintPrompt.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@ export class PylintExtensionPrompt implements IToolsExtensionPrompt {
7474
return false;
7575
}
7676
}
77+
78+
let _prompt: IToolsExtensionPrompt | undefined;
79+
export function getOrCreatePylintPrompt(serviceContainer: IServiceContainer): IToolsExtensionPrompt {
80+
if (!_prompt) {
81+
_prompt = new PylintExtensionPrompt(serviceContainer);
82+
}
83+
return _prompt;
84+
}

0 commit comments

Comments
 (0)