mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 19:17:09 +03:00
Give onlyIf(Not)Type
ability…
…to accept multiple node types.
This commit is contained in:
parent
ef90e16bda
commit
31f67b9fd6
@ -659,6 +659,24 @@ describe('ScopeResolver', () => {
|
||||
})).toBe(true);
|
||||
});
|
||||
|
||||
it('supports onlyIfType with multiple types', async () => {
|
||||
await grammar.setQueryForTest('highlightsQuery', `
|
||||
(formal_parameters _ @thing
|
||||
(#set! test.onlyIfType ", identifier"))
|
||||
`);
|
||||
|
||||
const languageMode = new WASMTreeSitterLanguageMode({ grammar, buffer });
|
||||
buffer.setLanguageMode(languageMode);
|
||||
buffer.setText(dedent`
|
||||
function foo (bar, baz, thud) {}
|
||||
`);
|
||||
await languageMode.ready;
|
||||
|
||||
let matched = await getAllMatches(grammar, languageMode);
|
||||
|
||||
expect(matched.length).toBe(5);
|
||||
});
|
||||
|
||||
it('supports onlyIfHasError', async () => {
|
||||
await grammar.setQueryForTest('highlightsQuery', `
|
||||
((statement_block) @messed-up-statement-block
|
||||
|
@ -436,14 +436,18 @@ ScopeResolver.TESTS = {
|
||||
return existingData === undefined;
|
||||
},
|
||||
|
||||
// Passes only if the node is of the given type.
|
||||
// Passes only if the node is of the given type. Can accept multiple
|
||||
// space-separated types.
|
||||
onlyIfType(node, nodeType) {
|
||||
return node.type === nodeType;
|
||||
if (!nodeType.includes(' ')) { return node.type === nodeType }
|
||||
let nodeTypes = nodeType.split(/\s+/);
|
||||
return nodeTypes.some(t => t === node.type);
|
||||
},
|
||||
|
||||
// Negates `onlyIfType`.
|
||||
onlyIfNotType(node, nodeType) {
|
||||
return node.type !== nodeType;
|
||||
onlyIfNotType(...args) {
|
||||
let isType = ScopeResolver.TESTS.onlyIfType(...args);
|
||||
return !isType;
|
||||
},
|
||||
|
||||
// Passes only if the node contains any descendant ERROR nodes.
|
||||
|
Loading…
Reference in New Issue
Block a user