lacygoill / vim9-syntax

16 stars 1 forks source link

Syntax is broken when CompilerSet contains line continuations #5

Closed bfrg closed 2 years ago

bfrg commented 2 years ago

errorformat can be quite long. So I often split it across multiple lines. I've noticed that this isn't supported yet.

Example:

vim9script

CompilerSet errorformat=
        \%D%*\\a[%*\\d]:\ Entering\ directory\ %*[`']%f',
        \%X%*\\a[%*\\d]:\ Leaving\ directory\ %*[`']%f',
        \%D%*\\a:\ Entering\ directory\ %*[`']%f',
        \%X%*\\a:\ Leaving\ directory\ %*[`']%f'

screenshot-2022-10-03_002039

lacygoill commented 2 years ago

I tried to fix the issue in these commits:

But it breaks this snippet:

vim9script
setlocal foldexpr=getline(v:lnum)=~'^#'?'>1':'='
ls

ls should be highlighted as a command; instead it's highlighted as an option.

Not sure how to fix this at the moment. If you have an idea, let me know. Although, the code is already quite complex. Not sure I want to add more complexity. FWIW, I try to avoid explicit line continuations as much as possible. For example, here, I would re-write the code like this:

vim9script
var value: list<string> =<< trim END
    %D%*\a[%*\d]: Entering directory %*[`']%f'
    %X%*\a[%*\d]: Leaving directory %*[`']%f'
    %D%*\a: Entering directory %*[`']%f'
    %X%*\a: Leaving directory %*[`']%f'
END
$'CompilerSet errorformat={value->join(',')}'->execute()

As a benefit, there is no need to double the backslashes, nor to escape the spaces, which makes the value easier to read and maintain. Here, I doubt the execute() makes a significant difference performance-wise.

What could also help is a compilerset() function which would work as a replacement for :CompilerSet. In a function call, it's easier to split and format a long string expression. Or maybe a more general setoption() function, which would accept some argument to let it work as a replacement for :CompilerSet, in addition to :set, :setlocal, :setglobal.

lacygoill commented 2 years ago

But it breaks this snippet:

Which is why I had to revert the commits.

bfrg commented 2 years ago

Thank you for doing this. I tried something similar before opening this issue and encountered the exact same problem. I didn't have time to go through the entire syntax file. I'll take a look at it again when I have more time.

The heredoc is a good alternative.