Skip to content

Commit

Permalink
Improve handling of named pipe arguments
Browse files Browse the repository at this point in the history
Use display_name in more places, and prefer file names with extensions
when we have two arguments.

Fixes #783
  • Loading branch information
Wilfred committed Nov 16, 2024
1 parent 956b09a commit 3a1e398
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => {
Expand Down

0 comments on commit 3a1e398

Please sign in to comment.