zsh-syntax-highlighting icon indicating copy to clipboard operation
zsh-syntax-highlighting copied to clipboard

Highlight precommands and correct expansions order

Open danielshahaf opened this issue 7 years ago • 10 comments

This is i343-precommands-v2, but rebased, and with an extra commit about ${foo} parameter expansions.

Related to #264, #328, #343, #168, #365 (see log messages and added comments).

danielshahaf avatar Dec 25 '17 05:12 danielshahaf

Tests pass locally.

danielshahaf avatar Dec 25 '17 08:12 danielshahaf

Haven't had a chance to figure out why but when on this branch

% zsh -f
% . ./zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 
% alias a=b
% : 'azsh-syntax-highlighting: BUG: _zsh_highlight_main_highlighter_expand_path: called without argument
'a'

That last line is typing : 'a'.

phy1729 avatar Jan 11 '18 23:01 phy1729

Note to self: audit for null argument elision.

danielshahaf avatar Jan 12 '18 02:01 danielshahaf

The problem is here:

https://github.com/danielshahaf/zsh-syntax-highlighting/blob/e9ab802593ebbfce5cf749b1854d2cc201b3aa68/highlighters/main/main-highlighter.zsh#L471-L482

$arg starts out as 'a' (three characters), then _zsh_highlight_main_highlighter_expand_path dequotes, _zsh_highlight_main__type returns alias, and _zsh_highlight_main__resolve_alias doesn't find an alias named 'a' (there's only an a alias) and returns an empty string, which is elided in _zsh_highlight_main_highlighter_check_path at https://github.com/danielshahaf/zsh-syntax-highlighting/blob/e9ab802593ebbfce5cf749b1854d2cc201b3aa68/highlighters/main/main-highlighter.zsh#L850-L852 .

The breakage is that alias lookup should be done on the non-dequoted argument. Not sure how to fix (ideas?).

Good catch!

danielshahaf avatar Jan 12 '18 14:01 danielshahaf

Filed #479 which would affect the failure mode of this.

danielshahaf avatar Jan 12 '18 14:01 danielshahaf

Remaining tasks:

  • [ ] Resolve all review comments
  • [ ] Update changelog
  • [ ] Fix trailing whitespace
  • [ ] alias a=b; : 'a' issue above, compare #479
  • [ ] Tests fail under zsh<5.1 # alias-comment1 1..1 not ok 1 - [1,1] «x» - expected "alias", observed "unknown-token". # TODO 'interactivecomments applies to aliases'

danielshahaf avatar Jan 12 '18 15:01 danielshahaf

Tests fail under zsh<5.1

Testing interactively in zsh-4.3.17, I get the expected output from running x, namely, pwd gets executed. So the test's expectations are correct for those old versions too. I don't immediately see the cause for the failure under 5.0.8.

danielshahaf avatar Jan 12 '18 15:01 danielshahaf

Need precommand_options[nice]+=':'

(Can't add it as a review comment)

edit: Done in 06ae6f9

danielshahaf avatar Jan 13 '18 05:01 danielshahaf

Left:

  • Address https://github.com/zsh-users/zsh-syntax-highlighting/pull/471#issuecomment-357249607 - alias lookup should only be done if it's either a global alias or at command word position
  • Address https://github.com/zsh-users/zsh-syntax-highlighting/pull/471#discussion_r161374006
  • Resolve conflicts
  • Merge
  • Address https://github.com/zsh-users/zsh-syntax-highlighting/pull/471#discussion_r161105273

danielshahaf avatar Jan 28 '18 21:01 danielshahaf

Triage: Incomplete; deferred ☹

danielshahaf avatar May 22 '20 04:05 danielshahaf