Skip to content

Commit

Permalink
feat: support no root_dir (limited functionality in neovim)
Browse files Browse the repository at this point in the history
resolves #44
  • Loading branch information
Feel-ix-343 committed Apr 23, 2024
1 parent fea143c commit 1c0b1f0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashSet;
use std::ops::{Deref, DerefMut};
use std::path::{Path, PathBuf};

Check warning on line 3 in src/main.rs

View workflow job for this annotation

GitHub Actions / Build and Upload (linux, ubuntu-latest, aarch64-unknown-linux-gnu, true)

unused import: `Path`

Check warning on line 3 in src/main.rs

View workflow job for this annotation

GitHub Actions / Build and Upload (linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused import: `Path`

Check warning on line 3 in src/main.rs

View workflow job for this annotation

GitHub Actions / Build and Upload (macos, macos-latest, x86_64-apple-darwin, true)

unused import: `Path`

Check warning on line 3 in src/main.rs

View workflow job for this annotation

GitHub Actions / Build and Upload (macos, macos-latest, aarch64-apple-darwin, true)

unused import: `Path`

Check warning on line 3 in src/main.rs

View workflow job for this annotation

GitHub Actions / Build and Upload (windows-gnu, windows-latest, x86_64-pc-windows-gnu, false)

unused import: `Path`
use std::str::FromStr;
use std::sync::Arc;

use completion::get_completions;
Expand Down Expand Up @@ -290,11 +291,12 @@ impl Backend {
#[tower_lsp::async_trait]
impl LanguageServer for Backend {
async fn initialize(&self, i: InitializeParams) -> Result<InitializeResult> {
let Some(root_uri) = i.root_uri else {
return Err(Error::new(ErrorCode::InvalidParams));
let root_dir = match i.root_uri {
Some(uri) => PathBuf::from_str(uri.path()).or(Err(Error::new(ErrorCode::InvalidParams)))?,
None => std::env::current_dir().or(Err(Error::new(ErrorCode::InvalidParams)))?,
};
let root_dir = Path::new(root_uri.path());
let read_settings = match Settings::new(root_dir, &i.capabilities) {

let read_settings = match Settings::new(&root_dir, &i.capabilities) {
Ok(settings) => settings,
Err(e) => {
self.client
Expand All @@ -307,7 +309,7 @@ impl LanguageServer for Backend {
}
};

let Ok(vault) = Vault::construct_vault(&read_settings, root_dir) else {
let Ok(vault) = Vault::construct_vault(&read_settings, &root_dir) else {
return Err(Error::new(ErrorCode::ServerError(0)));
};
let mut value = self.vault.write().await;
Expand Down

0 comments on commit 1c0b1f0

Please sign in to comment.