Skip to content

Commit

Permalink
broadcast diagnostic provider capabilities only
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyphack committed Oct 9, 2023
1 parent a2ef856 commit cb47201
Showing 1 changed file with 49 additions and 13 deletions.
62 changes: 49 additions & 13 deletions lsp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use env_logger::Builder;
use log::LevelFilter;
use log::{LevelFilter, info};
use tower_lsp::jsonrpc::Result;
use tower_lsp::lsp_types::*;
use tower_lsp::{Client, LanguageServer, LspService, Server};
Expand Down Expand Up @@ -66,22 +66,11 @@ impl LanguageServer for Backend {
text_document_sync: Some(TextDocumentSyncCapability::Kind(
TextDocumentSyncKind::FULL,
)),
execute_command_provider: Some(ExecuteCommandOptions {
commands: vec!["dummy.do_something".to_string()],
work_done_progress_options: Default::default(),
}),
workspace: Some(WorkspaceServerCapabilities {
workspace_folders: Some(WorkspaceFoldersServerCapabilities {
supported: Some(true),
change_notifications: Some(OneOf::Left(true)),
}),
file_operations: None,
}),
diagnostic_provider: Some(DiagnosticServerCapabilities::Options(
DiagnosticOptions {
identifier: Some("typechecker".to_string()),
inter_file_dependencies: true,
workspace_diagnostics: true,
workspace_diagnostics: false,
work_done_progress_options: Default::default(),
},
)),
Expand Down Expand Up @@ -125,6 +114,53 @@ impl LanguageServer for Backend {
}
}

async fn did_change(&self, params: DidChangeTextDocumentParams) {
self.client
.log_message(MessageType::INFO, "file changed!")
.await;
let uri = params.text_document.uri;
let path = uri.to_file_path();
if let Ok(path) = path {
let diagnostics = self.check_file(&path).await;
self.client
.publish_diagnostics(uri, diagnostics, None)
.await;
}
}

async fn diagnostic(&self, params: DocumentDiagnosticParams) -> Result<DocumentDiagnosticReportResult> {
self.client
.log_message(MessageType::INFO, "diagnostic!")
.await;
let uri = params.text_document.uri;
let path = uri.to_file_path();

info!("diagnostic: {:?}", path);
match path {
Ok(path) => {
let diagnostics = self.check_file(&path).await;
info!("diagnostics: {:?}", diagnostics);
Ok(DocumentDiagnosticReportResult::Report(
DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport{
related_documents: None,
full_document_diagnostic_report: FullDocumentDiagnosticReport{
result_id: None,
items: diagnostics,
}
})
))
}
Err(_) => {
Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Unchanged(RelatedUnchangedDocumentDiagnosticReport{
related_documents:None,
unchanged_document_diagnostic_report: UnchangedDocumentDiagnosticReport{
result_id: "typechecker".to_string(),
}
})))
}
}
}

async fn shutdown(&self) -> Result<()> {
Ok(())
}
Expand Down

0 comments on commit cb47201

Please sign in to comment.