Skip to content

Commit

Permalink
Break out extension, log cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
blopker committed Jan 21, 2025
1 parent 9299069 commit 32b7432
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 453 deletions.
197 changes: 1 addition & 196 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["codebook", "codebook-config", "codebook-lsp", "codebook-zed"]
members = ["codebook", "codebook-config", "codebook-lsp"]
resolver = "2"

[profile.test]
Expand Down
6 changes: 1 addition & 5 deletions codebook-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ impl CodebookConfig {
}

pub fn new_no_file() -> Self {
Self {
settings: Arc::new(RwLock::new(ConfigSettings::default())),
config_path: None,
cache_dir: env::temp_dir().join(CACHE_DIR),
}
Self::default()
}

pub fn reload(&self) -> Result<()> {
Expand Down
12 changes: 5 additions & 7 deletions codebook-lsp/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tower_lsp::{Client, LanguageServer};

use codebook::Codebook;
use codebook_config::CodebookConfig;
use log::info;
use log::{debug, info};

use crate::file_cache::{TextDocumentCache, TextDocumentCacheItem};

Expand Down Expand Up @@ -153,10 +153,8 @@ impl LanguageServer for Backend {
}

impl Backend {
pub fn new(client: Client, cache_dir: &PathBuf, workspace_dir: &PathBuf) -> Self {
let mut config =
CodebookConfig::load_from_dir(workspace_dir).expect("Unable to make config.");
config.cache_dir = cache_dir.clone();
pub fn new(client: Client, workspace_dir: &PathBuf) -> Self {
let config = CodebookConfig::load_from_dir(workspace_dir).expect("Unable to make config.");
let config_arc = Arc::new(config);
let codebook = Codebook::new(Arc::clone(&config_arc)).expect("Unable to make codebook");
Self {
Expand Down Expand Up @@ -259,12 +257,12 @@ impl Backend {
})
.collect();

info!("Diagnostics: {:?}", diagnostics);
debug!("Diagnostics: {:?}", diagnostics);
// 3) Send the diagnostics to the client.
self.client
.publish_diagnostics(uri, diagnostics, None)
.await;
info!("Published diagnostics for: {:?}", file_path);
debug!("Published diagnostics for: {:?}", file_path);
}

fn spell_check(
Expand Down
20 changes: 6 additions & 14 deletions codebook-lsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ use tower_lsp::{LspService, Server};
#[derive(Parser)]
#[command(version, about, long_about = None, arg_required_else_help = true)]
struct Cli {
/// Sets a custom config file
#[arg(short, long, value_name = "FOLDER")]
cache_dir: Option<PathBuf>,

/// Root of the workspace/project being checked
/// Root of the workspace/project being checked.
/// This may or may not have a codebook.toml file.
#[arg(short, long, value_name = "FOLDER")]
root: Option<PathBuf>,

Expand All @@ -34,27 +31,22 @@ async fn main() {
env_logger::init();
let cli = Cli::parse();

let cache_dir = match cli.cache_dir.as_deref() {
Some(path) => path,
None => Path::new(".cache/dictionaries/"),
};

let root = match cli.root.as_deref() {
Some(path) => path,
None => Path::new("."),
};

match &cli.command {
Some(Commands::Serve {}) => {
serve_lsp(&cache_dir.to_path_buf(), &root.to_path_buf()).await;
serve_lsp(&root.to_path_buf()).await;
}
None => {}
}
}

async fn serve_lsp(cache_dir: &PathBuf, root: &PathBuf) {
info!("Starting SpellCheck Language Server...");
async fn serve_lsp(root: &PathBuf) {
info!("Starting Codebook Language Server...");
let (stdin, stdout) = (tokio::io::stdin(), tokio::io::stdout());
let (service, socket) = LspService::new(|client| Backend::new(client, cache_dir, root));
let (service, socket) = LspService::new(|client| Backend::new(client, root));
Server::new(stdin, stdout, socket).serve(service).await;
}
14 changes: 0 additions & 14 deletions codebook-zed/Cargo.toml

This file was deleted.

Loading

0 comments on commit 32b7432

Please sign in to comment.