mirror of https://github.com/astral-sh/ruff
[ty] Remove last vestiges of `std::path` from `ty_server` (#19088)
Fixes https://github.com/astral-sh/ty/issues/603
This commit is contained in:
parent
9fc04d6bf0
commit
c4f2eec865
|
|
@ -4,10 +4,9 @@
|
||||||
//! are written to `stderr` by default, which should appear in the logs for most LSP clients. A
|
//! are written to `stderr` by default, which should appear in the logs for most LSP clients. A
|
||||||
//! `logFile` path can also be specified in the settings, and output will be directed there
|
//! `logFile` path can also be specified in the settings, and output will be directed there
|
||||||
//! instead.
|
//! instead.
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use std::str::FromStr;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use ruff_db::system::{SystemPath, SystemPathBuf};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tracing::level_filters::LevelFilter;
|
use tracing::level_filters::LevelFilter;
|
||||||
use tracing_subscriber::Layer;
|
use tracing_subscriber::Layer;
|
||||||
|
|
@ -15,14 +14,14 @@ use tracing_subscriber::fmt::time::ChronoLocal;
|
||||||
use tracing_subscriber::fmt::writer::BoxMakeWriter;
|
use tracing_subscriber::fmt::writer::BoxMakeWriter;
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
|
|
||||||
pub(crate) fn init_logging(log_level: LogLevel, log_file: Option<&Path>) {
|
pub(crate) fn init_logging(log_level: LogLevel, log_file: Option<&SystemPath>) {
|
||||||
let log_file = log_file
|
let log_file = log_file
|
||||||
.map(|path| {
|
.map(|path| {
|
||||||
// this expands `logFile` so that tildes and environment variables
|
// this expands `logFile` so that tildes and environment variables
|
||||||
// are replaced with their values, if possible.
|
// are replaced with their values, if possible.
|
||||||
if let Some(expanded) = shellexpand::full(&path.to_string_lossy())
|
if let Some(expanded) = shellexpand::full(&path.to_string())
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|path| PathBuf::from_str(&path).ok())
|
.map(|path| SystemPathBuf::from(&*path))
|
||||||
{
|
{
|
||||||
expanded
|
expanded
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -33,14 +32,11 @@ pub(crate) fn init_logging(log_level: LogLevel, log_file: Option<&Path>) {
|
||||||
std::fs::OpenOptions::new()
|
std::fs::OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
.open(&path)
|
.open(path.as_std_path())
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
#[expect(clippy::print_stderr)]
|
#[expect(clippy::print_stderr)]
|
||||||
{
|
{
|
||||||
eprintln!(
|
eprintln!("Failed to open file at {path} for logging: {err}");
|
||||||
"Failed to open file at {} for logging: {err}",
|
|
||||||
path.display()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ok()
|
.ok()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use std::collections::{BTreeMap, VecDeque};
|
use std::collections::{BTreeMap, VecDeque};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{Context, anyhow};
|
use anyhow::{Context, anyhow};
|
||||||
|
|
@ -235,14 +234,7 @@ impl Session {
|
||||||
// In the future, index the workspace directories to find all projects
|
// In the future, index the workspace directories to find all projects
|
||||||
// and create a project database for each.
|
// and create a project database for each.
|
||||||
let system = LSPSystem::new(self.index.as_ref().unwrap().clone());
|
let system = LSPSystem::new(self.index.as_ref().unwrap().clone());
|
||||||
|
let system_path = workspace.root();
|
||||||
let Some(system_path) = SystemPath::from_std_path(workspace.root()) else {
|
|
||||||
tracing::warn!(
|
|
||||||
"Ignore workspace `{}` because it's root contains non UTF8 characters",
|
|
||||||
workspace.root().display()
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let root = system_path.to_path_buf();
|
let root = system_path.to_path_buf();
|
||||||
let project = ProjectMetadata::discover(&root, &system)
|
let project = ProjectMetadata::discover(&root, &system)
|
||||||
|
|
@ -473,11 +465,15 @@ impl Workspaces {
|
||||||
.to_file_path()
|
.to_file_path()
|
||||||
.map_err(|()| anyhow!("Workspace URL is not a file or directory: {url:?}"))?;
|
.map_err(|()| anyhow!("Workspace URL is not a file or directory: {url:?}"))?;
|
||||||
|
|
||||||
|
// Realistically I don't think this can fail because we got the path from a Url
|
||||||
|
let system_path = SystemPathBuf::from_path_buf(path)
|
||||||
|
.map_err(|_| anyhow!("Workspace URL is not valid UTF8"))?;
|
||||||
|
|
||||||
self.workspaces.insert(
|
self.workspaces.insert(
|
||||||
url,
|
url,
|
||||||
Workspace {
|
Workspace {
|
||||||
options,
|
options,
|
||||||
root: path,
|
root: system_path,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -520,12 +516,12 @@ impl<'a> IntoIterator for &'a Workspaces {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct Workspace {
|
pub(crate) struct Workspace {
|
||||||
root: PathBuf,
|
root: SystemPathBuf,
|
||||||
options: ClientOptions,
|
options: ClientOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Workspace {
|
impl Workspace {
|
||||||
pub(crate) fn root(&self) -> &Path {
|
pub(crate) fn root(&self) -> &SystemPath {
|
||||||
&self.root
|
&self.root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use lsp_types::Url;
|
use lsp_types::Url;
|
||||||
|
use ruff_db::system::SystemPathBuf;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|
@ -89,7 +88,7 @@ pub(crate) struct TracingOptions {
|
||||||
pub(crate) log_level: Option<LogLevel>,
|
pub(crate) log_level: Option<LogLevel>,
|
||||||
|
|
||||||
/// Path to the log file - tildes and environment variables are supported.
|
/// Path to the log file - tildes and environment variables are supported.
|
||||||
pub(crate) log_file: Option<PathBuf>,
|
pub(crate) log_file: Option<SystemPathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is the exact schema for initialization options sent in by the client during
|
/// This is the exact schema for initialization options sent in by the client during
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue