Region strings' syntax highlighting is broken when they're defined as part of another region themselves

オープン
#4,148 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go, php, yaml
領域
cli, tooling

調査の方向性

~/.config/micro/syntax/php.yaml とネストされたリージョンの例で問題を再現し、提供された PHP スニペットを使って constant.string の正規表現形式と比較します。Micro がネストされたリージョン内でどのようにルールを適用するかを追跡し、外側の属性リージョンが閉じるまで、文字列が境界と優先順位を維持することを確認します。

索引モデルが issue の本文から書いたものです。

説明

bug triage
Description

I was attempting to do something like the following to add syntax highlighting for PHP's attributes:

# ~/.config/micro/syntax/php.yaml

# Other rules above
- special:
    start: "#\\["
    end: "\\]"
    rules:
        - constant.string:
            start: "'"
            end: "'"
            skip: "\\\\."
# Other rules below

When defined as a above, attributes themselves will be highlighted properly in a PHP file (when placed above the one-line comment definition), but if the attribute contains a string, the string will only be highlighted properly until it matches any other rule in the file, even if it's not defined within the string region itself, as well as the closing quotation mark. For example, in the following code:

#[SomeAttribute('A very !long string *here with /some +symbols')]

Since the exclamation mark character is defined in another, unrelated rule as an operator in the same file, Micro will only highlight the initial 'A very ! and the final ' as a string. The text in between will be highlighted as regular text, following rules defined outside of the attribute region, even before it in the file (when the colors help file states that rules further down in the file should have more priority than rules above them). So string will be highlighted as a type, and *, / and + will be highlighted as operators.

I have tried the same with other region rule definitions, and it seems to be a generalized problem for strings defined as regions within regions. Perhaps other rule definitions besides strings would suffer from this problem. It's worth testing further.

It is worth noting that changing the above YAML configuration to the following does not have this effect:

# ~/.config/micro/syntax/php.yaml

# Other rules above
- special:
    start: "#\\["
    end: "\\]"
    rules:
        - constant.string: "'.*?'"
# Other rules below

The code above doesn't present the same problem, and in this case, strings will only be overwritten based on rules defined below them as part of the same attribute region.

Environment
  • Version: 2.0.13
  • OS: Linux Mint 22.3
  • Terminal: GNOME Terminal
主要言語
Go
スター
29.8k
フォーク
1.4k
平均マージ
1日 12時間
マージ済み PR(30日)
2

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

micro-editor/micro のほかの issue

micro-editor/micro の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。