id stringlengths 20 30 | source stringclasses 1
value | chunk_index int64 0 520k | token_count int32 154 512 | content stringlengths 185 57.5k |
|---|---|---|---|---|
rust_dataset_chunk_506100 | rust_dataset.txt | 506,100 | 512 | <str>>,
path_style: PathStyle,
) -> Result<Self, globset::Error> {
let globs = globs
.into_iter()
.map(|as_str| {
GlobBuilder::new(as_str.as_ref())
.backslash_escape(path_style.is_posix())
.build()
})
... |
rust_dataset_chunk_506101 | rust_dataset.txt | 506,101 | 512 | ())
}
pub fn is_match<P: AsRef<RelPath>>(&self, other: P) -> bool {
let other = other.as_ref();
if self
.sources
.iter()
.any(|(_, source, _)| other.starts_with(source) || other.ends_with(source))
{
return true;
}
let other... |
rust_dataset_chunk_506102 | rust_dataset.txt | 506,102 | 512 | 2. Compares sequence lengths for leading zero handling
/// 3. For equal lengths, compares digit by digit
/// 4. For different lengths:
/// - Attempts numeric comparison first (for numbers up to 2^128 - 1)
/// - Falls back to string comparison if numbers would overflow
///
/// The function advances both iterators... |
rust_dataset_chunk_506103 | rust_dataset.txt | 506,103 | 512 | When comparing same letters, lowercase comes before uppercase
/// * Numbers are compared by numeric value, not character by character
/// * Leading zeros affect ordering when numeric values are equal
/// * Can handle numbers larger than u128::MAX (falls back to string comparison)
/// * When strings are equal case-inse... |
rust_dataset_chunk_506104 | rust_dataset.txt | 506,104 | 512 | Ordering {
if a.is_ascii() && b.is_ascii() {
a.bytes()
.map(|byte| byte.to_ascii_lowercase())
.cmp(b.bytes().map(|byte| byte.to_ascii_lowercase()))
} else {
a.to_lowercase().cmp(&b.to_lowercase())
}
}
fn stem_and_extension(filename: &str) -> (Option<&str>, Option<&s... |
rust_dataset_chunk_506105 | rust_dataset.txt | 506,105 | 512 | ,
}
/// Controls how files and directories are ordered relative to each other.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum SortMode {
/// Directories are listed before files at each level.
#[default]
DirectoriesFirst,
/// Files and directories are interleaved alphabetically.
Mixe... |
rust_dataset_chunk_506106 | rust_dataset.txt | 506,106 | 512 | => b_leaf_file.cmp(&a_leaf_file),
SortMode::Mixed => Ordering::Equal,
};
if !file_dir_ordering.is_eq() {
return file_dir_ordering;
}
let (a_stem, a_ext) = a_leaf_file
.then(|| stem_and_extensio... |
rust_dataset_chunk_506107 | rust_dataset.txt | 506,107 | 512 | Equal
}
})
}
(Some(_), None) => Ordering::Greater,
(None, Some(_)) => Ordering::Less,
(None, None) => Ordering::Equal,
};
if !ordering.is_eq() {
... |
rust_dataset_chunk_506108 | rust_dataset.txt | 506,108 | 512 | )
} else {
Ordering::Equal
}
})
});
if !ordering.is_eq() {
return ordering;
}
}
(Some(_), None) => break Ordering::Greater,
... |
rust_dataset_chunk_506109 | rust_dataset.txt | 506,109 | 512 | }
}
pub trait UrlExt {
/// A version of `url::Url::to_file_path` that does platform handling based on the provided `PathStyle` instead of the host platform.
///
/// Prefer using this over `url::Url::to_file_path` when you need to handle paths in a cross-platform way as is the case for remoting interact... |
rust_dataset_chunk_506110 | rust_dataset.txt | 506,110 | 512 | && bytes[bytes.len() - 2].is_ascii_alphabetic()
&& matches!(bytes[bytes.len() - 1], b':' | b'|')
{
bytes.push(b'/');
}
let path = String::from_utf8(bytes).map_err(|_| ())?;
debug_assert!(
PathStyle::Unix.is_... |
rust_dataset_chunk_506111 | rust_dataset.txt | 506,111 | 512 | _assert!(
PathStyle::Windows.is_absolute(Path::new(&string)),
"to_file_path() failed to produce an absolute Path"
);
let path = PathBuf::from(string);
Ok(path)
}
Err(())
}
}
/// Converts the already-decoded path of a URL into a pat... |
rust_dataset_chunk_506112 | rust_dataset.txt | 506,112 | 512 | assert!(PathMatcher::new(patterns, path_style).is_err());
let mut errors = Vec::new();
let matcher =
PathMatcher::new_lenient(["[", "{"], path_style, |error| errors.push(error));
assert_eq!(errors.len(), 2);
assert_eq!(matcher.path_style, path_style);
... |
rust_dataset_chunk_506113 | rust_dataset.txt | 506,113 | 512 | ) -> (&'static RelPath, bool) {
(RelPath::from_unix_str(path).unwrap(), is_file)
}
fn sorted_rel_paths(
mut paths: Vec<(&'static RelPath, bool)>,
mode: SortMode,
order: SortOrder,
) -> Vec<(&'static RelPath, bool)> {
paths.sort_by(|&a, &b| compare_rel_paths_by(a, b, ... |
rust_dataset_chunk_506114 | rust_dataset.txt | 506,114 | 512 | /file.rs"), true),
(Path::new("test_dirs/file.txt"), true),
(Path::new("test_dirs/file.md"), true),
(Path::new("test_dirs/file"), true),
(Path::new("test_dirs/file.a"), true),
];
paths.sort_by(|&a, &b| compare_paths(a, b));
assert_eq!(
... |
rust_dataset_chunk_506115 | rust_dataset.txt | 506,115 | 512 | Path::new("dir01"), false),
(Path::new("dir2"), false),
(Path::new("Dir02"), false),
(Path::new("dir10"), false),
(Path::new("Dir10"), false),
];
entries.sort_by(|&a, &b| compare_paths(a, b));
let ordered: Vec<&str> = entries
.iter()
... |
rust_dataset_chunk_506116 | rust_dataset.txt | 506,116 | 512 | (RelPath::from_unix_str("aardvark.txt").unwrap(), true),
];
paths
.sort_by(|&a, &b| compare_rel_paths_by(a, b, SortMode::FilesFirst, SortOrder::Default));
// Files first (case-insensitive), then directories (case-insensitive)
assert_eq!(
paths,
... |
rust_dataset_chunk_506117 | rust_dataset.txt | 506,117 | 512 | ("dir10").unwrap(), false),
(RelPath::from_unix_str("file1.txt").unwrap(), true),
];
paths
.sort_by(|&a, &b| compare_rel_paths_by(a, b, SortMode::FilesFirst, SortOrder::Default));
assert_eq!(
paths,
vec![
(RelPath::from_unix_str("fi... |
rust_dataset_chunk_506118 | rust_dataset.txt | 506,118 | 512 | ,
vec![
(RelPath::from_unix_str("Dir1").unwrap(), false),
(RelPath::from_unix_str("dir2").unwrap(), false),
(RelPath::from_unix_str("file1.txt").unwrap(), true),
(RelPath::from_unix_str("file2.txt").unwrap(), true),
]
);
... |
rust_dataset_chunk_506119 | rust_dataset.txt | 506,119 | 512 | ),
(RelPath::from_unix_str("target").unwrap(), false),
]
);
}
#[perf]
fn compare_rel_paths_files_first_with_nested() {
// Files come before directories, even with nested paths
let mut paths = vec![
(RelPath::from_unix_str("src/lib.rs").unwrap(... |
rust_dataset_chunk_506120 | rust_dataset.txt | 506,120 | 512 | _unix_str(".github").unwrap(), false),
(RelPath::from_unix_str("src").unwrap(), false),
];
paths
.sort_by(|&a, &b| compare_rel_paths_by(a, b, SortMode::FilesFirst, SortOrder::Default));
assert_eq!(
paths,
vec![
(RelPath::from_unix_s... |
rust_dataset_chunk_506121 | rust_dataset.txt | 506,121 | 512 | (RelPath::from_unix_str("a.py").unwrap(), true),
(RelPath::from_unix_str("a.RS").unwrap(), true),
(RelPath::from_unix_str("b.rs").unwrap(), true),
(RelPath::from_unix_str("file2.rs").unwrap(), true),
(RelPath::from_unix_str("file10.rs").unwrap(), true),
... |
rust_dataset_chunk_506122 | rust_dataset.txt | 506,122 | 512 | by extension
let mut paths = vec![
(RelPath::from_unix_str("file.rs").unwrap(), true),
(RelPath::from_unix_str("file.md").unwrap(), true),
(RelPath::from_unix_str("file.txt").unwrap(), true),
];
paths.sort_by(|&a, &b| compare_rel_paths_by(a, b, SortMode::Mixe... |
rust_dataset_chunk_506123 | rust_dataset.txt | 506,123 | 512 | RelPath::from_unix_str("a.txt").unwrap(), true),
(RelPath::from_unix_str("A.txt").unwrap(), true),
]
);
}
#[perf]
fn compare_rel_paths_upper() {
let directories_only_paths = vec![
rel_path_entry("mixedCase", false),
rel_path_entry("Zebra",... |
rust_dataset_chunk_506124 | rust_dataset.txt | 506,124 | 512 | ),
rel_path_entry("banana", false),
rel_path_entry("dog.md", true),
rel_path_entry("file1.txt", true),
]
);
assert_eq!(
sorted_rel_paths(
file_and_directory_paths,
SortMode::FilesFirst,
... |
rust_dataset_chunk_506125 | rust_dataset.txt | 506,125 | 512 | ,
),
vec![
rel_path_entry(".hidden", false),
rel_path_entry("banana", false),
rel_path_entry("dog", false),
rel_path_entry("mixedCase", false),
rel_path_entry("ALLCAPS", false),
rel_path_entry("Apple"... |
rust_dataset_chunk_506126 | rust_dataset.txt | 506,126 | 512 | _paths = vec![
rel_path_entry("mixedCase", false),
rel_path_entry("Zebra", false),
rel_path_entry("banana", false),
rel_path_entry("ALLCAPS", false),
rel_path_entry("Apple", false),
rel_path_entry("dog", false),
rel_path_entry(".hidden"... |
rust_dataset_chunk_506127 | rust_dataset.txt | 506,127 | 512 | Mode::FilesFirst,
SortOrder::Unicode,
),
vec![
rel_path_entry("Apple.txt", true),
rel_path_entry("File2.txt", true),
rel_path_entry("dog.md", true),
rel_path_entry("file1.txt", true),
rel_path_entry("... |
rust_dataset_chunk_506128 | rust_dataset.txt | 506,128 | 512 | None, "{input}");
}
}
#[test]
fn path_with_position_preserves_path_separators() {
for (input, expected_path, expected_column) in [
(
"/home/user/project/src/main.rs:49",
"/home/user/project/src/main.rs",
None,
),
... |
rust_dataset_chunk_506129 | rust_dataset.txt | 506,129 | 512 | /a(b).rs"),
("parent/😀(b).rs(12,3)", "parent/😀(b).rs"),
("parent/a(b).rs:(12,3)", "parent/a(b).rs"),
(r"src\file.rs\file.rs:12:3", r"src\file.rs\file.rs"),
] {
assert_eq!(
PathWithPosition::parse_str(input),
PathWithPosition {
... |
rust_dataset_chunk_506130 | rust_dataset.txt | 506,130 | 512 | "),
PathWithPosition {
path: PathBuf::from("test_file"),
row: Some(10),
column: Some(1)
}
);
assert_eq!(
PathWithPosition::parse_str("test_file.rs:"),
PathWithPosition {
path: PathBuf::from("... |
rust_dataset_chunk_506131 | rust_dataset.txt | 506,131 | 512 | 10-201212.log:34:"),
PathWithPosition {
path: PathBuf::from("app-editors:zed-0.143.6:20240710-201212.log"),
row: Some(34),
column: None,
}
);
assert_eq!(
PathWithPosition::parse_str("crates/file_finder/src/file_finder.r... |
rust_dataset_chunk_506132 | rust_dataset.txt | 506,132 | 512 | ("crates\\utils\\paths.rs"),
row: Some(101),
column: None
}
);
assert_eq!(
PathWithPosition::parse_str("\\\\?\\C:\\Users\\someone\\test_file.rs:1:20"),
PathWithPosition {
path: PathBuf::from("\\\\?\\C:\\Users\\someone\\... |
rust_dataset_chunk_506133 | rust_dataset.txt | 506,133 | 512 | _file.rs(1902):"),
PathWithPosition {
path: PathBuf::from("\\\\?\\C:\\Users\\someone\\test_file.rs"),
row: Some(1902),
column: None,
}
);
assert_eq!(
PathWithPosition::parse_str("C:\\Users\\someone\\test_file.rs:1902:13... |
rust_dataset_chunk_506134 | rust_dataset.txt | 506,134 | 512 | !(path.extension_or_hidden_file_name(), Some("rs"));
// Multiple dots in name
let path = Path::new("/a/b/c/long.file.name.rs");
assert_eq!(path.extension_or_hidden_file_name(), Some("rs"));
// Hidden file, no extension
let path = Path::new("/a/b/c/.gitignore");
assert_e... |
rust_dataset_chunk_506135 | rust_dataset.txt | 506,135 | 512 | _path = SanitizedPath::new(path);
assert_eq!(
sanitized_path.to_string(),
"C:\\Users\\someone\\test_file.rs"
);
let path = Path::new("\\\\?\\C:\\Users\\someone\\test_file.rs");
let sanitized_path = SanitizedPath::new(path);
assert_eq!(
sanitiz... |
rust_dataset_chunk_506136 | rust_dataset.txt | 506,136 | 512 | 100"), Ordering::Greater);
assert_eq!(compare("100", "0100"), Ordering::Less);
assert_eq!(compare("0100", "00100"), Ordering::Less);
// Large numbers
assert_eq!(compare("9999999999", "10000000000"), Ordering::Less);
assert_eq!(
compare(
"3402823669209... |
rust_dataset_chunk_506137 | rust_dataset.txt | 506,137 | 512 | ::Greater);
assert_eq!(natural_sort("a1b", "a1c"), Ordering::Less);
// Multiple numeric segments
assert_eq!(natural_sort("1a2", "1a10"), Ordering::Less);
assert_eq!(natural_sort("1a10", "1a2"), Ordering::Greater);
assert_eq!(natural_sort("2a1", "10a1"), Ordering::Less);
... |
rust_dataset_chunk_506138 | rust_dataset.txt | 506,138 | 512 | ("a", true, "a", true), Ordering::Equal);
// Files vs Directories
assert_eq!(compare("a", true, "a", false), Ordering::Greater);
assert_eq!(compare("a", false, "a", true), Ordering::Less);
assert_eq!(compare("b", false, "a", true), Ordering::Less);
// Extensions
assert_... |
rust_dataset_chunk_506139 | rust_dataset.txt | 506,139 | 512 | ", true),
Ordering::Greater
);
assert_eq!(
compare(
"project/tests/test_1.rs",
true,
"project/tests/test_2.rs",
true
),
Ordering::Less
);
assert_eq!(
compare(
... |
rust_dataset_chunk_506140 | rust_dataset.txt | 506,140 | 512 | // Leading zeros
assert_eq!(natural_sort("file002", "file2"), Ordering::Greater);
assert_eq!(natural_sort("file002", "file10"), Ordering::Less);
// Very large numbers
assert_eq!(
natural_sort("file999999999999999999999", "file999999999999999999998"),
Orde... |
rust_dataset_chunk_506141 | rust_dataset.txt | 506,141 | 512 | -sensitive comparison only occurs when both are equal case-insensitively.
assert_eq!(natural_sort("Dir1", "dir01"), Ordering::Less);
assert_eq!(natural_sort("dir2", "Dir02"), Ordering::Less);
assert_eq!(natural_sort("dir2", "dir02"), Ordering::Less);
// Numerically equal and case-insens... |
rust_dataset_chunk_506142 | rust_dataset.txt | 506,142 | 512 | assert_eq!(path.multiple_extensions(), None);
// Stories sample extension
let path = Path::new("/a/b/c/file_name.stories.tsx");
assert_eq!(path.multiple_extensions(), Some("stories.tsx".to_string()));
// Longer sample extension
let path = Path::new("/a/b/c/long.app.tar.... |
rust_dataset_chunk_506143 | rust_dataset.txt | 506,143 | 512 | ";
assert_eq!(WslPath::from_path(&path), None);
let path = r"\\wsl.localhost\Distro";
assert_eq!(
WslPath::from_path(&path),
Some(WslPath {
distro: "Distro".to_owned(),
path: "/".into(),
})
);
let path = r"\\ws... |
rust_dataset_chunk_506144 | rust_dataset.txt | 506,144 | 512 | C:/project", PathStyle::Unix),
"/C:/project"
);
}
#[test]
fn test_url_to_file_path_ext_posix_basic() {
use super::UrlExt;
let url = url::Url::parse("file:///home/user/file.txt").unwrap();
assert_eq!(
url.to_file_path_ext(PathStyle::Unix),
... |
rust_dataset_chunk_506145 | rust_dataset.txt | 506,145 | 512 | (PathStyle::Unix), Err(()));
}
#[test]
fn test_url_to_file_path_ext_posix_windows_drive_letter() {
use super::UrlExt;
let url = url::Url::parse("file:///C:").unwrap();
assert_eq!(
url.to_file_path_ext(PathStyle::Unix),
Ok(PathBuf::from("/C:/"))
);
... |
rust_dataset_chunk_506146 | rust_dataset.txt | 506,146 | 512 | unwrap();
assert_eq!(
url.to_file_path_ext(PathStyle::Windows),
Ok(PathBuf::from("d:\\folder\\file.txt"))
);
}
#[test]
fn test_url_to_file_path_ext_windows_unc_path() {
use super::UrlExt;
let url = url::Url::parse("file://server/share/path/file.txt")... |
rust_dataset_chunk_506147 | rust_dataset.txt | 506,147 | 512 | .com/path").unwrap();
assert_eq!(url.to_file_path_ext(PathStyle::Unix), Err(()));
assert_eq!(url.to_file_path_ext(PathStyle::Windows), Err(()));
let url = url::Url::parse("https://example.com/path").unwrap();
assert_eq!(url.to_file_path_ext(PathStyle::Unix), Err(()));
assert_eq!... |
rust_dataset_chunk_506148 | rust_dataset.txt | 506,148 | 512 | with_context(|| {
format!(
"failed to spawn command {}",
crate::redact::redact_command(&format!("{command:?}"))
)
})?;
Ok(Self { process })
}
#[cfg(windows)]
pub fn spawn(
command: std::process::Command,
... |
rust_dataset_chunk_506149 | rust_dataset.txt | 506,149 | 512 | object early,
// which triggers `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE` and kills the
// child before `output()` finishes collecting its stdout/stderr.
Ok(self.process.output().await?)
}
#[cfg(not(windows))]
pub fn kill(&mut self) -> Result<()> {
let pid = self.process.id();
... |
rust_dataset_chunk_506150 | rust_dataset.txt | 506,150 | 512 | unsafe impl Send for JobObject {}
unsafe impl Sync for JobObject {}
impl JobObject {
pub(crate) fn new() -> Result<Self> {
unsafe {
let job =
Self(CreateJobObjectW(None, None).context("failed to create job object")?);
let mut info = JO... |
rust_dataset_chunk_506151 | rust_dataset.txt | 506,151 | 512 | () {
let mut command = gpui_util::new_std_command("ping.exe");
command.args(["-n", "60", "127.0.0.1"]);
let process = smol::process::Command::from(command)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.kill_on_drop(true)
... |
rust_dataset_chunk_506152 | rust_dataset.txt | 506,152 | 512 | "
);
child.kill().expect("failed to terminate job");
let deadline = Instant::now() + Duration::from_secs(2);
while child.has_running_processes().expect("failed to query job") != Some(false) {
assert!(Instant::now() < deadline, "job did not become inactive");
std:... |
rust_dataset_chunk_506153 | rust_dataset.txt | 506,153 | 512 | Ok(handle) = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, pid) else {
return false;
};
let mut exit_code = 0u32;
let alive = GetExitCodeProcess(handle, &mut exit_code).is_ok()
&& exit_code == STILL_ACTIVE.0 as u32;
CloseHandle(han... |
rust_dataset_chunk_506154 | rust_dataset.txt | 506,154 | 512 | (suffix))
}
pub fn is_valid_environment_name(name: &str) -> bool {
!name.is_empty()
&& name
.chars()
.all(|character| character != '=' && !character.is_control())
}
/// Redact a string which could include a command with environment variables
pub fn redact_command(command: &str) -> ... |
rust_dataset_chunk_506155 | rust_dataset.txt | 506,155 | 512 | mut schemars::SchemaGenerator,
schema: impl Fn() -> schemars::Schema,
) -> schemars::Schema {
let schema_name = T::schema_name();
let definitions = generator.definitions_mut();
assert!(!definitions.contains_key(&format!("{schema_name}2")));
assert!(definitions.contains_key(schema_name.as_ref()));
... |
rust_dataset_chunk_506156 | rust_dataset.txt | 506,156 | 512 | ("allowTrailingCommas".to_string(), true.into());
}
}
}
--- FILE: zed/crates/util/src/serde.rs ---
pub const fn default_true() -> bool {
true
}
pub fn is_default<T: Default + PartialEq>(value: &T) -> bool {
*value == T::default()
}
--- FILE: zed/crates/util/src/shell_builder.rs ---
use std::bor... |
rust_dataset_chunk_506157 | rust_dataset.txt | 506,157 | 512 | ShellKind::Posix
| ShellKind::Nushell
| ShellKind::Fish
| ShellKind::Csh
| ShellKind::Tcsh
| ShellKind::Rc
| ShellKind::Xonsh
| ShellKind::Elvish => {
let interactivity = s... |
rust_dataset_chunk_506158 | rust_dataset.txt | 506,158 | 512 | Kind::Tcsh
| ShellKind::Rc
| ShellKind::Xonsh
| ShellKind::Elvish => {
combined_command.insert(0, '(');
combined_command.push_str("\n) </dev/null");
}
ShellKind::PowerShell... |
rust_dataset_chunk_506159 | rust_dataset.txt | 506,159 | 512 | arguments.
///
/// Prefer this over manually constructing a command with the output of `Self::build`,
/// as this method handles `cmd` weirdness on windows correctly.
pub fn build_smol_command(
self,
task_command: Option<String>,
task_args: &[String],
) -> smol::process::Com... |
rust_dataset_chunk_506160 | rust_dataset.txt | 506,160 | 512 | "echo '$env.hello' '$env.world' nothing '--($env.something)' '$' '${test'"
]
);
}
#[test]
fn test_literal_args_skip_variable_substitution() {
let shell = Shell::Program("nu".to_owned());
let (program, args) = ShellBuilder::new(&shell, false)
.... |
rust_dataset_chunk_506161 | rust_dataset.txt | 506,161 | 512 | _dev_null()
.build(Some(command.into()), &[]);
assert_eq!(program, "sh");
assert_eq!(
args,
vec!["-i", "-c", "exec </dev/null\ncat <<EOF\nhello\nEOF"]
);
}
#[test]
fn non_interactive_omits_interactive_flag() {
// Headless hosts (e.g. the ... |
rust_dataset_chunk_506162 | rust_dataset.txt | 506,162 | 512 | );
}
#[test]
fn windows_cmd_preserves_spaced_arg_as_single_shell_argument() {
let worktree_root = r"C:\worktrees\Godot Projects\sample-game";
let shell = Shell::Program("cmd".to_owned());
let (program, args) = ShellBuilder::new(&shell, true)
.build(Some("echo".i... |
rust_dataset_chunk_506163 | rust_dataset.txt | 506,163 | 512 | integrations that call posix_spawnp outside a real PTY), causing a
/// non-zero exit status even though `zed --printenv` ran successfully and
/// produced valid output on its separate fd.
fn parse_env_output(
env_output: &str,
status: &std::process::ExitStatus,
successful_capture_warning: impl FnOnce() -> ... |
rust_dataset_chunk_506164 | rust_dataset.txt | 506,164 | 512 | >'"
// use "-l -e '<command>; exit'" instead
ShellKind::Nushell => command.arg("-e"),
_ => command.args(["-i", "-c"]),
};
// Prefix with "./" if the path starts with "-" to prevent cd from interpreting it as a flag
let dir_str = directory.to_string_lossy();
let dir_str = if dir_... |
rust_dataset_chunk_506165 | rust_dataset.txt | 506,165 | 512 | #issuecomment-2999645482
const FD_STDIN: std::os::fd::RawFd = 0;
const FD_STDOUT: std::os::fd::RawFd = 1;
const FD_STDERR: std::os::fd::RawFd = 2;
match shell_kind {
ShellKind::Rc => (FD_STDIN, format!(">[1={FD_STDIN}]")), // `[1=0]`
ShellKind::Nushell | ShellKind::Tcsh => (FD_STDOUT, "... |
rust_dataset_chunk_506166 | rust_dataset.txt | 506,166 | 512 | Prefix with "./" if the path starts with "-" to prevent cd from interpreting it as a flag
let directory_string = directory.display().to_string();
let directory_string = if directory_string.starts_with('-') {
format!("./{directory_string}")
} else {
directory_string
};
let zed_path_s... |
rust_dataset_chunk_506167 | rust_dataset.txt | 506,167 | 512 |
.with_context(|| format!("command {cmd:?}"))?;
let env_output = String::from_utf8_lossy(&output.stdout);
parse_env_output(
&env_output,
&output.status,
|| {
format!(
"Command {cmd:?} exited with {} but environment was captured successfully. stderr: {... |
rust_dataset_chunk_506168 | rust_dataset.txt | 506,168 | 512 | _eq!((descriptor, redirection), (0, String::from("> /dev/fd/0")));
}
Ok(())
}
#[test]
fn parse_env_output_accepts_valid_env_when_shell_exits_nonzero() {
let env_json = serde_json::json!({
"PATH": path!("/usr/bin"),
"SHELL": path!("/bin/zsh"),
});
... |
rust_dataset_chunk_506169 | rust_dataset.txt | 506,169 | 512 | Shell::Program(program) => (program.clone(), &[]),
Shell::WithArguments { program, args, .. } => (program.clone(), args),
Shell::System => (get_system_shell(), &[]),
}
}
pub fn shell_kind(&self, is_windows: bool) -> ShellKind {
match self {
Shell:... |
rust_dataset_chunk_506170 | rust_dataset.txt | 506,170 | 512 | _in_installation(&path))
{
return Some(bash);
}
let git = which::which("git").ok()?;
let binary_directory = git.parent()?;
let parent = binary_directory.parent()?;
find_bash_in_installation(parent).or_else(|| find_bash_in_installation(parent.parent()?))
}
... |
rust_dataset_chunk_506171 | rust_dataset.txt | 506,171 | 512 | &&` and `||` for conditional
/// execution, `$()` and backticks for command substitution, and process substitution.
///
/// # Shell Notes
///
/// - **Nushell**: Uses `;` for sequential execution. The `and`/`or` keywords are boolean
/// operators on values (e.g., `$true and $false`), not comman... |
rust_dataset_chunk_506172 | rust_dataset.txt | 506,172 | 512 | Pwsh,
"cmd" => ShellKind::Cmd,
"nu" => ShellKind::Nushell,
"fish" => ShellKind::Fish,
"csh" => ShellKind::Csh,
"tcsh" => ShellKind::Tcsh,
"rc" => ShellKind::Rc,
"xonsh" => ShellKind::Xonsh,
"elvish" => ShellKind::Elvish,
... |
rust_dataset_chunk_506173 | rust_dataset.txt | 506,173 | 512 | ("${") {
match var_str.strip_suffix('}') {
Some(var_name) if !var_name.is_empty() && !var_name.contains(':') => {
format!("$env:{var_name}")
}
// `${SOME_VAR:-SOME_DEFAULT}`, we currently do not handle this situation,
// whi... |
rust_dataset_chunk_506174 | rust_dataset.txt | 506,174 | 512 | || c == '_' => {
let end = source
.find(|c: char| !c.is_alphanumeric() && c != '_')
.unwrap_or(source.len());
let var_name = &source[..end];
if !is_start {
text.push_str("(");
}
t... |
rust_dataset_chunk_506175 | rust_dataset.txt | 506,175 | 512 | ShellKind::Cmd => '&',
ShellKind::Posix
| ShellKind::Csh
| ShellKind::Tcsh
| ShellKind::Rc
| ShellKind::Fish
| ShellKind::PowerShell
| ShellKind::Pwsh
| ShellKind::Nushell
| ShellKind::Xonsh
... |
rust_dataset_chunk_506176 | rust_dataset.txt | 506,176 | 512 | i < chars.len() {
if chars[i] == '\\' {
let mut num_backslashes = 0;
while i < chars.len() && chars[i] == '\\' {
num_backslashes += 1;
i += 1;
}
if i < chars.len() && chars[i] == '"' {
... |
rust_dataset_chunk_506177 | rust_dataset.txt | 506,177 | 512 | .push('\'');
for c in s.chars() {
if c == '\'' {
result.push('\'');
}
result.push(c);
}
result.push('\'');
result
}
pub fn quote_powershell(arg: &str) -> Cow<'_, str> {
let ps_will_quote = Self::need_quotes_powershell(a... |
rust_dataset_chunk_506178 | rust_dataset.txt | 506,178 | 512 | if !arg.contains('\'') {
return Some(Cow::Owned(format!("'{arg}'")));
}
let mut quoted = String::with_capacity(arg.len() + 2);
quoted.push('"');
for character in arg.chars() {
if character == '\\' || character == '"' {
quoted.push('\\');
... |
rust_dataset_chunk_506179 | rust_dataset.txt | 506,179 | 512 | literal as a
// command. So strip the quotes, quote the command, and
// re-add the quotes if they are missing after requoting
let quoted = self.try_quote(arg)?;
return Some(if quoted.starts_with(['\'', '"']) {
... |
rust_dataset_chunk_506180 | rust_dataset.txt | 506,180 | 512 | match self {
ShellKind::Cmd => false,
ShellKind::Posix
| ShellKind::Csh
| ShellKind::Tcsh
| ShellKind::Rc
| ShellKind::Fish
| ShellKind::PowerShell
| ShellKind::Pwsh
| ShellKind::Nushell
| ShellKind:... |
rust_dataset_chunk_506181 | rust_dataset.txt | 506,181 | 512 | , "{program}");
}
}
// Examples
// WSL
// wsl.exe --distribution NixOS --cd /home/user -- /usr/bin/zsh -c "echo hello"
// wsl.exe --distribution NixOS --cd /home/user -- /usr/bin/zsh -c "\"echo hello\"" | grep hello"
// wsl.exe --distribution NixOS --cd ~ env RUST_LOG=info,remote=debug ... |
rust_dataset_chunk_506182 | rust_dataset.txt | 506,182 | 512 | v\\Scripts\\python.exe -m pytest \"test_foo.py::test_foo\"")
.unwrap()
.into_owned(),
"^\"C:\\Users\\johndoe\\dev\\python\\39007\\tests\\.venv\\Scripts\\python.exe -m pytest \\^\"test_foo.py::test_foo\\^\"^\"".to_string()
);
}
#[test]
fn test_try_quote_po... |
rust_dataset_chunk_506183 | rust_dataset.txt | 506,183 | 512 | slash (backslash not at end, so not doubled)
assert_eq!(
shell_kind.try_quote("path\\ test").unwrap().into_owned(),
"^\"path\\ test^\"".to_string()
);
// String ending with backslash (must be doubled before closing quote)
assert_eq!(
shell_kind.try_qu... |
rust_dataset_chunk_506184 | rust_dataset.txt | 506,184 | 512 | _prefix_aware("^'uname'")
.unwrap()
.into_owned(),
"^'uname'".to_string()
);
assert_eq!(
shell_kind.try_quote("'uname a'").unwrap().into_owned(),
"\"'uname a'\"".to_string()
);
assert_eq!(
shell_kind
... |
rust_dataset_chunk_506185 | rust_dataset.txt | 506,185 | 512 | _quote("/tmp/a\\'; echo INJECTED; true \\'")
.unwrap(),
"'/tmp/a'\\\\\\''; echo INJECTED; true '\\\\\\'"
);
assert_eq!(
shell_kind.try_quote("say \\\"hi\\\"").unwrap(),
"'say '\\\\'\"hi'\\\\'\"'"
);
asser... |
rust_dataset_chunk_506186 | rust_dataset.txt | 506,186 | 512 | a\\\\b \\\"c\\\" \\'d\\' \\$e \\!f",
"line\nbreak",
"bang!\nnew\\line",
"O'Brien!",
"a\\!b",
"a\\\\!b",
"!1x",
"!",
"!!",
"!$ !* !:1 !-1 !# !?x?",
"ending!",
"trailing\\",
"~/*... |
rust_dataset_chunk_506187 | rust_dataset.txt | 506,187 | 512 | (["-c", &inner]);
let nested = format!(
"{setting}{} {}",
shell_kind.prepend_command_prefix(&shell),
inner_arguments
.iter()
.map(|inner_argument| shell_kind.try_quote(inner_argument).unwrap())
... |
rust_dataset_chunk_506188 | rust_dataset.txt | 506,188 | 512 | script,
&format!("{} OK", shell_kind.try_quote(program).unwrap())
);
let output = smol::block_on(
smol::process::Command::new(&shell_program)
.arg("-f")
.args(&shell_arguments)
... |
rust_dataset_chunk_506189 | rust_dataset.txt | 506,189 | 512 | "%FOO%");
assert_eq!(ShellKind::Nushell.to_shell_variable("${FOO}"), "$env.FOO");
assert_eq!(ShellKind::Posix.to_shell_variable("${FOO}"), "${FOO}");
assert_eq!(ShellKind::PowerShell.to_shell_variable("$FOO"), "$env:FOO");
assert_eq!(
ShellKind::PowerShell.to_shell_variable... |
rust_dataset_chunk_506190 | rust_dataset.txt | 506,190 | 512 | ), "1.5KB");
assert_eq!(format_file_size(999999, true), "1000.0KB");
assert_eq!(format_file_size(1000000, true), "1.0MB");
assert_eq!(format_file_size(1500000, true), "1.5MB");
assert_eq!(format_file_size(10000000, true), "10.0MB");
}
#[test]
fn test_format_file_size_binary(... |
rust_dataset_chunk_506191 | rust_dataset.txt | 506,191 | 512 | }
}
}
result
}};
}
#[macro_export]
macro_rules! assert_set_eq {
($left:expr,$right:expr) => {{
use util::test::*;
use util::set_eq;
let left = $left;
let right = $right;
match set_eq!(&left, &right) {
Err(SetEqError::LeftMissin... |
rust_dataset_chunk_506192 | rust_dataset.txt | 506,192 | 512 | _markers);
let range_lookup = markers
.into_iter()
.map(|marker| {
(
marker.clone(),
match marker {
TextRangeMarker::Empty(empty_marker_char) => marker_offsets
.remove(&empty_marker_char)
... |
rust_dataset_chunk_506193 | rust_dataset.txt | 506,193 | 512 | /// ```
///
/// 3. To mark a range whose direction is meaningful (like a selection),
/// put a caron character beside one of its bounds, on the inside:
///
/// ```text
/// one «ˇreversed» selection and one «forwardˇ» selection
/// ```
///
/// Any • characters in the input string will be replaced with spa... |
rust_dataset_chunk_506194 | rust_dataset.txt | 506,194 | 512 | middle of a range");
}
} else if ranges_are_directed {
panic!("missing 'ˇ' marker to indicate range direction");
}
ranges.push(if reversed {
unmarked_len..current_range_start
} else {
... |
rust_dataset_chunk_506195 | rust_dataset.txt | 506,195 | 512 | }
}
}
impl From<char> for TextRangeMarker {
fn from(marker: char) -> Self {
Self::Empty(marker)
}
}
impl From<(char, char)> for TextRangeMarker {
fn from((left_marker, right_marker): (char, char)) -> Self {
Self::Range(left_marker, right_marker)
}
}
#[cfg(test)]
mod tests ... |
rust_dataset_chunk_506196 | rust_dataset.txt | 506,196 | 512 | => {
fs::create_dir(&path).unwrap();
#[cfg(not(target_family = "wasm"))]
#[allow(clippy::disallowed_methods)]
if path.file_name() == Some(OsStr::new(".git")) {
let output = std::process::Command::new("git")
... |
rust_dataset_chunk_506197 | rust_dataset.txt | 506,197 | 512 | f(Duration::from_secs(0)));
assert_eq!("59s", f(Duration::from_secs(59)));
assert_eq!("1m 0s", f(Duration::from_secs(60)));
assert_eq!("10m 0s", f(Duration::from_secs(600)));
assert_eq!("1h 0m 0s", f(Duration::from_secs(3600)));
assert_eq!("3h 2m 1s", f(Duration::from_secs(3600 ... |
rust_dataset_chunk_506198 | rust_dataset.txt | 506,198 | 512 | _system_shell,
};
pub fn truncate(s: &str, max_chars: usize) -> &str {
match s.char_indices().nth(max_chars) {
None => s,
Some((idx, _)) => &s[..idx],
}
}
/// Parses the contents of an `os-release` file (as found at `/etc/os-release`
/// and described by the systemd spec) into a human-readable... |
rust_dataset_chunk_506199 | rust_dataset.txt | 506,199 | 512 | debug_assert!(max_chars >= 5);
// If the string's byte length is <= max_chars, walking the string can be skipped since the
// number of chars is <= the number of bytes.
if s.len() <= max_chars {
return s.to_string();
}
let suffix_char_length = max_chars.saturating_sub(1);
let truncatio... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.