From e0aff37c276e41c520b20672aa8edf917522977d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:40:21 +0000 Subject: [PATCH] chore: bump lsp-types from 0.95.0 to 0.97.0 Bumps [lsp-types](https://github.com/gluon-lang/lsp-types) from 0.95.0 to 0.97.0. - [Changelog](https://github.com/gluon-lang/lsp-types/blob/master/CHANGELOG.md) - [Commits](https://github.com/gluon-lang/lsp-types/compare/v0.95.0...v0.97.0) --- updated-dependencies: - dependency-name: lsp-types dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 49 +++++++++++++---------- crates/lsp/Cargo.toml | 3 +- crates/lsp/src/forest.rs | 31 ++++++++++----- crates/lsp/src/handlers.rs | 19 +++++---- crates/lsp/src/lib.rs | 2 + crates/lsp/src/providers/completion.rs | 52 ++++++++++++++++--------- crates/lsp/src/providers/diagnostics.rs | 16 +++++--- crates/lsp/src/providers/formatting.rs | 3 +- crates/lsp/src/server.rs | 27 ++++++++----- crates/lsp/src/utils.rs | 16 ++++++++ 10 files changed, 145 insertions(+), 73 deletions(-) create mode 100644 crates/lsp/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index fc26e34d..f9c25029 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,6 +114,7 @@ dependencies = [ "tracing-subscriber", "tree-sitter", "tree-sitter-beancount", + "url", ] [[package]] @@ -291,11 +292,20 @@ dependencies = [ "log", ] +[[package]] +name = "fluent-uri" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17c704e9dbe1ddd863da1e6ff3567795087b1eb201ce80d8fa81162e1516500d" +dependencies = [ + "bitflags", +] + [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -360,9 +370,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -450,15 +460,15 @@ dependencies = [ [[package]] name = "lsp-types" -version = "0.95.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "158c1911354ef73e8fe42da6b10c0484cb65c7f1007f28022e847706c1ab6984" +checksum = "53353550a17c04ac46c585feb189c2db82154fc84b79c7a66c96c2c644f66071" dependencies = [ "bitflags", + "fluent-uri", "serde", "serde_json", "serde_repr", - "url", ] [[package]] @@ -538,9 +548,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pin-project-lite" @@ -748,9 +758,9 @@ checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" [[package]] name = "syn" -version = "2.0.82" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2", "quote", @@ -820,9 +830,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -916,9 +926,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" @@ -928,23 +938,22 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] [[package]] name = "url" -version = "2.4.1" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", "percent-encoding", - "serde", ] [[package]] diff --git a/crates/lsp/Cargo.toml b/crates/lsp/Cargo.toml index eaa96cf7..519aeba9 100644 --- a/crates/lsp/Cargo.toml +++ b/crates/lsp/Cargo.toml @@ -20,7 +20,7 @@ crossbeam-channel = "0.5.13" dashmap = "6.1" glob = "0.3" lsp-server = "0.7.7" -lsp-types = "0.95.0" +lsp-types = "0.97.0" regex = "1" ropey = "1.6" thiserror = "1.0" @@ -33,6 +33,7 @@ tree-sitter = "0.22" tree-sitter-beancount = "2" #tree-sitter-beancount = {git = "https://github.com/polarmutex/tree-sitter-beancount.git", branch="devel"} threadpool = "1.8.1" +url = "2" [dependencies.tracing-subscriber] version = "0.3.18" diff --git a/crates/lsp/src/forest.rs b/crates/lsp/src/forest.rs index f62d7347..f21a5045 100644 --- a/crates/lsp/src/forest.rs +++ b/crates/lsp/src/forest.rs @@ -2,18 +2,21 @@ use crate::beancount_data::BeancountData; use crate::server::LspServerStateSnapshot; use crate::server::ProgressMsg; use crate::server::Task; +use crate::utils::ToFilePath; use crossbeam_channel::Sender; use glob::glob; use std::collections::linked_list::LinkedList; use std::fs; use std::path; +use std::path::PathBuf; +use std::str::FromStr; use tracing::error; // Issus to look at if running into issues with this // https://github.com/silvanshade/lspower/issues/8 pub(crate) fn parse_initial_forest( snapshot: LspServerStateSnapshot, - root_url: lsp_types::Url, + root_url: PathBuf, sender: Sender, ) -> anyhow::Result { let mut seen_files = LinkedList::new(); @@ -43,17 +46,15 @@ pub(crate) fn parse_initial_forest( while iter.peek().is_some() { let file = iter.next().unwrap(); + tracing::info!("processing {:#?}", file); //session // .client // .log_message(lsp::MessageType::INFO, format!("parsing {}", file.as_ref())) // .await; - let file_path = file.to_file_path().ok().unwrap(); - processed += 1; - tracing::info!("processing {}", file.to_string()); - let text = fs::read_to_string(file_path.clone())?; + let text = fs::read_to_string(file.clone())?; let bytes = text.as_bytes(); let mut parser = tree_sitter::Parser::new(); @@ -94,12 +95,15 @@ pub(crate) fn parse_initial_forest( let path = if path.is_absolute() { path.to_path_buf() - } else if file_path.is_absolute() { - file_path.parent().unwrap().join(path) + } else if file.is_absolute() { + file.parent().unwrap().join(path) } else { path.to_path_buf() }; - let path_url = lsp_types::Url::from_file_path(path).unwrap(); + let path_url = lsp_types::Uri::from_str( + format!("file://{}", path.to_str().unwrap()).as_str(), + ) + .unwrap(); Some(path_url) }); @@ -107,10 +111,17 @@ pub(crate) fn parse_initial_forest( // This could get in an infinite loop if there is a loop wtth the include files // TODO see if I can prevent this for include_url in include_filenames { - for entry in glob(include_url.path()).expect("Failed to read glob") { + for entry in glob(include_url.to_file_path().unwrap().to_str().unwrap()) + .expect("Failed to read glob") + { match entry { Ok(path) => { - let url = lsp_types::Url::from_file_path(path).unwrap(); + let url = lsp_types::Uri::from_str( + format!("file://{}", path.to_str().unwrap()).as_str(), + ) + .unwrap() + .to_file_path() + .unwrap(); if !snapshot.forest.contains_key(&url) { total += 1; new_to_processs.push_back(url); diff --git a/crates/lsp/src/handlers.rs b/crates/lsp/src/handlers.rs index 411aae83..3d19f885 100644 --- a/crates/lsp/src/handlers.rs +++ b/crates/lsp/src/handlers.rs @@ -10,10 +10,12 @@ pub mod text_document { use crate::server::Task; use crate::to_json; use crate::treesitter_utils::lsp_textdocchange_to_ts_inputedit; + use crate::utils::ToFilePath; use anyhow::Result; use crossbeam_channel::Sender; use lsp_types::notification::Notification; use std::path::PathBuf; + use std::str::FromStr; use tracing::debug; /// handler for `textDocument/didOpen`. @@ -22,11 +24,11 @@ pub mod text_document { params: lsp_types::DidOpenTextDocumentParams, ) -> Result<()> { debug!("handlers::did_open"); - let uri = params.text_document.uri.clone(); + let uri = params.text_document.uri.to_file_path().unwrap(); let document = Document::open(params.clone()); //let tree = document.tree.clone(); - tracing::debug!("handlers::did_open - adding {}", uri); + tracing::debug!("handlers::did_open - adding {:#?}", &uri); state.open_docs.insert(uri.clone(), document); state.parsers.entry(uri.clone()).or_insert_with(|| { @@ -79,7 +81,7 @@ pub mod text_document { params: lsp_types::DidCloseTextDocumentParams, ) -> Result<()> { tracing::debug!("handlers::did_close"); - let uri = params.text_document.uri; + let uri = params.text_document.uri.to_file_path().unwrap(); state.open_docs.remove(&uri); // let version = Default::default(); Ok(()) @@ -91,8 +93,8 @@ pub mod text_document { params: lsp_types::DidChangeTextDocumentParams, ) -> Result<()> { tracing::debug!("handlers::did_change"); - let uri = ¶ms.text_document.uri; - tracing::debug!("handlers::did_change - requesting {}", uri); + let uri = ¶ms.text_document.uri.to_file_path().unwrap(); + tracing::debug!("handlers::did_change - requesting {:#?}", uri); let doc = state.open_docs.get_mut(uri).unwrap(); tracing::debug!("handlers::did_change - convert edits"); @@ -202,7 +204,7 @@ pub mod text_document { fn handle_diagnostics( snapshot: LspServerStateSnapshot, sender: Sender, - uri: lsp_types::Url, + uri: lsp_types::Uri, ) -> Result<()> { tracing::debug!("handlers::check_beancount"); let bean_check_cmd = &PathBuf::from("bean-check"); @@ -234,7 +236,10 @@ pub mod text_document { .send(Task::Notify(lsp_server::Notification { method: lsp_types::notification::PublishDiagnostics::METHOD.to_owned(), params: to_json(lsp_types::PublishDiagnosticsParams { - uri: file.clone(), + uri: lsp_types::Uri::from_str( + format!("file://{}", file.to_str().unwrap()).as_str(), + ) + .unwrap(), diagnostics, version: None, }) diff --git a/crates/lsp/src/lib.rs b/crates/lsp/src/lib.rs index 95b33698..fcdf3f08 100644 --- a/crates/lsp/src/lib.rs +++ b/crates/lsp/src/lib.rs @@ -11,6 +11,7 @@ pub mod providers; pub mod server; //pub mod session; mod treesitter_utils; +mod utils; use crate::config::Config; use crate::server::LspServerState; @@ -18,6 +19,7 @@ use anyhow::Result; use lsp_server::Connection; use lsp_types::InitializeParams; use serde::{de::DeserializeOwned, Serialize}; +use utils::ToFilePath; pub fn run_server() -> Result<()> { tracing::info!("beancount-language-server started"); diff --git a/crates/lsp/src/providers/completion.rs b/crates/lsp/src/providers/completion.rs index a8449287..bc9b6a95 100644 --- a/crates/lsp/src/providers/completion.rs +++ b/crates/lsp/src/providers/completion.rs @@ -1,9 +1,11 @@ use crate::beancount_data::BeancountData; use crate::server::LspServerStateSnapshot; use crate::treesitter_utils::text_for_tree_sitter_node; +use crate::utils::ToFilePath; use anyhow::Result; use chrono::Datelike; use std::collections::HashMap; +use std::path::PathBuf; use tracing::debug; /// Provider function for LSP ``. @@ -14,7 +16,7 @@ pub(crate) fn completion( ) -> Result>> { debug!("providers::completion"); - let uri = &cursor.text_document.uri; + let uri = &cursor.text_document.uri.to_file_path().unwrap(); let line = &cursor.position.line; let char = &cursor.position.character; debug!("providers::completion - line {} char {}", line, char); @@ -234,7 +236,7 @@ pub fn sub_one_month(date: chrono::NaiveDate) -> chrono::NaiveDate { } fn complete_narration( - data: HashMap, + data: HashMap, ) -> anyhow::Result>> { debug!("providers::completion::narration"); let mut completions = Vec::new(); @@ -252,7 +254,7 @@ fn complete_narration( } fn complete_account( - data: HashMap, + data: HashMap, ) -> anyhow::Result>> { debug!("providers::completion::account"); let mut completions = Vec::new(); @@ -270,7 +272,7 @@ fn complete_account( } fn complete_tag( - data: HashMap, + data: HashMap, ) -> anyhow::Result>> { debug!("providers::completion::tag"); let mut completions = Vec::new(); @@ -288,7 +290,7 @@ fn complete_tag( } fn complete_link( - data: HashMap, + data: HashMap, ) -> anyhow::Result>> { debug!("providers::completion::tag"); let mut completions = Vec::new(); @@ -315,8 +317,11 @@ mod tests { use crate::beancount_data::BeancountData; use crate::config::Config; use crate::document::Document; + use crate::utils::ToFilePath; use anyhow::Result; use std::collections::HashMap; + use std::path::PathBuf; + use std::str::FromStr; use test_log::test; #[derive(Debug)] @@ -404,12 +409,15 @@ mod tests { impl TestState { pub fn new(fixture: &str) -> Result { let fixture = Fixture::parse(fixture); - let forest: HashMap = fixture + let forest: HashMap = fixture .documents .iter() .map(|document| { let path = document.path.as_str(); - let k = lsp_types::Url::parse(format!("file://{path}").as_str()).unwrap(); + let k = lsp_types::Uri::from_str(format!("file://{path}").as_str()) + .unwrap() + .to_file_path() + .unwrap(); let mut parser = tree_sitter::Parser::new(); parser .set_language(&tree_sitter_beancount::language()) @@ -418,23 +426,29 @@ mod tests { (k, v) }) .collect(); - let beancount_data: HashMap = fixture + let beancount_data: HashMap = fixture .documents .iter() .map(|document| { let path = document.path.as_str(); - let k = lsp_types::Url::parse(format!("file://{path}").as_str()).unwrap(); + let k = lsp_types::Uri::from_str(format!("file://{path}").as_str()) + .unwrap() + .to_file_path() + .unwrap(); let content = ropey::Rope::from(document.text.clone()); let v = BeancountData::new(forest.get(&k).unwrap(), &content); (k, v) }) .collect(); - let open_docs: HashMap = fixture + let open_docs: HashMap = fixture .documents .iter() .map(|document| { let path = document.path.as_str(); - let k = lsp_types::Url::parse(format!("file://{path}").as_str()).unwrap(); + let k = lsp_types::Uri::from_str(format!("file://{path}").as_str()) + .unwrap() + .to_file_path() + .unwrap(); let v = Document { content: ropey::Rope::from(document.text.clone()), }; @@ -460,7 +474,7 @@ mod tests { .find_map(|document| document.cursor.map(|cursor| (document, cursor)))?; let path = document.path.as_str(); - let uri = lsp_types::Url::parse(format!("file://{path}").as_str()).unwrap(); + let uri = lsp_types::Uri::from_str(format!("file://{path}").as_str()).unwrap(); let id = lsp_types::TextDocumentIdentifier::new(uri); Some(lsp_types::TextDocumentPositionParams::new(id, cursor)) } @@ -497,7 +511,7 @@ mod tests { #[test] fn handle_date_completion() { let fixure = r#" -%! main.beancount +%! /main.beancount 2 | ^ @@ -550,7 +564,7 @@ mod tests { #[test] fn handle_txn_completion() { let fixure = r#" -%! main.beancount +%! /main.beancount 2023-10-01 t | ^ @@ -591,7 +605,7 @@ mod tests { #[test] fn handle_narration_completion() { let fixure = r#" -%! main.beancount +%! /main.beancount 2023-10-01 open Assets:Test USD 2023-10-01 open Expenses:Test USD 2023-10-01 txn "Test Co" @@ -621,7 +635,7 @@ mod tests { #[test] fn handle_payee_completion() { let fixure = r#" -%! main.beancount +%! /main.beancount 2023-10-01 open Assets:Test USD 2023-10-01 open Expenses:Test USD 2023-10-01 txn "Test Co" "Foo Bar" @@ -643,7 +657,7 @@ mod tests { #[test] fn handle_account_completion() { let fixure = r#" -%! main.beancount +%! /main.beancount 2023-10-01 open Assets:Test USD 2023-10-01 open Expenses:Test USD 2023-10-01 txn "Test Co" "Foo Bar" @@ -679,7 +693,7 @@ mod tests { #[test] fn handle_tag_completion() { let fixure = r#" -%! main.beancount +%! /main.beancount 2023-10-01 open Assets:Test USD 2023-10-01 open Expenses:Test USD 2023-10-01 txn "Test Co" "Foo Bar" #tag ^link @@ -709,7 +723,7 @@ mod tests { #[test] fn handle_link_completion() { let fixure = r#" -%! main.beancount +%! /main.beancount 2023-10-01 open Assets:Test USD 2023-10-01 open Expenses:Test USD 2023-10-01 txn "Test Co" "Foo Bar" #tag ^link diff --git a/crates/lsp/src/providers/diagnostics.rs b/crates/lsp/src/providers/diagnostics.rs index bac6c632..47c78a77 100644 --- a/crates/lsp/src/providers/diagnostics.rs +++ b/crates/lsp/src/providers/diagnostics.rs @@ -1,7 +1,10 @@ use crate::beancount_data::BeancountData; +use crate::utils::ToFilePath; use std::collections::HashMap; use std::path::Path; +use std::path::PathBuf; use std::process::Command; +use std::str::FromStr; use tracing::debug; pub struct DiagnosticData { @@ -31,10 +34,10 @@ impl Default for DiagnosticData { /// Provider function for LSP `textDocument/publishDiagnostics`. pub fn diagnostics( //previous_diagnostics: &DiagnosticData, - beancount_data: HashMap, + beancount_data: HashMap, bean_check_cmd: &Path, root_journal_file: &Path, -) -> HashMap> { +) -> HashMap> { let error_line_regexp = regex::Regex::new(r"^([^:]+):(\d+):\s*(.*)$").unwrap(); debug!("providers::diagnostics"); @@ -48,7 +51,7 @@ pub fn diagnostics( debug!("bean-check generating diags"); let output = std::str::from_utf8(&output.stderr); - let mut map: HashMap> = HashMap::new(); + let mut map: HashMap> = HashMap::new(); for line in output.unwrap().lines() { debug!("line: {}", line); @@ -59,7 +62,10 @@ pub fn diagnostics( character: 0, }; - let file_url = lsp_types::Url::from_file_path(&caps[1]).unwrap(); + let file_url = lsp_types::Uri::from_str(format!("file://{}", &caps[1]).as_str()) + .unwrap() + .to_file_path() + .unwrap(); let diag = lsp_types::Diagnostic { range: lsp_types::Range { start: position, @@ -78,7 +84,7 @@ pub fn diagnostics( HashMap::new() }; - let mut ret: HashMap> = HashMap::new(); + let mut ret: HashMap> = HashMap::new(); // Add previous urls to clear out if neccessary //for it in previous_diagnostics.current_diagnostics.iter() { diff --git a/crates/lsp/src/providers/formatting.rs b/crates/lsp/src/providers/formatting.rs index a90b3202..d45110fd 100644 --- a/crates/lsp/src/providers/formatting.rs +++ b/crates/lsp/src/providers/formatting.rs @@ -1,4 +1,5 @@ use crate::server::LspServerStateSnapshot; +use crate::utils::ToFilePath; use anyhow::Result; use std::cmp::Ordering; use tracing::debug; @@ -67,7 +68,7 @@ pub(crate) fn formatting( ) -> Result>> { debug!("providers::formatting"); - let uri = params.text_document.uri; + let uri = params.text_document.uri.to_file_path().unwrap(); let tree = snapshot.forest.get(&uri).unwrap(); let doc = snapshot.open_docs.get(&uri).unwrap(); diff --git a/crates/lsp/src/server.rs b/crates/lsp/src/server.rs index 6ffb3a7a..7d6f95f3 100644 --- a/crates/lsp/src/server.rs +++ b/crates/lsp/src/server.rs @@ -6,10 +6,13 @@ use crate::document::Document; use crate::forest; use crate::handlers; use crate::progress::Progress; +use crate::utils::ToFilePath; use anyhow::Result; use crossbeam_channel::{Receiver, Sender}; use lsp_types::notification::Notification; use std::collections::HashMap; +use std::path::PathBuf; +use std::str::FromStr; use std::time::Instant; pub(crate) type RequestHandler = fn(&mut LspServerState, lsp_server::Response); @@ -23,7 +26,7 @@ pub(crate) enum ProgressMsg { ForestInit { total: usize, done: usize, - data: Box>, + data: Box>, }, } @@ -48,17 +51,17 @@ struct LspServer { */ pub(crate) struct LspServerState { - pub beancount_data: HashMap, + pub beancount_data: HashMap, // the lsp server config options pub config: Config, - pub forest: HashMap, + pub forest: HashMap, // Documents that are currently kept in memory from the client - pub open_docs: HashMap, + pub open_docs: HashMap, - pub parsers: HashMap, + pub parsers: HashMap, // The request queue keeps track of all incoming and outgoing requests. pub req_queue: lsp_server::ReqQueue<(String, Instant), RequestHandler>, @@ -81,10 +84,10 @@ pub(crate) struct LspServerState { /// A snapshot of the state of the language server pub(crate) struct LspServerStateSnapshot { - pub beancount_data: HashMap, + pub beancount_data: HashMap, pub config: Config, - pub forest: HashMap, - pub open_docs: HashMap, + pub forest: HashMap, + pub open_docs: HashMap, } /* @@ -119,8 +122,12 @@ impl LspServerState { // init forest if self.config.journal_root.is_some() { let file = self.config.journal_root.as_ref().unwrap(); - let journal_root = lsp_types::Url::from_file_path(file) - .unwrap_or_else(|()| panic!("Cannot parse URL for file '{file:?}'")); + let journal_root = + lsp_types::Uri::from_str(format!("file://{}", file.to_str().unwrap()).as_str()) + .unwrap() + .to_file_path() + .unwrap(); + // .unwrap_or_else(|()| panic!("Cannot parse URL for file '{file:?}'")); tracing::info!("initializing forest..."); let snapshot = self.snapshot(); diff --git a/crates/lsp/src/utils.rs b/crates/lsp/src/utils.rs new file mode 100644 index 00000000..8ae44604 --- /dev/null +++ b/crates/lsp/src/utils.rs @@ -0,0 +1,16 @@ +use std::path::PathBuf; +use std::str::FromStr; + +pub trait ToFilePath { + fn to_file_path(&self) -> Result; +} + +impl ToFilePath for lsp_types::Uri { + fn to_file_path(&self) -> Result { + tracing::info!("TOFILEPATH {:#?}", url::Url::from_str(self.as_str())); + tracing::info!("TOFILEPATH {:#?}", url::Url::from_str(self.as_str())); + let url = url::Url::from_str(self.as_str()).map_err(|_| ())?; + tracing::info!("TOFILEPATH {:#?}", url); + url.to_file_path() + } +}