forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
isort
extension dependency (#20577)
Closes #20586
- Loading branch information
1 parent
fe4c5f1
commit cd6ca9d
Showing
21 changed files
with
274 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import * as path from 'path'; | ||
import * as fs from 'fs-extra'; | ||
import { Extension, extensions } from 'vscode'; | ||
import { PVSC_EXTENSION_ID } from '../constants'; | ||
|
||
export function getExtension<T = unknown>(extensionId: string): Extension<T> | undefined { | ||
return extensions.getExtension(extensionId); | ||
} | ||
|
||
export function isExtensionEnabled(extensionId: string): boolean { | ||
return extensions.getExtension(extensionId) !== undefined; | ||
} | ||
|
||
export function isExtensionDisabled(extensionId: string): boolean { | ||
// We need an enabled extension to find the extensions dir. | ||
const pythonExt = getExtension(PVSC_EXTENSION_ID); | ||
if (pythonExt) { | ||
let found = false; | ||
fs.readdirSync(path.dirname(pythonExt.extensionPath), { withFileTypes: false }).forEach((s) => { | ||
if (s.toString().startsWith(extensionId)) { | ||
found = true; | ||
} | ||
}); | ||
return found; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { IApplicationEnvironment } from '../../common/application/types'; | ||
import { IPersistentState, IPersistentStateFactory } from '../../common/types'; | ||
import { Common, ToolsExtensions } from '../../common/utils/localize'; | ||
import { executeCommand } from '../../common/vscodeApis/commandApis'; | ||
import { isExtensionDisabled, isExtensionEnabled } from '../../common/vscodeApis/extensionsApi'; | ||
import { showInformationMessage } from '../../common/vscodeApis/windowApis'; | ||
import { IServiceContainer } from '../../ioc/types'; | ||
import { sendTelemetryEvent } from '../../telemetry'; | ||
import { EventName } from '../../telemetry/constants'; | ||
|
||
export const ISORT_EXTENSION = 'ms-python.isort'; | ||
const ISORT_PROMPT_DONOTSHOW_KEY = 'showISortExtensionPrompt'; | ||
|
||
function doNotShowPromptState(serviceContainer: IServiceContainer, promptKey: string): IPersistentState<boolean> { | ||
const persistFactory: IPersistentStateFactory = serviceContainer.get<IPersistentStateFactory>( | ||
IPersistentStateFactory, | ||
); | ||
return persistFactory.createWorkspacePersistentState<boolean>(promptKey, false); | ||
} | ||
|
||
export class ISortExtensionPrompt { | ||
private shownThisSession = false; | ||
|
||
public constructor(private readonly serviceContainer: IServiceContainer) {} | ||
|
||
public async showPrompt(): Promise<boolean> { | ||
const isEnabled = isExtensionEnabled(ISORT_EXTENSION); | ||
if (isEnabled || isExtensionDisabled(ISORT_EXTENSION)) { | ||
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_ALREADY_INSTALLED, undefined, { | ||
extensionId: ISORT_EXTENSION, | ||
isEnabled, | ||
}); | ||
return true; | ||
} | ||
|
||
const doNotShow = doNotShowPromptState(this.serviceContainer, ISORT_PROMPT_DONOTSHOW_KEY); | ||
if (this.shownThisSession || doNotShow.value) { | ||
return false; | ||
} | ||
|
||
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_PROMPT_SHOWN, undefined, { extensionId: ISORT_EXTENSION }); | ||
this.shownThisSession = true; | ||
const response = await showInformationMessage( | ||
ToolsExtensions.isortPromptMessage, | ||
ToolsExtensions.installISortExtension, | ||
Common.doNotShowAgain, | ||
); | ||
|
||
if (response === Common.doNotShowAgain) { | ||
await doNotShow.updateValue(true); | ||
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_PROMPT_DISMISSED, undefined, { | ||
extensionId: ISORT_EXTENSION, | ||
dismissType: 'doNotShow', | ||
}); | ||
return false; | ||
} | ||
|
||
if (response === ToolsExtensions.installISortExtension) { | ||
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_INSTALL_SELECTED, undefined, { | ||
extensionId: ISORT_EXTENSION, | ||
}); | ||
const appEnv: IApplicationEnvironment = this.serviceContainer.get<IApplicationEnvironment>( | ||
IApplicationEnvironment, | ||
); | ||
await executeCommand('workbench.extensions.installExtension', ISORT_EXTENSION, { | ||
installPreReleaseVersion: appEnv.extensionChannel === 'insiders', | ||
}); | ||
return true; | ||
} | ||
|
||
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_PROMPT_DISMISSED, undefined, { | ||
extensionId: ISORT_EXTENSION, | ||
dismissType: 'close', | ||
}); | ||
|
||
return false; | ||
} | ||
} | ||
|
||
let _prompt: ISortExtensionPrompt | undefined; | ||
export function getOrCreateISortPrompt(serviceContainer: IServiceContainer): ISortExtensionPrompt { | ||
if (!_prompt) { | ||
_prompt = new ISortExtensionPrompt(serviceContainer); | ||
} | ||
return _prompt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.