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

Tree-sitter rolling fixes, 1.120 edition #1062

Merged
merged 8 commits into from
Aug 16, 2024
53 changes: 53 additions & 0 deletions spec/wasm-tree-sitter-language-mode-spec.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(re 4388bce)

Specs are appreciated! 👍

Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,59 @@ describe('WASMTreeSitterLanguageMode', () => {
]);
});

describe('when a highlighting query changes after load', () => {
it('updates the highlighting to reflect the new content', async () => {
jasmine.useRealClock();
const grammar = new WASMTreeSitterGrammar(atom.grammars, jsGrammarPath, jsConfig);

await grammar.setQueryForTest('highlightsQuery', scm`
(identifier) @variable
`);

buffer.setText('abc;');

const languageMode = new WASMTreeSitterLanguageMode({
buffer,
grammar
});
buffer.setLanguageMode(languageMode);
await languageMode.ready;
await wait(0);

expectTokensToEqual(editor, [
[
{ text: 'abc', scopes: ['variable'] },
{ text: ';', scopes: [] }
]
]);

// Set up a promise that resolves when highlighting updates after a
// query change.
let highlightingDidUpdate = new Promise((resolve) => {
let disposable = languageMode.onDidChangeHighlighting(
() => {
disposable.dispose();
resolve();
}
)
});

// Change the highlighting query.
await grammar.setQueryForTest('highlightsQuery', scm`
(identifier) @constant
`);
await highlightingDidUpdate;

// The language mode should automatically reload the query.
expectTokensToEqual(editor, [
[
{ text: 'abc', scopes: ['constant'] },
{ text: ';', scopes: [] }
]
]);
});
});

// TODO: Ignoring these specs because web-tree-sitter doesn't seem to do
// async. We can rehabilitate them if we ever figure it out.
xdescribe('when the buffer changes during a parse', () => {
Expand Down