forked from DonJayamanne/vscode-python-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge default-language-server into main (#16142)
* Bundle Pylance as part of an extension pack (not a hard dependency) (#16077) * extension pack * Undo package.json change * Add extension pack link at build time * Forgot to update all names * Update readme + license at build time (#16134) * Add license update * Update package.json description * Update readme * Add news file * Update header wording * let -> const * Wording * Consistenly use VS Code long form * Display an informational Pylance prompt for existing users (#16069) * Export extension version memento * Add localization strings * Add prompt check * Add to the list of things triggering on activation * Add tests * Rename file * Remove unsupported newlines * Fix localization + re-add newlines * Change to be a non-blocking diagnostic check * Change localization key * Update memento on close instead of just on ok * Fix localization * Add initialMementoValue handler * Links * Fix tests * Fix tests * Set PYLANCE_PROMPT_MEMENTO to false * Remove unused line * Set to true directly * Remove extra updateMemento calls * I can't read * Period * Run in foreground * Add handling test * Remove extension pack category (#16149) Co-authored-by: Jake Bailey <[email protected]>
- Loading branch information
1 parent
8be9f83
commit 3e79ef2
Showing
16 changed files
with
320 additions
and
9 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 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,5 @@ | ||
PLEASE NOTE: This Python extension for Visual Studio Code has a hard dependency on the Jupyter extension for Visual Studio Code which is installed automatically alongside it. The Python extension for Visual Studio Code also holds an optional dependency on the Pylance extension for Visual Studio Code, which is also installed automatically but is separately licensed. | ||
|
||
All the source code for the Python extension for Visual Studio Code is available under the MIT License (given below) as is the source code for the Jupyter extension for Visual Studio Code. But the optional Pylance extension for Visual Studio Code is only available in binary form and it is not licensed under the MIT License. The Pylance extension for Visual Studio Code is licensed under a Microsoft proprietary license, the terms of which are available here: https://marketplace.visualstudio.com/items/ms-python.vscode-pylance/license. | ||
|
||
------------------------------------------------------------------------------ |
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 @@ | ||
Bundle Pylance with the extension as an optional dependency. |
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
91 changes: 91 additions & 0 deletions
91
src/client/application/diagnostics/checks/pylanceDefault.ts
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,91 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
// eslint-disable-next-line max-classes-per-file | ||
import { inject, named } from 'inversify'; | ||
import { DiagnosticSeverity } from 'vscode'; | ||
import { IStartPage } from '../../../common/startPage/types'; | ||
import { IDisposableRegistry, IExtensionContext, Resource } from '../../../common/types'; | ||
import { Diagnostics, Common } from '../../../common/utils/localize'; | ||
import { IServiceContainer } from '../../../ioc/types'; | ||
import { BaseDiagnostic, BaseDiagnosticsService } from '../base'; | ||
import { DiagnosticCodes } from '../constants'; | ||
import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '../promptHandler'; | ||
import { DiagnosticScope, IDiagnostic, IDiagnosticHandlerService } from '../types'; | ||
|
||
export const PYLANCE_PROMPT_MEMENTO = 'pylanceDefaultPromptMemento'; | ||
|
||
export class PylanceDefaultDiagnostic extends BaseDiagnostic { | ||
constructor(message: string, resource: Resource) { | ||
super( | ||
DiagnosticCodes.PylanceDefaultDiagnostic, | ||
message, | ||
DiagnosticSeverity.Information, | ||
DiagnosticScope.Global, | ||
resource, | ||
); | ||
} | ||
} | ||
|
||
export const PylanceDefaultDiagnosticServiceId = 'PylanceDefaultDiagnosticServiceId'; | ||
|
||
export class PylanceDefaultDiagnosticService extends BaseDiagnosticsService { | ||
constructor( | ||
@inject(IServiceContainer) serviceContainer: IServiceContainer, | ||
@inject(IExtensionContext) private readonly context: IExtensionContext, | ||
@inject(IStartPage) private readonly startPage: IStartPage, | ||
@inject(IDiagnosticHandlerService) | ||
@named(DiagnosticCommandPromptHandlerServiceId) | ||
protected readonly messageService: IDiagnosticHandlerService<MessageCommandPrompt>, | ||
@inject(IDisposableRegistry) disposableRegistry: IDisposableRegistry, | ||
) { | ||
super([DiagnosticCodes.PylanceDefaultDiagnostic], serviceContainer, disposableRegistry, true); | ||
} | ||
|
||
public async diagnose(resource: Resource): Promise<IDiagnostic[]> { | ||
if (!(await this.shouldShowPrompt())) { | ||
return []; | ||
} | ||
|
||
return [new PylanceDefaultDiagnostic(Diagnostics.pylanceDefaultMessage(), resource)]; | ||
} | ||
|
||
protected async onHandle(diagnostics: IDiagnostic[]): Promise<void> { | ||
if (diagnostics.length === 0 || !this.canHandle(diagnostics[0])) { | ||
return; | ||
} | ||
|
||
const diagnostic = diagnostics[0]; | ||
if (await this.filterService.shouldIgnoreDiagnostic(diagnostic.code)) { | ||
return; | ||
} | ||
|
||
const options = [{ prompt: Common.ok() }]; | ||
|
||
await this.messageService.handle(diagnostic, { | ||
commandPrompts: options, | ||
onClose: this.updateMemento.bind(this), | ||
}); | ||
} | ||
|
||
private async updateMemento() { | ||
await this.context.globalState.update(PYLANCE_PROMPT_MEMENTO, true); | ||
} | ||
|
||
private async shouldShowPrompt(): Promise<boolean> { | ||
const savedVersion: string | undefined = this.startPage.initialMementoValue; | ||
const promptShown: boolean | undefined = this.context.globalState.get(PYLANCE_PROMPT_MEMENTO); | ||
|
||
// savedVersion being undefined means that this is the first time the user activates the extension, | ||
// and we don't want to show the prompt to first-time users. | ||
// We set PYLANCE_PROMPT_MEMENTO here to skip the prompt | ||
// in case the user reloads the extension and savedVersion becomes set | ||
if (savedVersion === undefined) { | ||
await this.updateMemento(); | ||
return false; | ||
} | ||
|
||
// promptShown being undefined means that this is the first time we check if we should show the prompt. | ||
return promptShown === undefined; | ||
} | ||
} |
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
Oops, something went wrong.