Improve handling of named pipe arguments

Use display_name in more places, and prefer file names with extensions
when we have two arguments.

Fixes #783
pull/789/head
Wilfred Hughes 2024-11-15 23:11:25 +07:00
parent 956b09a63e
commit 3a1e398edc
3 changed files with 15 additions and 6 deletions

@ -6,6 +6,10 @@ Improved handling of multiline strings, which could cause a crash if
they occurred at the end of the file. This was particularly noticeable
with YAML.
### Parsing
Improved language detection when one argument is a named pipe.
### Syntax Highlighting
Improved syntax highlighting, particularly for keywords.

@ -546,13 +546,12 @@ fn diff_file_content(
diff_options: &DiffOptions,
overrides: &[(LanguageOverride, Vec<glob::Pattern>)],
) -> DiffResult {
let (guess_src, guess_path) = match rhs_path {
FileArgument::NamedPath(path) => (&rhs_src, Path::new(path)),
FileArgument::Stdin => (&rhs_src, Path::new(&display_path)),
FileArgument::DevNull => (&lhs_src, Path::new(&display_path)),
let guess_src = match rhs_path {
FileArgument::DevNull => &lhs_src,
_ => &rhs_src,
};
let language = guess(guess_path, guess_src, overrides);
let language = guess(Path::new(display_path), guess_src, overrides);
let lang_config = language.map(|lang| (lang, tsp::from_language(lang)));
if lhs_src == rhs_src {

@ -556,7 +556,13 @@ fn build_display_path(lhs_path: &FileArgument, rhs_path: &FileArgument) -> Strin
match common_path_suffix(lhs, rhs) {
Some(common_suffix) => common_suffix,
None => rhs.display().to_string(),
None => {
if rhs.extension().is_some() {
rhs.display().to_string()
} else {
lhs.display().to_string()
}
}
}
}
(FileArgument::NamedPath(p), _) | (_, FileArgument::NamedPath(p)) => {