Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/configuration/language-server-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ the following settings are exclusive to basedpyright

**basedpyright.analysis.fileEnumerationTimeout** [integer]: Timeout (in seconds) for file enumeration operations. When basedpyright scans your workspace files, it can take a long time in some workspaces. This setting controls when to show a "slow enumeration" warning. Default is 10 seconds.

**basedpyright.analysis.maxLiteralStringLength** [integer]: Maximum number of characters to show for string literals in hovers, completions, etc. Defaults to `50`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think instead of adding a config option we should add an option to the type printer to not truncate the string at all if it's for a completion


**basedpyright.analysis.autoFormatStrings** [boolean]: Whether to automatically insert an `f` in front of a string when typing a `{` inside it. Defaults to `true`. [more info](../benefits-over-pyright/pylance-features.md#automatic-conversion-to-f-string-when-typing-inside-a-string)

**basedpyright.analysis.configFilePath** [path]: Path to the directory or file containing the Pyright configuration (`pyrightconfig.json` or `pyproject.toml`). If a directory is specified, basedpyright will search for the config file in that directory. This is useful for monorepo structures where the config file is in a subdirectory rather than the workspace root. For example, if your Python code is in a `backend/` subdirectory with its own `pyproject.toml`, you can set this to `${workspaceFolder}/backend` to make basedpyright use that configuration file instead of searching from the workspace root.
Expand Down
1 change: 1 addition & 0 deletions packages/pyright-internal/src/analyzer/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@ export class Program {
minimumLoggingThreshold: this._configOptions.typeEvaluationTimeThreshold,
evaluateUnknownImportsAsAny: !!this._configOptions.evaluateUnknownImportsAsAny,
verifyTypeCacheEvaluatorFlags: !!this._configOptions.internalTestMode,
maxLiteralStringLength: this._configOptions.maxLiteralStringLength,
},
this._logTracker,
this._configOptions.logTypeEvaluationTime
Expand Down
7 changes: 7 additions & 0 deletions packages/pyright-internal/src/analyzer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,13 @@ export class AnalyzerService {
configOptions.fileEnumerationTimeoutInSec = languageServerOptions.fileEnumerationTimeoutInSec;
}

if (languageServerOptions.maxLiteralStringLength !== undefined) {
const maxLiteralStringLength = languageServerOptions.maxLiteralStringLength;
if (maxLiteralStringLength > 0) {
configOptions.maxLiteralStringLength = maxLiteralStringLength;
}
}

// Special case, the language service can also set a pythonPath. It should override any other setting.
if (languageServerOptions.pythonPath) {
this._console.info(
Expand Down
19 changes: 11 additions & 8 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ export interface EvaluatorOptions {
minimumLoggingThreshold: number;
evaluateUnknownImportsAsAny: boolean;
verifyTypeCacheEvaluatorFlags: boolean;
maxLiteralStringLength: number | undefined;
}

// Describes a "deferred class completion" that is run when a class type is
Expand Down Expand Up @@ -28861,17 +28862,16 @@ export function createTypeEvaluator(
}

function printObjectTypeForClass(type: ClassType): string {
return TypePrinter.printObjectTypeForClass(
type,
evaluatorOptions.printTypeFlags,
getEffectiveReturnType,
undefined
);
return TypePrinter.printObjectTypeForClass(type, evaluatorOptions.printTypeFlags, getEffectiveReturnType, {
maxLiteralStringLength: evaluatorOptions.maxLiteralStringLength,
});
}

function printFunctionParts(type: FunctionType, extraFlags?: TypePrinter.PrintTypeFlags): [string[], string] {
const flags = extraFlags ? evaluatorOptions.printTypeFlags | extraFlags : evaluatorOptions.printTypeFlags;
return TypePrinter.printFunctionParts(type, flags, getEffectiveReturnType);
return TypePrinter.printFunctionParts(type, flags, getEffectiveReturnType, {
maxLiteralStringLength: evaluatorOptions.maxLiteralStringLength,
});
}

// Prints two types and determines whether they need to be output in
Expand Down Expand Up @@ -28929,7 +28929,10 @@ export function createTypeEvaluator(
if (options?.useFullyQualifiedNames) {
flags |= TypePrinter.PrintTypeFlags.UseFullyQualifiedNames;
}
const result = TypePrinter.printType(type, flags, getEffectiveReturnType, options?.importTracker);
const result = TypePrinter.printType(type, flags, getEffectiveReturnType, {
importTracker: options?.importTracker,
maxLiteralStringLength: options?.maxLiteralStringLength ?? evaluatorOptions.maxLiteralStringLength,
});
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ export interface PrintTypeOptions {
printTypeVarVariance?: boolean;
omitTypeArgsIfUnknown?: boolean;
importTracker?: ImportTracker;
maxLiteralStringLength?: number;
}

export interface DeclaredSymbolTypeInfo {
Expand Down
Loading