Merge pull request #29 from kbwo/feat/config-workspace

Configuration to disable workspace diagnostics #28
This commit is contained in:
Kodai Kabasawa 2024-08-04 18:51:43 +09:00 committed by GitHub
commit 1447e9e085
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 3 deletions

View file

@ -12,6 +12,7 @@
}
]
},
"testing.enableWorkspaceDiagnostics": true,
"testing.server.path": "testing-language-server",
"testing.trace.server": "verbose"
}

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);
}
}