feat: add configuration to disable workspace diagnostics

close #28
This commit is contained in:
kbwo 2024-08-04 18:28:33 +09:00
parent 90be4e498f
commit 8939558793
2 changed files with 32 additions and 3 deletions

View file

@ -36,7 +36,7 @@ fn main_loop(server: &mut TestingLS) -> Result<(), LSError> {
'read_header: loop {
let mut buffer = String::new();
let stdin = io::stdin();
let mut handle = stdin.lock(); // We get `StdinLock` here.
let mut handle = stdin.lock();
handle.read_line(&mut buffer)?;
if buffer.is_empty() {

View file

@ -33,6 +33,15 @@ impl Default for TestingLS {
}
}
/// The status of workspace diagnostics
/// - Skipped: Skip workspace diagnostics (when `enable_workspace_diagnostics` is false)
/// - Done: Finish workspace diagnostics (when `enable_workspace_diagnostics` is true)
#[derive(Debug, PartialEq, Eq)]
pub enum WorkspaceDiagnosticsStatus {
Skipped,
Done,
}
impl TestingLS {
pub fn new() -> Self {
Self {
@ -204,8 +213,11 @@ impl TestingLS {
Ok(())
}
pub fn diagnose_workspace(&mut self) -> Result<(), LSError> {
pub fn diagnose_workspace(&mut self) -> Result<WorkspaceDiagnosticsStatus, LSError> {
self.refresh_workspaces_cache()?;
if !self.options.enable_workspace_diagnostics.unwrap_or(false) {
return Ok(WorkspaceDiagnosticsStatus::Skipped);
}
self.workspaces_cache.iter().for_each(
|WorkspaceAnalysis {
@ -217,7 +229,7 @@ impl TestingLS {
})
},
);
Ok(())
Ok(WorkspaceDiagnosticsStatus::Done)
}
pub fn refreshing_needed(&self, path: &str) -> bool {
@ -566,4 +578,21 @@ mod tests {
assert_eq!(diagnostic.severity.unwrap(), DiagnosticSeverity::WARNING);
assert!(diagnostic.message.contains("Cannot run test command:"));
}
#[test]
fn skip_workspace_diagnostics() {
let mut server = TestingLS {
workspace_folders: Some(vec![WorkspaceFolder {
uri: Url::from_file_path(current_dir().unwrap()).unwrap(),
name: "demo".to_string(),
}]),
options: InitializedOptions {
adapter_command: HashMap::new(),
enable_workspace_diagnostics: Some(false),
},
workspaces_cache: Vec::new(),
};
let status = server.diagnose_workspace().unwrap();
assert_eq!(status, WorkspaceDiagnosticsStatus::Skipped);
}
}