Skip to content

Commit

Permalink
pull-pylance-with-pyright-1.1.369-9665934702 (#8225)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
PylanceBot and github-actions[bot] committed Jun 25, 2024
1 parent a5cbd47 commit 1168be7
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 146 deletions.
66 changes: 33 additions & 33 deletions packages/pyright-internal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/pyright-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"leven": "3.1.0",
"source-map-support": "^0.5.21",
"tmp": "^0.2.1",
"vscode-jsonrpc": "^9.0.0-next.2",
"vscode-languageserver": "^10.0.0-next.2",
"vscode-jsonrpc": "^9.0.0-next.4",
"vscode-languageserver": "^10.0.0-next.6",
"vscode-languageserver-textdocument": "1.0.11",
"vscode-languageserver-types": "^3.17.6-next.3",
"vscode-languageserver-types": "^3.17.6-next.4",
"vscode-uri": "^3.0.8"
},
"devDependencies": {
Expand Down
42 changes: 22 additions & 20 deletions packages/pyright-internal/src/languageServerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,32 +389,34 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis
status: InitStatus | undefined,
serverSettings?: ServerSettings
): Promise<void> {
status?.markCalled();

serverSettings = serverSettings ?? (await this.getSettings(workspace));
try {
status?.markCalled();

// Set logging level first.
(this.console as ConsoleWithLogLevel).level = serverSettings.logLevel ?? LogLevel.Info;
serverSettings = serverSettings ?? (await this.getSettings(workspace));

// Apply the new path to the workspace (before restarting the service).
serverSettings.pythonPath = this.workspaceFactory.applyPythonPath(
workspace,
serverSettings.pythonPath ? serverSettings.pythonPath : undefined
);
// Set logging level first.
(this.console as ConsoleWithLogLevel).level = serverSettings.logLevel ?? LogLevel.Info;

this._dynamicFeatures.update(serverSettings);
// Apply the new path to the workspace (before restarting the service).
serverSettings.pythonPath = this.workspaceFactory.applyPythonPath(
workspace,
serverSettings.pythonPath ? serverSettings.pythonPath : undefined
);

// Then use the updated settings to restart the service.
this.updateOptionsAndRestartService(workspace, serverSettings);
this._dynamicFeatures.update(serverSettings);

workspace.disableLanguageServices = !!serverSettings.disableLanguageServices;
workspace.disableTaggedHints = !!serverSettings.disableTaggedHints;
workspace.disableOrganizeImports = !!serverSettings.disableOrganizeImports;
// Then use the updated settings to restart the service.
this.updateOptionsAndRestartService(workspace, serverSettings);

// Don't use workspace.isInitialized directly since it might have been
// reset due to pending config change event.
// The workspace is now open for business.
status?.resolve();
workspace.disableLanguageServices = !!serverSettings.disableLanguageServices;
workspace.disableTaggedHints = !!serverSettings.disableTaggedHints;
workspace.disableOrganizeImports = !!serverSettings.disableOrganizeImports;
} finally {
// Don't use workspace.isInitialized directly since it might have been
// reset due to pending config change event.
// The workspace is now open for business.
status?.resolve();
}
}

updateOptionsAndRestartService(
Expand Down
25 changes: 15 additions & 10 deletions packages/pyright-internal/src/languageService/autoImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { throwIfCancellationRequested } from '../common/cancellationUtils';
import { appendArray } from '../common/collectionUtils';
import { ExecutionEnvironment } from '../common/configOptions';
import { TextEditAction } from '../common/editAction';
import { SourceFileInfo } from '../common/extensibility';
import { ProgramView, SourceFileInfo } from '../common/extensibility';
import { stripFileExtension } from '../common/pathUtils';
import * as StringUtils from '../common/stringUtils';
import { Position } from '../common/textRange';
Expand Down Expand Up @@ -164,6 +164,7 @@ export class AutoImporter {

constructor(
protected readonly execEnvironment: ExecutionEnvironment,
protected readonly program: ProgramView,
protected readonly importResolver: ImportResolver,
protected readonly parseResults: ParseFileResults,
private readonly _invocationPosition: Position,
Expand Down Expand Up @@ -215,13 +216,13 @@ export class AutoImporter {
) {
this.moduleSymbolMap.forEach((topLevelSymbols, key) => {
// See if this file should be offered as an implicit import.
const isStubFileOrHasInit = this.isStubFileOrHasInit(this.moduleSymbolMap!, topLevelSymbols.uri);
const uriProperties = this.getUriProperties(this.moduleSymbolMap!, topLevelSymbols.uri);
this.processModuleSymbolTable(
topLevelSymbols,
topLevelSymbols.uri,
word,
similarityLimit,
isStubFileOrHasInit,
uriProperties,
abbrFromUsers,
aliasMap,
results,
Expand Down Expand Up @@ -312,7 +313,7 @@ export class AutoImporter {
moduleUri: Uri,
word: string,
similarityLimit: number,
isStubOrHasInit: { isStub: boolean; hasInit: boolean },
fileProperties: { isStub: boolean; hasInit: boolean; isUserCode: boolean },
abbrFromUsers: string | undefined,
importAliasMap: Map<string, Map<string, ImportAliasData>>,
results: AutoImportResultMap,
Expand All @@ -326,8 +327,10 @@ export class AutoImporter {
}

const dotCount = StringUtils.getCharacterCount(importSource, '.');
topLevelSymbols.forEach((autoImportSymbol, name, library) => {
if (!this._shouldIncludeVariable(autoImportSymbol, name, isStubOrHasInit.isStub, library)) {
topLevelSymbols.forEach((autoImportSymbol, name) => {
if (
!this._shouldIncludeVariable(autoImportSymbol, name, fileProperties.isStub, !fileProperties.isUserCode)
) {
return;
}

Expand Down Expand Up @@ -368,7 +371,7 @@ export class AutoImporter {
return;
}

const nameForImportFrom = this.getNameForImportFrom(library, moduleUri);
const nameForImportFrom = this.getNameForImportFrom(/* library */ !fileProperties.isUserCode, moduleUri);
const autoImportTextEdits = this._getTextEditsForAutoImportByFilePath(
{ name, alias: abbrFromUsers },
{ name: importSource, nameForImportFrom },
Expand All @@ -394,7 +397,8 @@ export class AutoImporter {
// If the current file is in a directory that also contains an "__init__.py[i]"
// file, we can use that directory name as an implicit import target.
// Or if the file is a stub file, we can use it as import target.
if (!isStubOrHasInit.isStub && !isStubOrHasInit.hasInit) {
// Skip this check for user code.
if (!fileProperties.isStub && !fileProperties.hasInit && !fileProperties.isUserCode) {
return;
}

Expand Down Expand Up @@ -435,13 +439,14 @@ export class AutoImporter {
return undefined;
}

protected isStubFileOrHasInit<T>(map: Map<string, T>, uri: Uri) {
protected getUriProperties<T>(map: Map<string, T>, uri: Uri) {
const fileDir = uri.getDirectory();
const initPathPy = fileDir.initPyUri;
const initPathPyi = fileDir.initPyiUri;
const isStub = uri.hasExtension('.pyi');
const hasInit = map.has(initPathPy.key) || map.has(initPathPyi.key);
return { isStub, hasInit };
const sourceFileInfo = this.program.getSourceFileInfo(uri);
return { isStub, hasInit, isUserCode: isUserCode(sourceFileInfo) };
}

private _shouldIncludeVariable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ export class CompletionProvider {

const autoImporter = new AutoImporter(
this.execEnv,
this.program,
this.importResolver,
this.parseResults,
this.position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"Diagnostic": {
"abstractMethodInvocation": "Metodu „{method}“ nelze volat, protože je abstraktní a neimplementovaná.",
"annotatedMetadataInconsistent": "Annotated metadata type \"{metadataType}\" is not compatible with type \"{type}\"",
"annotatedMetadataInconsistent": "Typ metadat s poznámkami „{metadataType}“ není kompatibilní s typem „{type}“.",
"annotatedParamCountMismatch": "Počet poznámek parametrů se neshoduje: očekával(o/y) se {expected}, ale přijal(o/y) se {received}.",
"annotatedTypeArgMissing": "Byl očekáván jeden argument typu a jedna nebo více poznámek pro Annotated",
"annotationBytesString": "Poznámky typu nemůžou používat řetězcové literály bajtů.",
Expand Down Expand Up @@ -159,7 +159,7 @@
"enumMemberSet": "Člen výčtu {name} se nedá přiřadit.",
"enumMemberTypeAnnotation": "Poznámky typu nejsou pro členy výčtu povolené",
"exceptionGroupIncompatible": "Syntaxe skupiny výjimek (except*) vyžaduje Python 3.11 nebo novější",
"exceptionGroupTypeIncorrect": "Exception type in except* cannot derive from BaseGroupException",
"exceptionGroupTypeIncorrect": "Typ výjimky v kromě* se nedá odvodit z BaseGroupException.",
"exceptionTypeIncorrect": "„{type}“ se neodvozuje od BaseException",
"exceptionTypeNotClass": "{type} není platná třída výjimky",
"exceptionTypeNotInstantiable": "Konstruktor pro výjimku typu {type} vyžaduje jeden nebo více argumentů",
Expand Down Expand Up @@ -403,6 +403,7 @@
"protocolBaseClassWithTypeArgs": "Argumenty typu nejsou u třídy Protocol povoleny při použití syntaxe parametru typu",
"protocolIllegal": "Použití protokolu vyžaduje Python 3.7 nebo novější",
"protocolNotAllowed": "„Protocol“ nejde v tomto kontextu použít.",
"protocolTypeArgMustBeTypeParam": "Type argument for \"Protocol\" must be a type parameter",
"protocolUnsafeOverlap": "Třída se nebezpečně překrývá s názvem „{name}“ a může vytvořit shodu při spuštění.",
"protocolVarianceContravariant": "Proměnná typu „{variable}“ použitá v obecném protokolu „{class}“ by měla být kontravariantní",
"protocolVarianceCovariant": "Proměnná typu „{variable}“ použitá v obecném protokolu „{class}“ by měla být kovariantní",
Expand Down
Loading

0 comments on commit 1168be7

Please sign in to comment.