Skip to content

Commit 8c8cb01

Browse files
committed
Adds testing for semantic lookups
Largely written in iterations by copilot Signed-off-by: Jonatan Waern<jonatan.waern@intel.com>
1 parent bad38b1 commit 8c8cb01

10 files changed

Lines changed: 1919 additions & 1 deletion

File tree

src/actions/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,44 @@ impl <O: Output> InitActionContext<O> {
400400
}
401401
}
402402

403+
/// Create an InitActionContext for testing purposes
404+
///
405+
/// This constructor is only available in test builds and provides a minimal
406+
/// but functional InitActionContext for testing LSP operations.
407+
#[cfg(test)]
408+
pub fn new_for_testing(
409+
analysis: Arc<Mutex<AnalysisStorage>>,
410+
vfs: Arc<Vfs>,
411+
) -> InitActionContext<O> {
412+
let shut_down = Arc::new(AtomicBool::new(false));
413+
let config = Arc::new(Mutex::new(Config::default()));
414+
415+
InitActionContext {
416+
analysis,
417+
vfs,
418+
analysis_queue: Arc::new(AnalysisQueue::init(Arc::clone(&shut_down))),
419+
current_notifier: Arc::new(Mutex::new(None)),
420+
quiescent: Arc::new(AtomicBool::new(false)),
421+
workspace_roots: Arc::new(Mutex::new(Vec::new())),
422+
cached_path_resolver: Arc::new(Mutex::new(None)),
423+
direct_opens: Arc::new(Mutex::new(HashSet::new())),
424+
compilation_info: Arc::new(Mutex::new(HashMap::new())),
425+
device_active_contexts: Arc::new(Mutex::new(HashSet::new())),
426+
previously_checked_contexts: Arc::new(Mutex::new(HashSet::new())),
427+
prev_changes: Arc::new(Mutex::new(HashMap::new())),
428+
active_waits: Arc::new(Mutex::new(Vec::new())),
429+
outstanding_requests: Arc::new(Mutex::new(HashMap::new())),
430+
config,
431+
lint_config: Arc::new(Mutex::new(LintCfg::default())),
432+
sent_warnings: Arc::new(Mutex::new(HashSet::new())),
433+
jobs: Arc::new(Mutex::new(Jobs::default())),
434+
client_capabilities: Arc::new(ClientCapabilities::default()),
435+
has_notified_missing_builtins: false,
436+
shut_down,
437+
pid: std::process::id(),
438+
}
439+
}
440+
403441
fn add_direct_open(&self, path: PathBuf) {
404442
// NOTE: from_path_buf already logs the error, no need to do it here
405443
let Some(canon_path) = CanonPath::from_path_buf(path) else { return };

src/actions/semantic_lookup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,4 @@ pub fn references_at_fp(context: &InitActionContext<impl Output>,
396396
.into_iter()
397397
.flat_map(|s|s.lock().unwrap().references.clone())
398398
.collect())
399-
}
399+
}

0 commit comments

Comments
 (0)