Commit Graph

1244 Commits

Author SHA1 Message Date
Daniel Shahaf
cdd7f899cb brackets: Optimize the character iteration
Test case: See the first comment of issue #295.

Before:
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)   14         284.67    20.33   82.84%    284.67    20.33   82.84%  _zsh_highlight_highlighter_brackets_paint
 2)   15         313.72    20.91   91.30%     26.62     1.77    7.75%  _zsh_highlight
 3)   14         318.68    22.76   92.74%      7.41     0.53    2.16%  _zsh_highlight_call_widget

After:
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)   15          57.25     3.82   45.33%     28.30     1.89   22.41%  _zsh_highlight
 2)   14          81.96     5.85   64.90%     27.02     1.93   21.40%  _zsh_highlight_call_widget
 3)   14          26.31     1.88   20.84%     26.31     1.88   20.84%  _zsh_highlight_highlighter_brackets_paint
 4)    2          10.66     5.33    8.44%      8.97     4.49    7.10%  VCS_INFO_formats
 5)    2          25.92    12.96   20.52%      7.72     3.86    6.11%  VCS_INFO_get_data_git

(That's not in my everyday configuration but in my minimal testing
setup, which runs vcs_info with the default settings.)
2020-07-14 20:19:40 +00:00
Daniel Shahaf
d62baa50f4 Revert "driver: Move the initialization of $zsh_highlight__memo_feature out of the entry point function."
This reverts commit 8a1bd7c8b6.

The detection only works correctly from a widget function, so the change
was wrong: it caused zsh_highlight__memo_feature to be set to false
every time.
2020-07-14 02:29:46 +00:00
Daniel Shahaf
8a1bd7c8b6 driver: Move the initialization of $zsh_highlight__memo_feature out of the entry point function.
This is needed for feature/redrawhook to be able to use it.
2020-07-14 02:07:32 +00:00
Daniel Shahaf
d9a7963970 driver: Follow-up to grandparent: Have all test suite entry points declare the mock $region_highlight.
tests/generate.zsh already does this.
2020-07-14 01:57:02 +00:00
Daniel Shahaf
810c2dcede Use the new, unreleased zsh 'memo=' feature to remove only our own entries from $region_highlight.
Fixes #418 (interoperability issue with other plugins).
2020-07-14 00:32:36 +00:00
Daniel Shahaf
075c852924 driver: Stop re-declaring $region_highlight. It's unneeded. 2020-07-14 00:32:36 +00:00
Nuri Jung
fb929edc30 docs: regexp highlighter: Fix a wrong associative array name in the example.
Factored out from #747.
2020-07-01 12:55:43 +00:00
Il Harper
91d2eeaf23 docs: Fix obs-repository link 2020-06-15 00:23:05 -05:00
Daniel Shahaf
f6471dbec3 tests: Fix a wrong value of $PREBUFFER in a test, and add checks to prevent this from recurring.
Discussed: https://github.com/zsh-users/zsh-syntax-highlighting/pull/706#issuecomment-642072978
2020-06-11 08:14:07 +00:00
Daniel Shahaf
f6f7a91818 test harness: Fix use of an undefined variable in an error message.
The error message uses «$1», but it is always unset at that point.
Furthermore, the NO_UNSET (-u) option is in effect.  Therefore, when the
error message was to be printed, zsh's NO_UNSET error message was
printed instead:
.
    (anon):20: 1: parameter not set

That error message was printed to stderr, and was caught by the caller
within the test harness:
.
    Bail out! On './highlighters/main/test-data/path_prefix3.zsh': output on stderr

Thus, the bug being fixed would not caused false positive or false
negative test results, but only wrong error messages.

Follow-up to 0.7.1-71-ge6eea1f, "test harness: Don't leak options from
test files to the test harness".
2020-06-11 08:09:45 +00:00
Daniel Shahaf
6fd92e1bbd 'main': Don't progress the $in_redirection staller while $in_param.
Fixes #712.
2020-06-08 14:38:59 +00:00
Daniel Shahaf
792c065acb tests: Add an XFail test for issue #712.
The second test point passes on 0.7.1, but the third does not.
2020-06-08 14:38:43 +00:00
Daniel Shahaf
0f11d80968 'main': Highlight the parentheses of array assignments as reserved words.
Fixes #585.
2020-06-08 14:23:43 +00:00
Daniel Shahaf
00c0c76550 CI += zsh-5.8
Fixes #740.
2020-05-26 17:52:17 +00:00
Matthew Martin
870bccf8ff main: Add tests for arithmetic expansion 2020-05-23 20:29:09 -05:00
Matthew Martin
a238647df9 main: Add arithmetic substitution highlighting
Closes #607 #649 #704
2020-05-23 20:29:00 -05:00
Daniel Shahaf
f8b1470314 changelog.md: Restore vertical whitespace before section headers. 2020-05-22 04:55:17 +00:00
Daniel Shahaf
ade4b28d2d 'main': Fix issue #677, concerning multiline aliases.
The fix is to exempt such aliases from the empty commands sanity check.
2020-05-22 04:54:10 +00:00
Daniel Shahaf
8211a95421 changelog: Update through HEAD. 2020-05-22 04:44:49 +00:00
Daniel Shahaf
d4df626c03 'main': Optimize the unquoted arguments characterwise walker
Fixes #730.

% repeat 3 { zsh -f tests/test-zprof.zsh main | tee … | grep -w _zsh_highlight | head -n1 }
19)    1       26787.11 26787.11  100.00%      5.33     5.33    0.02%  _zsh_highlight
19)    1       26900.64 26900.64  100.00%      5.45     5.45    0.02%  _zsh_highlight
19)    1       26915.76 26915.76  100.00%      5.47     5.47    0.02%  _zsh_highlight

Merge remote-tracking branch 'danielsh/perf-argument-1-v2'

* danielsh/perf-argument-1-v2:
  'main': Further optimize argument parsing.
  'main': Optimize a hot path.
  tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file.
2020-05-22 04:43:04 +00:00
Daniel Shahaf
8f5d74d219 'main': Further optimize argument parsing.
% repeat 3 { zsh -f tests/test-zprof.zsh main | tee … | grep -w _zsh_highlight | head -n1 }
18)    1       26895.86 26895.86  100.00%      6.35     6.35    0.02%  _zsh_highlight
19)    1       27399.11 27399.11  100.00%      5.52     5.52    0.02%  _zsh_highlight
19)    1       27027.58 27027.58  100.00%      5.66     5.66    0.02%  _zsh_highlight

----

This commit has been rebased.  The above statistics were measured after
the rebase.  The below statistics had been measured before the rebase.

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    3       25689.17  8563.06   98.15%  18422.01  6140.67   70.38%  _zsh_highlight_main_highlighter_highlight_list
 2) 32390        5706.13     0.18   21.80%   2315.68     0.07    8.85%  _zsh_highlight_main_highlighter_highlight_argument
19)    1       26173.33 26173.33  100.00%      5.27     5.27    0.02%  _zsh_highlight

Interestingly, if I make the change in this diff to
_zsh_highlight_main_highlighter_highlight_double_quote —

>     diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh
>     index da6ab2b..bb17618 100644
>     --- a/highlighters/main/main-highlighter.zsh
>     +++ b/highlighters/main/main-highlighter.zsh
>     @@ -1462,10 +1462,13 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
>        local i j k ret style
>        reply=()
>
>     -  for (( i = $1 + 1 ; i <= $#arg ; i += 1 )) ; do
>     +  (( i = $1 ))
>     +  while (( ++i <= $#arg )); do
>     +    i=${arg[(ib.i.)[\"\`\$\\\\${histchars[1]}]]}
>          (( j = i + start_pos - 1 ))
>          (( k = j + 1 ))
>          case "$arg[$i]" in
>     +      ("")  break;;
>            ('"') break;;
>            ('`') saved_reply=($reply)
>                  _zsh_highlight_main_highlighter_highlight_backtick $i

— it actually makes things measurably slower (!), even on input that has
a large number of pasted double-quoted strings: on «BUFFER=": ${(r.8*1500..foo"bar".):-}"»
the slowdown is (1123.24ms / 1091.06ms = 1.0295).  Therefore, I won't be
committing that change.
2020-05-22 04:36:59 +00:00
Daniel Shahaf
700c0e18fe 'main': Optimize a hot path.
% git co HEAD^ && repeat 3 { zsh -f tests/test-zprof.zsh main | tee … | grep -w _zsh_highlight | head -n1 }
HEAD is now at 64e3651 'main': Optimize a hot path.
19)    1       28765.13 28765.13  100.00%      5.57     5.57    0.02%  _zsh_highlight
19)    1       28566.46 28566.46  100.00%      5.91     5.91    0.02%  _zsh_highlight
19)    1       28248.12 28248.12  100.00%      5.57     5.57    0.02%  _zsh_highlight

----

This commit has been rebased.  The above statistics were measured after
the rebase.  The below statistics had been measured before the rebase.

Before this patch:

    num  calls                time                       self            name
    -----------------------------------------------------------------------------------
     1)    3       33410.81 11136.94   98.51%  19277.07  6425.69   56.84%  _zsh_highlight_main_highlighter_highlight_list
    19)    1       33916.21 33916.21  100.00%      5.27     5.27    0.02%  _zsh_highlight

With this patch:

    num  calls                time                       self            name
    -----------------------------------------------------------------------------------
     1)    3       27167.49  9055.83   98.17%  18754.77  6251.59   67.77%  _zsh_highlight_main_highlighter_highlight_list
    19)    1       27674.40 27674.40  100.00%      5.39     5.39    0.02%  _zsh_highlight

And if test-zprof.zsh is changed to not set interactivecomments:

    num  calls                time                       self            name
    -----------------------------------------------------------------------------------
     1) 13360       36029.12     2.70   83.56%  30304.23     2.27   70.28%  _zsh_highlight_main_highlighter_highlight_argument
    21)    1       43117.76 43117.76  100.00%      4.52     4.52    0.01%  _zsh_highlight

    num  calls                time                       self            name
    -----------------------------------------------------------------------------------
     1) 13360       14782.89     1.11   68.12%   9163.42     0.69   42.23%  _zsh_highlight_main_highlighter_highlight_argument
    21)    1       21699.93 21699.93  100.00%      4.17     4.17    0.02%  _zsh_highlight
2020-05-22 04:32:39 +00:00
Daniel Shahaf
a50647e77b tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file.
% git co HEAD^ && repeat 3 { zsh -f tests/test-zprof.zsh main | tee … | grep -w _zsh_highlight | head -n1 }
HEAD is now at f1948df tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file.
19)    1       34378.97 34378.97  100.00%      5.43     5.43    0.02%  _zsh_highlight
19)    1       34058.34 34058.34  100.00%      5.50     5.50    0.02%  _zsh_highlight
19)    1       34364.80 34364.80  100.00%      5.36     5.36    0.02%  _zsh_highlight
2020-05-22 04:31:48 +00:00
Daniel Shahaf
b253a8b86a changelog: Update through HEAD.
The great-grandparent commit, "a3ae74 'main': Fix the last commit's bug
concerning parameter elision not happening in redirects in command
position.", is not added because it's not a change with respect
to 0.7.1.
2020-05-22 03:30:49 +00:00
Daniel Shahaf
4dd4797ae0 test harness: Print the expected-v.-actual on every failure, not just upon cardinality failures.
I was looking into something and wanted to see how a the second word in the
array was highlighted, even though the failure was on the third word.
2020-05-22 03:27:48 +00:00
Daniel Shahaf
5171ec524f Document ZSH_HIGHLIGHT_MAXLENGTH.
Fixes #698.
2020-05-22 02:23:18 +00:00
Daniel Shahaf
ea3ae74164 'main': Fix the last commit's bug concerning parameter elision not happening in redirects in command position. 2020-05-13 12:51:52 +00:00
Daniel Shahaf
41b8a74692 'main': Add a test for parameter elision not happening in redirects in command position.
Will be fixed in the next commit.
2020-05-13 12:51:40 +00:00
Daniel Shahaf
3a4b212c7d 'main': Fix regression in zsh 5.3.1 and older: all precmd hooks later than z-sy-h would be aborted.
In those versions of zsh, «[[ -o nosuchoption ]]» is regarded as
a syntax error.  In newer zsh versions, it merely returns non-zero
(specifically, it returns 3, unlike «[[ -o unsetoption ]]» which
returns 1).

Fixes #732.
Fixes #733.
2020-05-06 20:27:55 +00:00
Daniel Shahaf
0582ea1910 changelog += WARN_NESTED_VAR fixes (#727, #731) 2020-05-05 17:59:51 +00:00
Daniel Shahaf
e65ebf0466 'main': Fix a regression caused by the great-grandparent commit's WARN_NESTED_VAR fix.
An error message was emitted on versions of zsh that don't have the
WARN_NESTED_VAR option.

Fixes #731.
2020-05-05 14:31:42 +00:00
Daniel Shahaf
06710f3780 'main': Don't run _zsh_highlight_main__type on every non-command word.
Fixes #728, the performance regression from 0.7.1.
2020-05-04 18:35:15 +00:00
Daniel Shahaf
343ec1061f 'make perf': Show only a cumulative datum per highligher, rather than per test file.
The overall per-highlighter duration should be less prone to random
noise than the multitude of per-test-file figures.
2020-05-04 17:48:47 +00:00
Daniel Shahaf
16d818a21f 'main': Don't trip WARN_NESTED_VAR.
Fixes #727.
2020-05-04 13:27:33 +00:00
Daniel Shahaf
f1b9fbbaf0 'main': Follow-up to previous: Document the version number, and deduplicate some option letters. 2020-04-20 11:11:29 +00:00
Daniel Shahaf
8d32609a7b 'main': precommands += strace 2020-04-20 11:09:24 +00:00
Daniel Shahaf
f5d1be7ec2 editorconfig: Fix Makefile settings 2020-04-12 02:59:39 +00:00
Dimitris Apostolou
415e762ab2
Fix typo 2020-04-08 21:04:48 +03:00
Daniel Shahaf
ccb1da4ae8 Bump copyright years. 2020-04-03 02:03:18 +00:00
Daniel Shahaf
96eb2e31a1 driver: Fix "_zsh_highlight:3: read-only variable: ret" warnings when POSIX_BUILTINS is set.
Fixes #719.

Cf. #688.
2020-04-03 01:19:38 +00:00
Daniel Shahaf
291634ecfe tests: Add a test for the infinite loop fixed by each of the last two commits.
Accidentally lost during a rebase.
2020-04-03 01:04:31 +00:00
Daniel Shahaf
96e6cbe22f 'main': Fix expansion of positional parameters in _zsh_highlight_main_highlighter__try_expand_parameter.
As described in the last commit's log message, ${parameter_name_pattern]
explicitly matches positional parameters but ${parameters[$MATCH]}
expands to nothing in that case (when, e.g., [[ $MATCH == '1' ]]; note
this is equality of strings, not integers).

As a side effect, this removes the dependency on the zsh/parameter
module for expanding parameters.
2020-04-02 23:52:05 +00:00
Daniel Shahaf
2a30d4fb5a 'main': Fix an infinite loop.
On the test case, the behaviour was as follows:

+highlighters/main/main-highlighter.zsh:733> _zsh_highlight_main_highlighter__try_expand_parameter '$1'
+highlighters/main/main-highlighter.zsh:432> local arg='$1'
+highlighters/main/main-highlighter.zsh:433> unset reply
+highlighters/main/main-highlighter.zsh:439> local -a match mbegin mend
+highlighters/main/main-highlighter.zsh:440> local MATCH
+highlighters/main/main-highlighter.zsh:440> integer MBEGIN MEND
+highlighters/main/main-highlighter.zsh:441> local parameter_name
+highlighters/main/main-highlighter.zsh:442> local -a words
+highlighters/main/main-highlighter.zsh:443> [[ '$' != \$ ]]
+highlighters/main/main-highlighter.zsh:446> [[ 1 == { ]]
+highlighters/main/main-highlighter.zsh:449> parameter_name=1
+highlighters/main/main-highlighter.zsh:451> [[ none == none ]]
+highlighters/main/main-highlighter.zsh:451> zmodload -e zsh/parameter
+highlighters/main/main-highlighter.zsh:452> [[ ${parameter_name} -regex-match ^${~parameter_name_pattern}$ ]]
+highlighters/main/main-highlighter.zsh:453> [[ '' != *special* ]]
+highlighters/main/main-highlighter.zsh:456> case array-special (*array*|*assoc*)
+highlighters/main/main-highlighter.zsh:458> words=( '$1' )
+highlighters/main/main-highlighter.zsh:469> reply=( '$1' )

There are two problems here:

- In terms of _zsh_highlight_main_highlighter__try_expand_parameter's
  pre- and postconditions, the expansion of the word «$1» (line 733)
  included that same word (line 469).

  That happened because word-to-be-expanded is passed to
  _zsh_highlight_main_highlighter__try_expand_parameter as its first
  positional parameter, and in this case the word happened to be «$1».

- Furthermore, the exclusion of special parameters (line 453) false
  negatived.  That happened because $parameter_name_pattern explicitly
  allows positional parameters, but ${parameters[(e)1]} expands to
  nothing.  This will be fixed in the next commit.

Not a regression from 0.7.1.
2020-04-02 23:44:11 +00:00
Daniel Shahaf
90fec4d658 'main': precommands += ionice(1) (from util-linux) 2020-04-01 06:38:41 +00:00
Daniel Shahaf
f563780236 driver: Simplify initialization of $zsyh_user_options in the fallback codepath. 2020-03-29 20:54:28 +00:00
Daniel Shahaf
b8c93afd34 driver: Make sure we don't change the return value in a called function. 2020-03-29 20:45:46 +00:00
Daniel Shahaf
2aca4e2c02 'main': Make logic more robust. No functional change.
Before this commit, if the value didn't begin with a dollar sign,
_zsh_highlight_main_highlighter__try_expand_parameter() would return 1
by accident.¹  Tweak the input validation to make this behaviour
explicit.  No functional change.

¹ Specifically, it would return 1 because ${parameter_name}'s value
would be the empty string and ${parameter_name_pattern} wouldn't match
that.
2020-03-28 03:57:13 +00:00
Daniel Shahaf
7678a8a227 'main': Break out an anonymous function into a named function.
This is in order to allow it to be reused.

No functional change.
2020-03-27 01:29:11 +00:00
Daniel Shahaf
5d139fcd94 Fix typos in comments. 2020-03-27 01:28:11 +00:00
Matthew Martin
d1802e388e main: Add test for issue #713 2020-03-22 15:01:53 -05:00