Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions docs/benefits-over-pyright/baseline.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ this file gets automatically updated as errors are removed over time in both the

if you need to suppress a diagnostic for another reason, consider using [a `# pyright: ignore` comment](../configuration/comments.md#prefer-pyrightignore-comments) instead.

## disabling automatic updates

if you prefer to manually control when the baseline file is updated, you can set `baselineMode` to `"discard"` in your [language server settings](../configuration/language-server-settings.md). this will prevent the baseline file from being automatically updated when you save files, and you'll need to use the _"basedpyright: Write new errors to baseline"_ command to update it manually.

## how does it work?

each baselined error is stored and matched by the following details:
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration/language-server-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ the following settings are exclusive to basedpyright

**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.

**basedpyright.analysis.baselineMode** ["auto", "discard"]: Controls how the baseline file is updated when files are saved. Use `auto` to automatically remove fixed errors from the baseline (default), or `discard` to prevent automatic updates. [more info](../benefits-over-pyright/baseline.md)


### discouraged settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ServerSettings {
typeCheckingMode?: string | undefined;
useLibraryCodeForTypes?: boolean | undefined;
baselineFile?: Uri | undefined;
baselineMode?: 'auto' | 'discard' | undefined;
configFilePath?: Uri | undefined;
disableLanguageServices?: boolean | undefined;
disableTaggedHints?: boolean | undefined;
Expand Down
5 changes: 3 additions & 2 deletions packages/pyright-internal/src/languageServerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis
workspace.useTypingExtensions = serverSettings.useTypingExtensions ?? false;
workspace.fileEnumerationTimeoutInSec = serverSettings.fileEnumerationTimeoutInSec ?? 10;
workspace.autoFormatStrings = serverSettings.autoFormatStrings ?? true;
workspace.baselineMode = serverSettings.baselineMode ?? 'auto';
} finally {
// Don't use workspace.isInitialized directly since it might have been
// reset due to pending config change event.
Expand Down Expand Up @@ -1864,10 +1865,10 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis
filesRequiringBaselineUpdate.get(workspace)!.push(fileDiagnostics);
}
for (const [workspace, files] of filesRequiringBaselineUpdate.entries()) {
if (!workspace.rootUri) {
if (!workspace.rootUri || workspace.baselineMode === 'discard') {
continue;
}
const baselineDiffSummary = workspace.service.backgroundAnalysisProgram.writeBaseline('auto', false, files);
const baselineDiffSummary = workspace.service.backgroundAnalysisProgram.writeBaseline(workspace.baselineMode, false, files);
if (baselineDiffSummary) {
this.console.info(
`${baselineDiffSummary}. files: ${files.map((file) => file.fileUri.toString()).join(', ')}`
Expand Down
5 changes: 5 additions & 0 deletions packages/pyright-internal/src/realLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ export abstract class RealLanguageServer extends LanguageServerBase {
serverSettings.baselineFile = resolvePathWithEnvVariables(workspace, baselineFile, workspaces);
}

const baselineMode = pythonAnalysisSection.baselineMode;
if (baselineMode === 'auto' || baselineMode === 'discard') {
serverSettings.baselineMode = baselineMode;
}

const configFilePath = pythonAnalysisSection.configFilePath;
if (configFilePath && isString(configFilePath)) {
serverSettings.configFilePath = resolvePathWithEnvVariables(workspace, configFilePath, workspaces);
Expand Down
1 change: 1 addition & 0 deletions packages/pyright-internal/src/tests/envVarUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,6 @@ function createWorkspace(rootUri: Uri | undefined): Workspace {
useTypingExtensions: false,
fileEnumerationTimeoutInSec: 10,
autoFormatStrings: true,
baselineMode: 'auto',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class TestLanguageService implements LanguageServerInterface {
useTypingExtensions: false,
fileEnumerationTimeoutInSec: 10,
autoFormatStrings: true,
baselineMode: 'auto',
};
}
/** unlike the real one, this test implementation doesn't support notebook cells. TODO: language server tests for notebook cells */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export class TestState {
useTypingExtensions: false,
fileEnumerationTimeoutInSec: 10,
autoFormatStrings: true,
baselineMode: 'auto',
};

if (!delayFileInitialization) {
Expand Down
2 changes: 2 additions & 0 deletions packages/pyright-internal/src/workspaceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export interface Workspace extends WorkspaceFolder {
useTypingExtensions: boolean;
fileEnumerationTimeoutInSec: number;
autoFormatStrings: boolean;
baselineMode: 'auto' | 'discard';
}

export interface NormalWorkspace extends Workspace {
Expand Down Expand Up @@ -305,6 +306,7 @@ export class WorkspaceFactory implements IWorkspaceFactory {
useTypingExtensions: false,
fileEnumerationTimeoutInSec: 10,
autoFormatStrings: true,
baselineMode: 'auto',
};

// Stick in our map
Expand Down
14 changes: 14 additions & 0 deletions packages/vscode-pyright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@
"markdownDescription": "Path to the baseline file. Defaults to `./.basedpyright/baseline.json`",
"scope": "resource"
},
"basedpyright.analysis.baselineMode": {
"type": "string",
"default": "auto",
"enum": [
"auto",
"discard"
],
"enumDescriptions": [
"Automatically update the baseline file when baselined errors are fixed.",
"Never update the baseline file automatically."
],
"markdownDescription": "Controls how the baseline file is updated when files are saved. Use `auto` to automatically remove fixed errors from the baseline, or `discard` to prevent automatic updates.",
"scope": "resource"
},
"basedpyright.analysis.configFilePath": {
"type": "string",
"default": "",
Expand Down