Add initial inline diagnostics support (#25297)

https://github.com/user-attachments/assets/eb881707-e575-47ef-9ae0-67d8085d8065

Closes https://github.com/zed-industries/zed/pull/22668
Closes https://github.com/zed-industries/zed/issues/4901

Takes https://github.com/zed-industries/zed/pull/22668 and fixes all
review items on top.
Inline diagnostics are disabled by default, but can be enabled via
settings permanently, or temporarily toggled with the `editor:
ToggleInlineDiagnostics` action and the corresponding editor menu item
<img width="242" alt="image"
src="https://github.com/user-attachments/assets/8e177511-4626-4434-902b-d6aa4d3fafd0"
/>

Inline diagnostics does not show currently active diagnostics group, as
it gets inline into the editor too, inside the text.
Inline git blame takes precedence and is shown instead of the
diagnostics, edit predictions dim the diagnostics if located on the same
line.

One notable drawback of the implementation is the inability to wrap,
making inline diagnostics cut off the right side:


![image](https://github.com/user-attachments/assets/6e87268a-b51a-4a2b-8b8d-01d932c62fea)

(same as inline git blame and other elements to the right of the text)
Given that it's disabled by default and go to next/prev diagnostics will
show them better, seems fine to leave in the first iteration.


Release Notes:

- Added initial inline diagnostics support

---------

Co-authored-by: Paul J. Davis <paul.davis@tiledb.com>
Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
This commit is contained in:
Kirill Bulatov 2025-02-21 01:39:47 +02:00 committed by GitHub
parent 74c581b9f4
commit 5ae93ce68d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 579 additions and 81 deletions

View file

@ -40,6 +40,10 @@ pub struct ProjectSettings {
#[serde(default)]
pub lsp: HashMap<LanguageServerName, LspSettings>,
/// Configuration for Diagnostics-related features.
#[serde(default)]
pub diagnostics: DiagnosticsSettings,
/// Configuration for Git-related features
#[serde(default)]
pub git: GitSettings,
@ -78,6 +82,77 @@ pub enum DirenvSettings {
Direct,
}
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct DiagnosticsSettings {
/// Whether or not to include warning diagnostics
#[serde(default = "true_value")]
pub include_warnings: bool,
/// Settings for showing inline diagnostics
#[serde(default)]
pub inline: InlineDiagnosticsSettings,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
pub struct InlineDiagnosticsSettings {
/// Whether or not to show inline diagnostics
///
/// Default: false
#[serde(default)]
pub enabled: bool,
/// Whether to only show the inline diaganostics after a delay after the
/// last editor event.
///
/// Default: 150
#[serde(default = "default_inline_diagnostics_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
/// longer than this value will still push diagnostics further to the right.
///
/// Default: 0
#[serde(default)]
pub min_column: u32,
#[serde(default)]
pub max_severity: Option<DiagnosticSeverity>,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum DiagnosticSeverity {
Error,
Warning,
Info,
Hint,
}
impl Default for InlineDiagnosticsSettings {
fn default() -> Self {
Self {
enabled: false,
update_debounce_ms: default_inline_diagnostics_debounce_ms(),
padding: default_inline_diagnostics_padding(),
min_column: 0,
max_severity: None,
}
}
}
fn default_inline_diagnostics_debounce_ms() -> u64 {
150
}
fn default_inline_diagnostics_padding() -> u32 {
4
}
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct GitSettings {
/// Whether or not to show the git gutter.
@ -156,7 +231,7 @@ pub struct InlineBlameSettings {
/// Whether to show commit summary as part of the inline blame.
///
/// Default: false
#[serde(default = "false_value")]
#[serde(default)]
pub show_commit_summary: bool,
}
@ -164,10 +239,6 @@ const fn true_value() -> bool {
true
}
const fn false_value() -> bool {
false
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
pub struct BinarySettings {
pub path: Option<String>,