Commit Graph

11476 Commits (809ca7a04adc05d6f705c49ccfc5c58b9ab6a63e)
 

Author SHA1 Message Date
Stargazing Koishi 809ca7a04a
Update linguist-vendored attribute 2023-01-19 14:13:25 +07:00
Wilfred Hughes fe68f43e93 Use crossterm for is_tty and terminal width
This is activly maintained, handles stdout being directed, and seems
to be tested more on Windows too (potentially improving #363).
2023-01-17 00:03:08 +07:00
Wilfred Hughes 64f8baf921 Update Cargo.lock for d8fa9f82b 2023-01-16 09:45:08 +07:00
Wilfred Hughes 4cc6c399c1
Merge pull request #464 from yusancky/yusancky-trans-zh-1
[translation] Adjust content of Chinese translation
2023-01-16 08:30:48 +07:00
yusancky 390fa6f4a5
fix: `这个博客` -> `这篇博客` 2023-01-16 18:05:24 +07:00
yusancky f4fda2479f
Adjust content of Chinese translation 2023-01-16 17:18:26 +07:00
Wilfred Hughes d8fa9f82b2 Update terminal_size 2023-01-15 23:24:51 +07:00
Wilfred Hughes 48c64297c5 Roll version 2023-01-15 20:15:40 +07:00
Wilfred Hughes dffc72d1ca cargo fmt 2023-01-15 20:13:08 +07:00
Wilfred Hughes daa7156a2c Fix crash with --display=inline and trailing whitespace
Line numbers may be less than .max_line(), as .max_line() trims
whitespace. Ensure pad_after() is robust to this, and add a test.

I could only reproduce the crash in inline display mode, but in
principle this could be an issue in all modes.

Fixes #452
2023-01-15 20:04:12 +07:00
Wilfred Hughes e17b6e6109 Clarify wording 2023-01-15 15:56:37 +07:00
Wilfred Hughes c9105ca0ba cargo fmt 2023-01-15 15:49:24 +07:00
Wilfred Hughes b8a2910c26 Reuse the tree-sitter tree for extracting comments
This reduces instruction counts by 9% on some test
files (e.g. samples_files/typing_before.ml).
2023-01-15 15:47:15 +07:00
Wilfred Hughes 2536fe7396 Factor out parsing to tree in main.rs 2023-01-15 15:42:44 +07:00
Wilfred Hughes 2d6ee94ac1 Split out to_tree and to_syntax functions in parser 2023-01-15 15:39:07 +07:00
Wilfred Hughes a488efd63b Add highlighting for ignored syntactic elements
This finishes --ignore-comment support.

Fixes #449.
2023-01-15 14:49:46 +07:00
Wilfred Hughes f3b02f7b47 cargo fmt 2023-01-15 11:43:09 +07:00
Wilfred Hughes 0e3c57c64a Skip unique items before computing Myer's diff on text
This substantially improves performance on text files where there are
few lines in common.

For example, 10,000 line files with no lines in common is more than 10x
faster (8.5 seconds to 0.49 seconds on my machine), and
sample_files/huge_cpp_before.cpp is nearly 2% faster.

Fixes the case mentioned by @quackenbush in #236.

This is inspired by the heuristics discussions at
https://github.com/mitsuhiko/similar/issues/15
2023-01-15 11:38:02 +07:00
Wilfred Hughes c08eefb14a Move slice_by_hash to myers_diff and add unit tests 2023-01-15 11:03:31 +07:00
Wilfred Hughes dd92af3643 Add tests for myers_diff module 2023-01-15 10:55:14 +07:00
Wilfred Hughes 85e630aabc cargo fmt 2023-01-14 12:52:53 +07:00
Wilfred Hughes efec759504 Only set language_used after a full syntactic diff
This fixes cases where the language is detected but the file hits the
byte limit.

Fixes #462.
2023-01-14 12:52:08 +07:00
Wilfred Hughes 6eed874362 Clarify field name 2023-01-14 12:30:54 +07:00
Wilfred Hughes 61a8d1a99f Fix mercurial example
Piping to less as shown just feeds control codes to less, which isn't
useful.

Closes #461
2023-01-13 08:33:55 +07:00
Wilfred Hughes b264360b02 Fix missing swift files from 08b3ff138 2023-01-12 08:15:25 +07:00
Wilfred Hughes 94b6117723 Define an --ignore-comments option and pass to parser
Initial work for #449
2023-01-10 08:47:58 +07:00
Wilfred Hughes 08b3ff138f Rename vendor/ directory
Closes #453
2023-01-10 08:35:01 +07:00
Wilfred Hughes 60b75e0f1b Mark vendor/ directory as vendored 2023-01-10 08:25:05 +07:00
Wilfred Hughes 1ad9789b38 clippy fixes 2023-01-10 00:45:07 +07:00
Wilfred Hughes 63a3bf0c91 Ensure we use the correct config for sublanguage parsing
Otherwise get the wrong node names for atoms.
2023-01-08 22:24:43 +07:00
Wilfred Hughes 8ed4fbccfa Treat colour values (e.g. `#FFF`) as atoms in CSS 2023-01-08 22:22:46 +07:00
Wilfred Hughes 44168638f4 Next release will be 0.42 2023-01-08 22:21:56 +07:00
Wilfred Hughes 29d87a6ac4 Adding TODO 2023-01-08 22:06:58 +07:00
Wilfred Hughes fbe79aa408 Fix spelling 2023-01-08 21:46:02 +07:00
Wilfred Hughes c310fb34f9 Use u32 for edge cost
This is performance neutral (both runtime and memory size) but the
code is slightly readable as there are fewer conversions.
2023-01-08 21:34:49 +07:00
Wilfred Hughes c6d8dedc5d Fix duplicate word in manual 2023-01-08 21:33:55 +07:00
Wilfred Hughes 34967f588d Treat predefined_type as an atom in TypeScript
Currently it contains a nested string node, even though it's a fixed
set of known types. This was preventing us from applying good syntax
highlighting.

This was particularly noticeable with `string`, which wasn't
previously highlighted as a type.
2023-01-07 22:43:50 +07:00
Wilfred Hughes 610a6e441d Ensure that textual fallback diffing has a parse language of None
Previously we still passed the parse language after exceeding the
graph limit, leading to incorrect underline highlighting.
2023-01-06 19:07:05 +07:00
Wilfred Hughes 8a799af0ff cargo fmt 2023-01-06 18:18:37 +07:00
Wilfred Hughes 9ae4eb17fd Add test for is_all_whitespace 2023-01-06 18:16:01 +07:00
Wilfred Hughes d8d4b8c003 Add is_all_whitespace helper function 2023-01-06 08:36:54 +07:00
Wilfred Hughes cd87796552 Treat doctype nodes as atoms in HTML
The tree-sitter parser doesn't include the text after DOCTYPE in the
inner tag.
2023-01-03 08:40:39 +07:00
Steinar H. Gunderson 9133918dd4 Support parsing of sub-languages.
This allows given nodes (configurable per-language, using tree-sitter's
query syntax) to be re-parsed as other languages. The canonical example
is CSS or JavaScript inside HTML, which normally would be a single token
but now can get the full range of syntax highlighting and tree diffing.

The config sets this up for only two languages: HTML (contains CSS or
JavaScript in <script> or <style> tags; we don't support style="" or
onclick="" etc. at this point), and Makefiles (contains Bash in
$(shell ...) commands). The latter is fairly obscure; the big win is
in the former.

It would be nice to also have this support for PHP; however, the HTML
parser seems to be a bit confused when asked to parse the partial HTML
blocks we get if we just mark the "text" blocks as HTML, so for this
to work well, probably the PHP blocks should be parsed as sub-languages
of HTML instead of vice versa.

Also, as a minor quibble, there should be support for bash in Perl's
backticks (similar to in Makefiles), but the tree-sitter Perl parser
does not support backticks at all (it goes into error recovery).

There may have been languages that I've missed, e.g. some languages
might have nodes that contain e.g. SQL.

Fixes #382. Potentially relevant to #376.
2023-01-03 08:31:48 +07:00
Wilfred Hughes 0fc1842595 Improve word highlighting heuristics in comments
Previously we highlighted changed whitespace, which led to ugly
results if the number of words changed (there was a different number
of whitespace characters so some were highlighted).

Also treat _ and - as word constituents, as it produces nicer results
when people write example CLI invocations in comments.
2023-01-02 16:56:31 +07:00
Wilfred Hughes 87dcfd2cca Replace tabs in inline output too 2023-01-01 22:55:48 +07:00
Wilfred Hughes e9eb4cd209 Always return the padding amount in split_string_by_width 2023-01-01 22:50:38 +07:00
Wilfred Hughes e8e5ca8e47 Replace tabs during display, so parsing sees the original source
Fixes #350
2023-01-01 22:44:47 +07:00
Wilfred Hughes 7e560ec943 Use .link_lib_modifier() from latest cc version
https://github.com/rust-lang/cc-rs/pull/671 has now been merged and
released, so a247218811 is now unncessary.
2022-12-30 23:13:46 +07:00
Wilfred Hughes 23ef083412 clippy errors should never stop compilation
Workaround suggested in
https://github.com/rust-lang/rust-clippy/issues/9534
2022-12-30 23:13:17 +07:00
Wilfred Hughes 2b00d9fb34 Update bumpalo 2022-12-30 11:35:17 +07:00