Added new language server setting pyright.disableTaggedHints to disable the use of diagnostics hints with tags. Some language server clients do not display these tagged hints in the intended manner and instead treat them as regular diagnostics.

This commit is contained in:
Eric Traut 2024-01-14 21:11:13 -08:00
parent 4f9ecaa96a
commit cdcd4046b5
12 changed files with 39 additions and 5 deletions

View File

@ -6,6 +6,8 @@ The Pyright language server honors the following settings.
**pyright.disableOrganizeImports** [boolean]: Disables the “Organize Imports” command. This is useful if you are using another extension that provides similar functionality and you dont want the two extensions to fight each other.
**pyright.disableTaggedHints** [boolean]: Disables the use of hint diagnostics with special tags to tell the client to display text ranges in a "grayed out" manner (to indicate unreachable code or unreferenced symbols) or in a "strike through" manner (to indicate use of a deprecated feature).
**pyright.openFilesOnly** [boolean]: Determines whether pyright analyzes (and reports errors for) all files in the workspace, as indicated by the config file. If this option is set to true, pyright analyzes only open files. This setting is deprecated in favor of python.analysis.diagnosticMode. It will be removed at a future time.
**pyright.useLibraryCodeForTypes** [boolean]: This setting is deprecated in favor of python.analysis.useLibraryCodeForTypes. It will be removed at a future time.

View File

@ -16,7 +16,7 @@ import { ConfigOptions, ExecutionEnvironment, matchFileSpecs } from '../common/c
import { ConsoleInterface, StandardConsole } from '../common/console';
import * as debug from '../common/debug';
import { assert } from '../common/debug';
import { Diagnostic } from '../common/diagnostic';
import { Diagnostic, DiagnosticCategory } from '../common/diagnostic';
import { FileDiagnostics } from '../common/diagnosticSink';
import { FileEditAction } from '../common/editAction';
import { EditableProgram, ProgramView } from '../common/extensibility';
@ -889,11 +889,18 @@ export class Program {
this._sourceFileList.forEach((sourceFileInfo) => {
if (this._shouldCheckFile(sourceFileInfo)) {
const diagnostics = sourceFileInfo.sourceFile.getDiagnostics(
options,
sourceFileInfo.diagnosticsVersion
);
let diagnostics = sourceFileInfo.sourceFile.getDiagnostics(options, sourceFileInfo.diagnosticsVersion);
if (diagnostics !== undefined) {
// Filter out all categories that are translated to tagged hints?
if (options.disableTaggedHints) {
diagnostics = diagnostics.filter(
(diag) =>
diag.category !== DiagnosticCategory.UnreachableCode &&
diag.category !== DiagnosticCategory.UnusedCode &&
diag.category !== DiagnosticCategory.Deprecated
);
}
fileDiagnostics.push({
fileUri: sourceFileInfo.sourceFile.getUri(),
version: sourceFileInfo.sourceFile.getClientVersion(),

View File

@ -641,6 +641,8 @@ export class AnalyzerService {
this._configFileUri = configFilePath || pyprojectFilePath;
configOptions.disableTaggedHints = !!commandLineOptions.disableTaggedHints;
// If we found a config file, parse it to compute the effective options.
let configJsonObj: object | undefined;
if (configFilePath) {

View File

@ -147,6 +147,9 @@ export class CommandLineOptions {
// Analyze functions and methods that have no type annotations?
analyzeUnannotatedFunctions?: boolean;
// Disable reporting of hint diagnostics with tags?
disableTaggedHints?: boolean;
constructor(executionRoot: string, fromVsCodeExtension: boolean) {
this.executionRoot = executionRoot;
this.fromVsCodeExtension = fromVsCodeExtension;

View File

@ -857,6 +857,9 @@ export class ConfigOptions {
// Was this config initialized from JSON (pyrightconfig/pyproject)?
initializedFromJson = false;
// Filter out any hint diagnostics with tags?
disableTaggedHints = false;
//---------------------------------------------------------------
// Diagnostics Rule Set

View File

@ -138,6 +138,7 @@ export interface ServerSettings {
typeCheckingMode?: string | undefined;
useLibraryCodeForTypes?: boolean | undefined;
disableLanguageServices?: boolean | undefined;
disableTaggedHints?: boolean | undefined;
disableOrganizeImports?: boolean | undefined;
autoSearchPaths?: boolean | undefined;
extraPaths?: Uri[] | undefined;
@ -509,6 +510,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis
this.updateOptionsAndRestartService(workspace, serverSettings);
workspace.disableLanguageServices = !!serverSettings.disableLanguageServices;
workspace.disableTaggedHints = !!serverSettings.disableTaggedHints;
workspace.disableOrganizeImports = !!serverSettings.disableOrganizeImports;
// Don't use workspace.isInitialized directly since it might have been

View File

@ -67,6 +67,7 @@ export class AnalyzerServiceExecutor {
options.fileSystem
),
disableLanguageServices: true,
disableTaggedHints: true,
disableOrganizeImports: true,
disableWorkspaceSymbol: true,
isInitialized: createInitStatus(),
@ -103,6 +104,7 @@ function getEffectiveCommandLineOptions(
commandLineOptions.typeEvaluationTimeThreshold = serverSettings.typeEvaluationTimeThreshold ?? 50;
commandLineOptions.enableAmbientAnalysis = trackFiles;
commandLineOptions.pythonEnvironmentName = pythonEnvironmentName;
commandLineOptions.disableTaggedHints = serverSettings.disableTaggedHints;
if (!trackFiles) {
commandLineOptions.watchForSourceChanges = false;

View File

@ -91,6 +91,7 @@ export class PyrightServer extends LanguageServerBase {
openFilesOnly: true,
useLibraryCodeForTypes: true,
disableLanguageServices: false,
disableTaggedHints: false,
disableOrganizeImports: false,
typeCheckingMode: 'standard',
diagnosticSeverityOverrides: {},
@ -205,6 +206,7 @@ export class PyrightServer extends LanguageServerBase {
}
serverSettings.disableLanguageServices = !!pyrightSection.disableLanguageServices;
serverSettings.disableTaggedHints = !!pyrightSection.disableTaggedHints;
serverSettings.disableOrganizeImports = !!pyrightSection.disableOrganizeImports;
const typeCheckingMode = pyrightSection.typeCheckingMode;

View File

@ -97,6 +97,7 @@ export class TestLanguageService implements LanguageServerInterface {
fileSystem: this.fs,
}),
disableLanguageServices: false,
disableTaggedHints: false,
disableOrganizeImports: false,
disableWorkspaceSymbol: false,
isInitialized: createInitStatus(),
@ -125,6 +126,7 @@ export class TestLanguageService implements LanguageServerInterface {
openFilesOnly: this._workspace.service.getConfigOptions().checkOnlyOpenFiles,
useLibraryCodeForTypes: this._workspace.service.getConfigOptions().useLibraryCodeForTypes,
disableLanguageServices: this._workspace.disableLanguageServices,
disableTaggedHints: this._workspace.disableTaggedHints,
autoImportCompletions: this._workspace.service.getConfigOptions().autoImportCompletions,
functionSignatureDisplay: this._workspace.service.getConfigOptions().functionSignatureDisplay,
};

View File

@ -197,6 +197,7 @@ export class TestState {
kinds: [WellKnownWorkspaceKinds.Test],
service: service,
disableLanguageServices: false,
disableTaggedHints: false,
disableOrganizeImports: false,
disableWorkspaceSymbol: false,
isInitialized: createInitStatus(),

View File

@ -79,6 +79,7 @@ export interface Workspace {
kinds: string[];
service: AnalyzerService;
disableLanguageServices: boolean;
disableTaggedHints: boolean;
disableOrganizeImports: boolean;
disableWorkspaceSymbol: boolean;
isInitialized: InitStatus;
@ -383,6 +384,7 @@ export class WorkspaceFactory {
pythonPathKind,
service: this._createService(name, rootUri, kinds),
disableLanguageServices: false,
disableTaggedHints: false,
disableOrganizeImports: false,
disableWorkspaceSymbol: false,
isInitialized: createInitStatus(),

View File

@ -1261,6 +1261,12 @@
"description": "Disables type completion, definitions, and references.",
"scope": "resource"
},
"pyright.disableTaggedHints": {
"type": "boolean",
"default": false,
"description": "Disable hint diagnostics with special hints for grayed-out or strike-through text.",
"scope": "resource"
},
"pyright.disableOrganizeImports": {
"type": "boolean",
"default": false,