Skip to content

Commit

Permalink
squash&merge: Inline diagnostics: helix-editor#6417
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Apr 15, 2023
1 parent 4cdba7c commit 4954e85
Show file tree
Hide file tree
Showing 22 changed files with 1,453 additions and 435 deletions.
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ The following statusline elements can be configured:
| `display-inlay-hints` | Display inlay hints[^2] | `false` |
| `display-signature-help-docs` | Display docs under signature help popup | `true` |
| `snippets` | Enables snippet completions. Requires a server restart (`:lsp-restart`) to take effect after `:config-reload`/`:set`. | `true` |
| `display-inline-diagnostics` | Display diagnostics under their starting line | `true` |

[^1]: By default, a progress spinner is shown in the statusline beside the file path.
[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix.
Expand Down
1 change: 1 addition & 0 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ These scopes are used for theming the editor interface:
| `ui.text.inactive` | Same as `ui.text` but when the text is inactive (e.g. suggestions) |
| `ui.text.info` | The key: command text in `ui.popup.info` boxes |
| `ui.virtual.ruler` | Ruler columns (see the [`editor.rulers` config][editor-section]) |
| `ui.virtual.diagnostics` | Default style for inline diagnostics lines (notably control the background) |
| `ui.virtual.whitespace` | Visible whitespace characters |
| `ui.virtual.indent-guide` | Vertical indent width guides |
| `ui.virtual.inlay-hint` | Default style for inlay hints of all kinds |
Expand Down
50 changes: 48 additions & 2 deletions helix-core/src/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
//! LSP diagnostic utility types.
use serde::{Deserialize, Serialize};
use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

/// Describes the severity level of a [`Diagnostic`].
#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord)]
pub enum Severity {
Hint,
Info,
Warning,
Error,
}

impl Serialize for Severity {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(match *self {
Severity::Hint => "hint",
Severity::Info => "info",
Severity::Warning => "warning",
Severity::Error => "error",
})
}
}

impl<'de> Deserialize<'de> for Severity {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let res = match String::deserialize(deserializer)?.as_str() {
"hint" => Severity::Hint,
"info" => Severity::Info,
"warning" => Severity::Warning,
"error" => Severity::Error,
_ => {
return Err(D::Error::custom(
"expected \"hint\", \"info\", \"warning\" or \"error\"",
))
}
};
Ok(res)
}
}
impl Default for Severity {
fn default() -> Self {
Self::Hint
Expand All @@ -23,6 +57,12 @@ pub struct Range {
pub end: usize,
}

impl Range {
pub fn contains(self, pos: usize) -> bool {
(self.start..self.end).contains(&pos)
}
}

#[derive(Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)]
pub enum NumberOrString {
Number(i32),
Expand All @@ -47,3 +87,9 @@ pub struct Diagnostic {
pub source: Option<String>,
pub data: Option<serde_json::Value>,
}

impl Diagnostic {
pub fn severity(&self) -> Severity {
self.severity.unwrap_or(Severity::Warning)
}
}
Loading

0 comments on commit 4954e85

Please sign in to comment.