Add access to the source bytes of the Tree

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
java
領域
tooling

調査の方向性

まず Parser#parse と Tree#getText を読んで、ソースバイトがどのように変換され保持されるかを追跡し、次に以前クローズされた pull request #65 のアプローチを確認します。コピーや String への変換を避けつつ、内部データの編集を防ぐ、保存されたバイトへのアクセス経路を定義してください。完了とは、呼び出し側が重複した保存なしにツリーのソースバイトを安全に使用できることを意味します。

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

説明

Currently when you parse some source code, you can only provide it as a String. The Parser#parse function then converts it to a byte[] before it is passed to tree-sitter. Also, the Tree class only exposes the underlying source code as a String. It stores the content as a byte[]. But every call to Tree#getText converts it to a String.

Those conversion create computational overhead as Java stores its string in UTF-16 while the input encoding for the source code in the byte array can be UTF-8.

In my use case, I parse some text and then want to edit it. I check for some nodes and remove their contents from the text (e.g. by replacing them with whitespace). To avoid those conversions, I currently need to store the input text two times (once in the Tree instance and once separately for the byte level editing). If one could access the byte[] of the tree this could be avoided. I understand, that we do not want the internal byte[] to be edited. Thus one could also expose it as a read only ByteBuffer using ByteBuffer#asReadOnlyBuffer

I proposed a similar change already in https://github.com/tree-sitter/java-tree-sitter/pull/65 but it was closed. In fact, I've been maintaining a private fork of this repo since then, to have the functionality available. I'd really like to have this possibility in the official bindings as I think it could also benefit others.

主要言語
Java
スター
142
フォーク
34
PR マージ指標
30日以内にマージされた PR はありません

環境構築

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

はじめの一歩

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

tree-sitter/java-tree-sitter のほかの issue

tree-sitter/java-tree-sitter の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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