laburnum 1.17.1

An LSP framework for building language servers and compilers, powered by an incremental query tree with content-addressed storage, task-based dataflow, and parallel queries.
Documentation
// Copyright Two Neutron Stars Incorporated and contributors
// SPDX-License-Identifier: BlueOak-1.0.0

use {
  crate::{
    Partitions,
    protocol::{
      jsonrpc,
      lsp::LanguageServer,
    },
    scheduler::task::TaskContext,
  },
  otel::event,
  serde_json::Value,
};

pub(super) async fn handle_query_source_keys<
  P: Partitions,
  T: LanguageServer<P>,
>(
  _arguments: &[Value],
  ctx: &mut TaskContext<P, T>,
) -> jsonrpc::Result<Option<Value>> {
  let source_cache = ctx.source_cache();
  let guard = source_cache.read();

  let all_keys = guard.get_all_source_keys();

  event!(
    "query_source_keys.result",
    "key_count" = all_keys.len() as i64
  );

  let mut uri_to_source_key = serde_json::Map::new();
  for (uri, source_key) in all_keys {
    uri_to_source_key
      .insert(uri.to_string(), serde_json::json!(source_key.to_string()));
  }

  Ok(Some(serde_json::Value::Object(uri_to_source_key)))
}