Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Add access to the source bytes of the Tree

Aperta
#180 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
java
Ambito
tooling

Direzione di ricerca

Inizia leggendo Parser#parse e Tree#getText per tracciare come i byte sorgente vengono convertiti e conservati, quindi esamina l’approccio nella pull request #65 precedentemente chiusa. Definisci un percorso di accesso ai byte memorizzati che eviti la copia o la conversione in String, impedendo al contempo le modifiche ai dati interni; il lavoro è completato quando i chiamanti possono usare in sicurezza i byte sorgente dell’albero senza memoria duplicata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
142
Fork
34
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tree-sitter/java-tree-sitter

Tutte le issue di tree-sitter/java-tree-sitter

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.