lsp: Revert URL type change (#13193)

This reverts URI changes made in
https://github.com/zed-industries/zed/pull/12928 while keeping the perf
goodies in tact. We should keep an eye out for
https://github.com/gluon-lang/lsp-types/issues/284
Fixes: https://github.com/zed-industries/zed/issues/13135
Fixes: https://github.com/zed-industries/zed/issues/13131
Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-06-18 12:39:56 +02:00 committed by GitHub
parent 479c5df491
commit 3a26a4809d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 189 additions and 344 deletions

View file

@ -22,9 +22,8 @@ collections.workspace = true
futures.workspace = true
gpui.workspace = true
log.workspace = true
lsp-types = { git = "https://github.com/zed-industries/lsp-types", branch = "zed-main" }
lsp-types = { git = "https://github.com/zed-industries/lsp-types", rev = "72357d6f6d212bdffba3b5ef4b31d8ca856058e7" }
parking_lot.workspace = true
pct-str = "2.0"
postage.workspace = true
serde.workspace = true
serde_json.workspace = true

View file

@ -3,9 +3,7 @@ mod input_handler;
pub use lsp_types::request::*;
pub use lsp_types::*;
pub use lsp_types::Uri as RawUri;
use anyhow::{anyhow, bail, Context, Result};
use anyhow::{anyhow, Context, Result};
use collections::HashMap;
use futures::{channel::oneshot, io::BufWriter, select, AsyncRead, AsyncWrite, Future, FutureExt};
use gpui::{AppContext, AsyncAppContext, BackgroundExecutor, Task};
@ -23,13 +21,11 @@ use smol::{
use smol::process::windows::CommandExt;
use std::{
borrow::Cow,
ffi::OsString,
fmt,
io::Write,
path::PathBuf,
pin::Pin,
str::FromStr,
sync::{
atomic::{AtomicI32, Ordering::SeqCst},
Arc, Weak,
@ -58,61 +54,6 @@ pub enum IoKind {
StdErr,
}
#[derive(Clone, Debug, Hash, PartialEq)]
pub struct Uri(lsp_types::Uri);
const FILE_SCHEME: &str = "file://";
impl Uri {
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Self> {
let mut uri = FILE_SCHEME.to_owned();
for part in path.as_ref().components() {
let part: Cow<_> = match part {
std::path::Component::Prefix(prefix) => prefix.as_os_str().to_string_lossy(),
std::path::Component::RootDir => "/".into(),
std::path::Component::CurDir => ".".into(),
std::path::Component::ParentDir => "..".into(),
std::path::Component::Normal(component) => {
let as_str = component.to_string_lossy();
pct_str::PctString::encode(as_str.chars(), pct_str::URIReserved)
.to_string()
.into()
}
};
if !uri.ends_with('/') {
uri.push('/');
}
uri.push_str(&part);
}
Ok(lsp_types::Uri::from_str(&uri)?.into())
}
pub fn to_file_path(self) -> Result<PathBuf> {
if self
.0
.scheme()
.map_or(true, |scheme| !scheme.eq_lowercase("file"))
{
bail!("file path does not have a file scheme");
}
Ok(self.0.path().as_str().into())
}
}
impl PartialEq<lsp_types::Uri> for Uri {
fn eq(&self, other: &lsp_types::Uri) -> bool {
self.0.eq(other)
}
}
impl From<lsp_types::Uri> for Uri {
fn from(uri: lsp_types::Uri) -> Self {
Self(uri)
}
}
impl From<Uri> for lsp_types::Uri {
fn from(uri: Uri) -> Self {
uri.0
}
}
/// Represents a launchable language server. This can either be a standalone binary or the path
/// to a runtime with arguments to instruct it to launch the actual language server file.
#[derive(Debug, Clone, Deserialize)]
@ -582,12 +523,12 @@ impl LanguageServer {
options: Option<Value>,
cx: &AppContext,
) -> Task<Result<Arc<Self>>> {
let root_uri = Uri::from_file_path(&self.working_dir).unwrap();
let root_uri = Url::from_file_path(&self.working_dir).unwrap();
#[allow(deprecated)]
let params = InitializeParams {
process_id: None,
root_path: None,
root_uri: Some(root_uri.clone().into()),
root_uri: Some(root_uri.clone()),
initialization_options: options,
capabilities: ClientCapabilities {
workspace: Some(WorkspaceClientCapabilities {
@ -714,11 +655,10 @@ impl LanguageServer {
..Default::default()
}),
general: None,
notebook_document: None,
},
trace: None,
workspace_folders: Some(vec![WorkspaceFolder {
uri: root_uri.into(),
uri: root_uri,
name: Default::default(),
}]),
client_info: release_channel::ReleaseChannel::try_global(cx).map(|release_channel| {
@ -1384,6 +1324,7 @@ impl FakeLanguageServer {
mod tests {
use super::*;
use gpui::{SemanticVersion, TestAppContext};
use std::str::FromStr;
#[ctor::ctor]
fn init_logger() {
@ -1426,7 +1367,7 @@ mod tests {
server
.notify::<notification::DidOpenTextDocument>(DidOpenTextDocumentParams {
text_document: TextDocumentItem::new(
RawUri::from_str("file://a/b").unwrap(),
Url::from_str("file://a/b").unwrap(),
"rust".to_string(),
0,
"".to_string(),
@ -1447,7 +1388,7 @@ mod tests {
message: "ok".to_string(),
});
fake.notify::<notification::PublishDiagnostics>(PublishDiagnosticsParams {
uri: RawUri::from_str("file://b/c").unwrap(),
uri: Url::from_str("file://b/c").unwrap(),
version: Some(5),
diagnostics: vec![],
});