Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use real file path when available in ruff server #11800

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ruff_server/src/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub(crate) fn fix_all(
result: LinterResult { error, .. },
..
} = ruff_linter::linter::lint_fix(
query.virtual_file_path(),
&query.virtual_file_path(),
package,
flags::Noqa::Enabled,
UnsafeFixes::Disabled,
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_server/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub(crate) fn check(query: &DocumentQuery, encoding: PositionEncoding) -> Diagno

// Generate checks.
let LinterResult { data, .. } = check_path(
query.virtual_file_path(),
&query.virtual_file_path(),
package,
&locator,
&stylist,
Expand All @@ -127,7 +127,7 @@ pub(crate) fn check(query: &DocumentQuery, encoding: PositionEncoding) -> Diagno
);

let noqa_edits = generate_noqa_edits(
query.virtual_file_path(),
&query.virtual_file_path(),
data.as_slice(),
&locator,
parsed.comment_ranges(),
Expand Down
16 changes: 10 additions & 6 deletions crates/ruff_server/src/session/index.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::borrow::Cow;
use std::path::PathBuf;
use std::{collections::BTreeMap, path::Path, sync::Arc};

use anyhow::anyhow;
use lsp_types::Url;
use rustc_hash::FxHashMap;
use std::path::PathBuf;
use std::{collections::BTreeMap, path::Path, sync::Arc};

pub(crate) use ruff_settings::RuffSettings;

use crate::{
edit::{DocumentKey, DocumentVersion, NotebookDocument},
Expand All @@ -13,8 +17,6 @@ use super::{settings::ResolvedClientSettings, ClientSettings};

mod ruff_settings;

pub(crate) use ruff_settings::RuffSettings;

type SettingsIndex = BTreeMap<PathBuf, WorkspaceSettings>;

/// Stores and tracks all open documents in a session, along with their associated settings.
Expand Down Expand Up @@ -544,8 +546,10 @@ impl DocumentQuery {
/// Get the path for the document selected by this query, ignoring whether the file exists on disk.
///
/// Returns the URL's path if this is an unsaved (untitled) document.
pub(crate) fn virtual_file_path(&self) -> &Path {
Path::new(self.file_url().path())
pub(crate) fn virtual_file_path(&self) -> Cow<Path> {
self.file_path()
.map(Cow::Owned)
.unwrap_or_else(|| Cow::Borrowed(Path::new(self.file_url().path())))
}

/// Attempt to access the single inner text document selected by the query.
Expand Down
Loading