diff --git a/server/src/hover.rs b/server/src/hover.rs index 3ec4cc1..6f9d373 100644 --- a/server/src/hover.rs +++ b/server/src/hover.rs @@ -1,6 +1,6 @@ // Copyright (c) ZeroC, Inc. -use crate::utils::convert_uri_to_slice_formated_url; +use crate::utils::url_to_file_path; use slicec::{ compilation_state::CompilationState, grammar::{Element, Enum, Primitive, Symbol, TypeRef, TypeRefDefinition, Types}, @@ -14,7 +14,7 @@ pub fn try_into_hover_result( uri: Url, position: Position, ) -> tower_lsp::jsonrpc::Result { - let file = convert_uri_to_slice_formated_url(uri) + let file = url_to_file_path(&uri) .and_then(|p| state.files.get(&p)) .expect("Could not convert URI to Slice formatted URL for hover request"); diff --git a/server/src/jump_definition.rs b/server/src/jump_definition.rs index 4999f7c..6f4a2be 100644 --- a/server/src/jump_definition.rs +++ b/server/src/jump_definition.rs @@ -1,6 +1,6 @@ // Copyright (c) ZeroC, Inc. -use crate::utils::convert_uri_to_slice_formated_url; +use crate::utils::url_to_file_path; use slicec::{ compilation_state::CompilationState, grammar::{ @@ -14,7 +14,7 @@ use slicec::{ use tower_lsp::lsp_types::{Position, Url}; pub fn get_definition_span(state: &CompilationState, uri: Url, position: Position) -> Option { - let file_path = convert_uri_to_slice_formated_url(uri)?; + let file_path = url_to_file_path(&uri)?; // Attempt to retrieve the file from the state let file = state.files.get(&file_path)?; diff --git a/server/src/utils.rs b/server/src/utils.rs index bbb2c16..b17de6e 100644 --- a/server/src/utils.rs +++ b/server/src/utils.rs @@ -26,21 +26,12 @@ where } } -// This helper function converts a Url from tower_lsp into a string that can be used to -// retrieve a file from the compilation state from slicec. -pub fn convert_uri_to_slice_formated_url(uri: Url) -> Option { - Some( - uri.to_file_path() - .ok()? - .to_str()? - .to_owned(), - ) -} - pub fn convert_slice_url_to_uri(url: &str) -> Option { Url::from_file_path(url).ok() } +// This helper function converts a Url from tower_lsp into a string that can be used to +// retrieve a file from the compilation state from slicec. pub fn url_to_file_path(url: &Url) -> Option { Some(url.to_file_path().ok()?.to_str()?.to_owned()) }