Skip to content

Commit

Permalink
feat: Use autogenerated options.json
Browse files Browse the repository at this point in the history
  • Loading branch information
k3yss committed Dec 19, 2024
1 parent c2f99c6 commit b347e07
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions devenv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ tracing-appender.workspace = true
dashmap.workspace = true
tree-sitter.workspace = true
tree-sitter-nix.workspace = true

[build-dependencies]
cc = "*"
22 changes: 20 additions & 2 deletions devenv/src/devenv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{cli, cnix, config, log, lsp, tasks};
use super::{cli, cnix, config, log, lsp, tasks, utils};
use clap::crate_version;
use cli_table::Table;
use cli_table::{print_stderr, WithTitle};
Expand Down Expand Up @@ -397,7 +397,25 @@ impl Devenv {
.await
}

pub async fn lsp(&mut self, completion_json: &Value) -> Result<()> {
pub async fn lsp(&mut self) -> Result<()> {
let options = self.nix.build(&["optionsJSON"]).await?;
let options_path = options[0]
.join("share")
.join("doc")
.join("nixos")
.join("options.json");
let options_contents = fs::read(options_path).expect("Failed to read options.json");
let options_json: serde_json::Value =
serde_json::from_slice(&options_contents).expect("Failed to parse options.json");
let mut flatten_json = utils::flatten(options_json);
let filter_keys = vec![
String::from("declarations"),
String::from("loc"),
String::from("readOnly"),
];
let filter_keys_refs: Vec<&str> = filter_keys.iter().map(|s| s.as_str()).collect();
let completion_json = utils::filter_json(&mut flatten_json, filter_keys_refs);

let (stdin, stdout) = (tokio::io::stdin(), tokio::io::stdout());
info!("Inside the tokio main async lsp");
let (service, socket) = LspService::new(|client| lsp::Backend {
Expand Down
15 changes: 1 addition & 14 deletions devenv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@ async fn main() -> Result<()> {
.with_writer(non_blocking)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let file = File::open("/home/k3ys/tmp/option.json").unwrap();
let json: serde_json::Value =
serde_json::from_reader(file).expect("file should be proper JSON");
// debug!("trimmed_json {:?}", trimmed_json);
let mut flatten_json = utils::flatten(json);
// debug!("flatten_json: {}", serde_json::to_string_pretty(&flatten_json).unwrap());
let filter_keys = vec![
String::from("declarations"),
String::from("loc"),
String::from("readOnly"),
];
let filter_keys_refs: Vec<&str> = filter_keys.iter().map(|s| s.as_str()).collect();
let completion_json = utils::filter_json(&mut flatten_json, filter_keys_refs);

let mut config = config::Config::load()?;
for input in cli.global_options.override_input.chunks_exact(2) {
Expand Down Expand Up @@ -161,7 +148,7 @@ async fn main() -> Result<()> {
Commands::Gc {} => devenv.gc(),
Commands::Info {} => devenv.info().await,
Commands::Repl {} => devenv.repl(),
Commands::Lsp {} => devenv.lsp(&completion_json).await,
Commands::Lsp {} => devenv.lsp().await,
Commands::Build { attributes } => devenv.build(&attributes).await,
Commands::Update { name } => devenv.update(&name).await,
Commands::Up { process, detach } => devenv.up(process.as_deref(), &detach, &detach).await,
Expand Down

0 comments on commit b347e07

Please sign in to comment.