Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Remove unwrap() from `lsp::Uri::from_file_path` (#50244)

Conrad Irwine762bb96a299
diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs
index ad3d4bdb703..676fd06f495 100644
--- a/crates/project/src/lsp_store.rs
+++ b/crates/project/src/lsp_store.rs
@@ -11406,6 +11406,15 @@ impl LspStore {
let buffer_id = buffer.remote_id();
if local.registered_buffers.contains_key(&buffer_id) {
+ let abs_path = file.abs_path(cx);
+ let uri = match lsp::Uri::from_file_path(&abs_path) {
+ Ok(uri) => uri,
+ Err(()) => {
+ log::error!("failed to convert path to URI: {:?}", abs_path);
+ continue;
+ }
+ };
+
let versions = local
.buffer_snapshots
.entry(buffer_id)
@@ -11427,14 +11436,13 @@ impl LspStore {
let snapshot = versions.last().unwrap();
let version = snapshot.version;
let initial_snapshot = &snapshot.snapshot;
- let uri = lsp::Uri::from_file_path(file.abs_path(cx)).unwrap();
language_server.register_buffer(
uri,
adapter.language_id(&language.name()),
version,
initial_snapshot.text(),
);
- buffer_paths_registered.push((buffer_id, file.abs_path(cx)));
+ buffer_paths_registered.push((buffer_id, abs_path));
local
.buffers_opened_in_servers
.entry(buffer_id)
diff --git a/crates/project/src/lsp_store/lsp_ext_command.rs b/crates/project/src/lsp_store/lsp_ext_command.rs
index 270db67576f..9c284a14361 100644
--- a/crates/project/src/lsp_store/lsp_ext_command.rs
+++ b/crates/project/src/lsp_store/lsp_ext_command.rs
@@ -211,10 +211,10 @@ impl LspCommand for OpenDocs {
_: &Arc<LanguageServer>,
_: &App,
) -> Result<OpenDocsParams> {
+ let uri = lsp::Uri::from_file_path(path)
+ .map_err(|()| anyhow::anyhow!("{path:?} is not a valid URI"))?;
Ok(OpenDocsParams {
- text_document: lsp::TextDocumentIdentifier {
- uri: lsp::Uri::from_file_path(path).unwrap(),
- },
+ text_document: lsp::TextDocumentIdentifier { uri },
position: point_to_lsp(self.position),
})
}