GDQuest / GDQuest/GDScript-formatter

Preserve two empty lines when function is commented out

オープン
#208 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
455
フォーク
39
平均マージ
1日 15時間
マージ済み PR(30日)
4

説明

When you comment out a function in between or after a function, the formatter unnecessarily removes empty lines. Here is an example:

Before:

```gdscript
func f(x: float) -> float:
return x

func g(x: float) -> float:
return x

func h(x: float) -> float:
return x
```

After commenting out middle function:

```gdscript
func f(x: float) -> float:
return x

# func g(x: float) -> float:
# return x

func h(x: float) -> float:
return x
```
---

This violates the official style guide which says:

> **Surround** functions and class definitions with two blank lines

This also annoyingly bobs functions up and down as you temporarily comment them out, which is not ideal. I assume the problem here is that the formatter treats commented sections following a function as part of the function itself, and thus tries to use a single empty line.

At least on VSCode, comments made with `CTRL + /` respect the indent level of the commented code. So, it should be possible to detect whether a comment is part of the function or part of a codeblock outside the function using the indent level. However, I am not sure if this convention is universal.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

issue の GDScript 例を使って formatter の動作を再現し、その後、関数の境界付近でコメント、インデント、空行がどのように扱われるかを追跡します。formatter がコメントアウトされた関数本体と関数間のコメントを区別しているか確認します。コメントアウトされた関数の前後に 2 行の空行を保持し、それ以外では既存のフォーマット動作を維持できれば完了です。

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

評価

技術スタック
rust
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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