Skip to content

Commit 1d47d9f

Browse files
committed
Move testthat out of Document
1 parent e6e01f0 commit 1d47d9f

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

crates/ark/src/lsp/diagnostics.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ impl<'a> DiagnosticContext<'a> {
135135
}
136136
}
137137

138-
pub(crate) fn generate_diagnostics(doc: Document, state: WorldState) -> Vec<Diagnostic> {
138+
pub(crate) fn generate_diagnostics(
139+
doc: Document,
140+
state: WorldState,
141+
testthat: bool,
142+
) -> Vec<Diagnostic> {
139143
let mut diagnostics = Vec::new();
140144

141145
if !state.config.diagnostics.enable {
@@ -190,7 +194,7 @@ pub(crate) fn generate_diagnostics(doc: Document, state: WorldState) -> Vec<Diag
190194
// don't special-case how workspace inclusion works for packages). We might
191195
// want to provide a mechanism for test packages to declare this sort of
192196
// test files setup.
193-
if doc.testthat {
197+
if testthat {
194198
if let Some(pkg) = state.library.get("testthat") {
195199
for export in &pkg.namespace.exports {
196200
context.workspace_symbols.insert(export.clone());
@@ -1138,10 +1142,10 @@ mod tests {
11381142

11391143
use harp::eval::RParseEvalOptions;
11401144
use once_cell::sync::Lazy;
1145+
use tower_lsp::lsp_types;
11411146
use tower_lsp::lsp_types::Position;
11421147

11431148
use crate::interface::console_inputs;
1144-
use crate::lsp::diagnostics::generate_diagnostics;
11451149
use crate::lsp::documents::Document;
11461150
use crate::lsp::inputs::library::Library;
11471151
use crate::lsp::inputs::package::Package;
@@ -1154,6 +1158,10 @@ mod tests {
11541158
// Default state that includes installed packages and default scopes.
11551159
static DEFAULT_STATE: Lazy<WorldState> = Lazy::new(|| current_state());
11561160

1161+
fn generate_diagnostics(doc: Document, state: WorldState) -> Vec<lsp_types::Diagnostic> {
1162+
super::generate_diagnostics(doc, state, false)
1163+
}
1164+
11571165
fn current_state() -> WorldState {
11581166
let inputs = console_inputs().unwrap();
11591167

crates/ark/src/lsp/documents.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ pub struct Document {
4848

4949
// Configuration of the document, such as indentation settings.
5050
pub config: DocumentConfig,
51-
52-
/// Whether the document is a testthat file. This property should not be
53-
/// here, it's just a short term stopgap.
54-
pub testthat: bool,
5551
}
5652

5753
impl std::fmt::Debug for Document {
@@ -84,7 +80,6 @@ impl Document {
8480
version,
8581
ast,
8682
config: Default::default(),
87-
testthat: false,
8883
}
8984
}
9085

crates/ark/src/lsp/main_loop.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -827,15 +827,11 @@ async fn process_diagnostics_batch(batch: Vec<RefreshDiagnosticsTask>) {
827827
// stopgap approach that has some false positives (e.g. when we
828828
// work on testthat itself the flag will always be true), but
829829
// that shouldn't have much practical impact.
830-
let mut doc = document.clone();
831-
if Path::new(uri.path())
830+
let testthat = Path::new(uri.path())
832831
.components()
833-
.any(|c| c.as_os_str() == "testthat")
834-
{
835-
doc.testthat = true;
836-
};
832+
.any(|c| c.as_os_str() == "testthat");
837833

838-
let diagnostics = generate_diagnostics(doc, state.clone());
834+
let diagnostics = generate_diagnostics(document.clone(), state.clone(), testthat);
839835
Some(RefreshDiagnosticsResult {
840836
uri,
841837
diagnostics,

0 commit comments

Comments
 (0)