Skip to content

Commit

Permalink
Handle LSP "diagnostic" message to fix "diagnostic failed" error (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewlacy authored Sep 27, 2024
1 parent fce1529 commit d4313a9
Showing 1 changed file with 54 additions and 31 deletions.
85 changes: 54 additions & 31 deletions crates/brioche-core/src/script/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,37 +427,60 @@ impl LanguageServer for BriocheLspServer {
}]))
}

// async fn diagnostic(
// &self,
// params: DocumentDiagnosticParams,
// ) -> Result<DocumentDiagnosticReportResult> {
// self.client
// .log_message(MessageType::INFO, "diagnostic")
// .await;
// let response = self
// .js_lsp
// .send::<Vec<Diagnostic>>(JsLspMessage::Diagnostic(params.clone()))
// .await;
// let diagnostics = match response {
// Ok(diagnostics) => diagnostics,
// Err(error) => {
// tracing::error!(error = %error, "failed to get diagnostics");
// return Err(tower_lsp::jsonrpc::Error::internal_error());
// }
// };

// tracing::info!(?diagnostics, "got diagnostics");

// Ok(DocumentDiagnosticReportResult::Report(
// DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport {
// full_document_diagnostic_report: FullDocumentDiagnosticReport {
// items: diagnostics,
// ..Default::default()
// },
// ..Default::default()
// }),
// ))
// }
async fn diagnostic(
&self,
params: DocumentDiagnosticParams,
) -> Result<DocumentDiagnosticReportResult> {
self.client
.log_message(MessageType::INFO, "diagnostic")
.await;

let specifier = lsp_uri_to_module_specifier(&params.text_document.uri);
match specifier {
Ok(specifier) => {
let result = self
.compiler_host
.load_documents(vec![specifier.clone()])
.await;
match result {
Ok(()) => {}
Err(error) => {
tracing::warn!("failed to load document {specifier}: {error:#}");
}
}
}
Err(error) => {
tracing::warn!(
"failed to parse URI {}: {error:#}",
params.text_document.uri
);
}
}

let response = self
.js_lsp
.send::<Vec<Diagnostic>>(JsLspMessage::Diagnostic(params.clone()))
.await;
let diagnostics = match response {
Ok(diagnostics) => diagnostics,
Err(error) => {
tracing::error!(error = %error, "failed to get diagnostics");
return Err(tower_lsp::jsonrpc::Error::internal_error());
}
};

tracing::info!(?diagnostics, "got diagnostics");

Ok(DocumentDiagnosticReportResult::Report(
DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport {
full_document_diagnostic_report: FullDocumentDiagnosticReport {
items: diagnostics,
..Default::default()
},
..Default::default()
}),
))
}
}

async fn try_update_lockfile_for_module(
Expand Down

0 comments on commit d4313a9

Please sign in to comment.