Fix #24081 - lsp diagnostic code type conversion (#24347)

- **store `buffer::Diagnostic`as NumberOrString instead of assuming
String**
- **update zed-industries/lsp-types rev**

Closes #24081

Release Notes:

- Fixed an issue where language server diagnostic codes would be converted to strings leading to errors with some language servers
This commit is contained in:
Ben Kunkle 2025-02-05 21:23:46 -06:00 committed by GitHub
parent 10b6bc2508
commit 8b3d315e40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 12 additions and 22 deletions

View file

@ -28,7 +28,7 @@ use gpui::{
AnyElement, App, AppContext as _, Context, Entity, EventEmitter, HighlightStyle, Pixels,
SharedString, StyledText, Task, TaskLabel, TextStyle, Window,
};
use lsp::LanguageServerId;
use lsp::{LanguageServerId, NumberOrString};
use parking_lot::Mutex;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@ -202,7 +202,7 @@ pub struct Diagnostic {
/// The name of the service that produced this diagnostic.
pub source: Option<String>,
/// A machine-readable code that identifies this diagnostic.
pub code: Option<String>,
pub code: Option<NumberOrString>,
/// Whether this diagnostic is a hint, warning, or error.
pub severity: DiagnosticSeverity,
/// The human-readable message associated with this diagnostic.

View file

@ -56,17 +56,11 @@ impl DiagnosticEntry<PointUtf16> {
/// Returns a raw LSP diagnostic used to provide diagnostic context to LSP
/// codeAction request
pub fn to_lsp_diagnostic_stub(&self) -> Result<lsp::Diagnostic> {
let code = self
.diagnostic
.code
.clone()
.map(lsp::NumberOrString::String);
let range = range_to_lsp(self.range.clone())?;
Ok(lsp::Diagnostic {
code,
range,
code: self.diagnostic.code.clone(),
severity: Some(self.diagnostic.severity),
source: self.diagnostic.source.clone(),
message: self.diagnostic.message.clone(),

View file

@ -213,7 +213,7 @@ pub fn serialize_diagnostics<'a>(
group_id: entry.diagnostic.group_id as u64,
is_primary: entry.diagnostic.is_primary,
is_valid: true,
code: entry.diagnostic.code.clone(),
code: entry.diagnostic.code.as_ref().map(|s| s.to_string()),
is_disk_based: entry.diagnostic.is_disk_based,
is_unnecessary: entry.diagnostic.is_unnecessary,
data: entry.diagnostic.data.as_ref().map(|data| data.to_string()),
@ -419,7 +419,7 @@ pub fn deserialize_diagnostics(
},
message: diagnostic.message,
group_id: diagnostic.group_id as usize,
code: diagnostic.code,
code: diagnostic.code.map(lsp::NumberOrString::from_string),
is_primary: diagnostic.is_primary,
is_disk_based: diagnostic.is_disk_based,
is_unnecessary: diagnostic.is_unnecessary,