Pull diagnostics fixes (#32242)

Follow-up of https://github.com/zed-industries/zed/pull/19230

* starts to send `result_id` in pull requests to allow servers to reply
with non-full results
* fixes a bug where disk-based diagnostics were offset after pulling the
diagnostics
* fixes a bug due to which pull diagnostics could not be disabled
* uses better names and comments for the workspace pull diagnostics part

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2025-06-06 16:18:05 +03:00 committed by GitHub
parent 508b604b67
commit 380d8c5662
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 272 additions and 109 deletions

View file

@ -127,9 +127,8 @@ pub struct DiagnosticsSettings {
/// Whether or not to include warning diagnostics.
pub include_warnings: bool,
/// Minimum time to wait before pulling diagnostics from the language server(s).
/// 0 turns the debounce off, None disables the feature.
pub lsp_pull_diagnostics_debounce_ms: Option<u64>,
/// Settings for using LSP pull diagnostics mechanism in Zed.
pub lsp_pull_diagnostics: LspPullDiagnosticsSettings,
/// Settings for showing inline diagnostics.
pub inline: InlineDiagnosticsSettings,
@ -146,6 +145,26 @@ impl DiagnosticsSettings {
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct LspPullDiagnosticsSettings {
/// Whether to pull for diagnostics or not.
///
/// Default: true
#[serde(default = "default_true")]
pub enabled: bool,
/// Minimum time to wait before pulling diagnostics from the language server(s).
/// 0 turns the debounce off.
///
/// Default: 50
#[serde(default = "default_lsp_diagnostics_pull_debounce_ms")]
pub debounce_ms: u64,
}
fn default_lsp_diagnostics_pull_debounce_ms() -> u64 {
50
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct InlineDiagnosticsSettings {
@ -157,11 +176,13 @@ pub struct InlineDiagnosticsSettings {
/// last editor event.
///
/// Default: 150
#[serde(default = "default_inline_diagnostics_update_debounce_ms")]
pub update_debounce_ms: u64,
/// The amount of padding between the end of the source line and the start
/// of the inline diagnostic in units of columns.
///
/// Default: 4
#[serde(default = "default_inline_diagnostics_padding")]
pub padding: u32,
/// The minimum column to display inline diagnostics. This setting can be
/// used to horizontally align inline diagnostics at some position. Lines
@ -173,6 +194,47 @@ pub struct InlineDiagnosticsSettings {
pub max_severity: Option<DiagnosticSeverity>,
}
fn default_inline_diagnostics_update_debounce_ms() -> u64 {
150
}
fn default_inline_diagnostics_padding() -> u32 {
4
}
impl Default for DiagnosticsSettings {
fn default() -> Self {
Self {
button: true,
include_warnings: true,
lsp_pull_diagnostics: LspPullDiagnosticsSettings::default(),
inline: InlineDiagnosticsSettings::default(),
cargo: None,
}
}
}
impl Default for LspPullDiagnosticsSettings {
fn default() -> Self {
Self {
enabled: true,
debounce_ms: default_lsp_diagnostics_pull_debounce_ms(),
}
}
}
impl Default for InlineDiagnosticsSettings {
fn default() -> Self {
Self {
enabled: false,
update_debounce_ms: default_inline_diagnostics_update_debounce_ms(),
padding: default_inline_diagnostics_padding(),
min_column: 0,
max_severity: None,
}
}
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct CargoDiagnosticsSettings {
/// When enabled, Zed disables rust-analyzer's check on save and starts to query
@ -208,30 +270,6 @@ impl DiagnosticSeverity {
}
}
impl Default for DiagnosticsSettings {
fn default() -> Self {
Self {
button: true,
include_warnings: true,
lsp_pull_diagnostics_debounce_ms: Some(30),
inline: InlineDiagnosticsSettings::default(),
cargo: None,
}
}
}
impl Default for InlineDiagnosticsSettings {
fn default() -> Self {
Self {
enabled: false,
update_debounce_ms: 150,
padding: 4,
min_column: 0,
max_severity: None,
}
}
}
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct GitSettings {
/// Whether or not to show the git gutter.