Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function highlightTreeSitter fails to markup long code #44

Open
ayame113 opened this issue Apr 19, 2021 · 0 comments
Open

Function highlightTreeSitter fails to markup long code #44

ayame113 opened this issue Apr 19, 2021 · 0 comments

Comments

@ayame113
Copy link

ayame113 commented Apr 19, 2021

Execution was success:

await highlightTreeSitter(`function () {console.log()}\n`.repeat(30), 'source.js')
<span class="syntax--source syntax--js"><span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span><span class="syntax--support syntax--variable syntax--dom">console</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">log</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span>
...
<span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span><span class="syntax--support syntax--variable syntax--dom">console</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">log</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span>
</span>

Randomly fail:

await highlightTreeSitter(`function () {console.log()}\n`.repeat(80), 'source.js')

Completely fail:

await highlightTreeSitter(`function () {console.log()}\n`.repeat(120), 'source.js')
<span class="syntax--source syntax--js">function () {console.log()}
function () {console.log()}
...
function () {console.log()}
</span>

As far as I've tested locally, adding something like await delay (100) after buf.setText (sourceCode) in the implementation seems to work as expected.

buf.setLanguageMode(lm)
buf.setText(sourceCode)
const end = buf.getEndPosition()

const delay = ms => new Promise(resolve=>setTimeout(resolve, ms))
    buf.setLanguageMode(lm)
    buf.setText(sourceCode)
    await delay(100) // <- add this line
    const end = buf.getEndPosition()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant