mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 07:28:08 +03:00
Merge pull request #20212 from sharedprophet/support-semanticolor
Support semanticolor
This commit is contained in:
commit
212081ea45
3
script/package-lock.json
generated
3
script/package-lock.json
generated
@ -1265,8 +1265,7 @@
|
||||
"boolean": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/boolean/-/boolean-3.0.1.tgz",
|
||||
"integrity": "sha512-HRZPIjPcbwAVQvOTxR4YE3o8Xs98NqbbL1iEZDCz7CL8ql0Lt5iOyJFxfnAB0oFs8Oh02F/lLlg30Mexv46LjA==",
|
||||
"optional": true
|
||||
"integrity": "sha512-HRZPIjPcbwAVQvOTxR4YE3o8Xs98NqbbL1iEZDCz7CL8ql0Lt5iOyJFxfnAB0oFs8Oh02F/lLlg30Mexv46LjA=="
|
||||
},
|
||||
"boxen": {
|
||||
"version": "1.3.0",
|
||||
|
@ -73,6 +73,58 @@ describe('TreeSitterLanguageMode', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('provides the grammar with the text of leaf nodes only', async () => {
|
||||
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
|
||||
parser: 'tree-sitter-javascript',
|
||||
scopes: {
|
||||
program: 'source',
|
||||
'call_expression > identifier': 'function',
|
||||
property_identifier: 'property',
|
||||
'call_expression > member_expression > property_identifier': 'method'
|
||||
}
|
||||
});
|
||||
const original = grammar.idForScope.bind(grammar);
|
||||
let tokens = [];
|
||||
grammar.idForScope = function(scope, text) {
|
||||
if (text && tokens[tokens.length - 1] !== text) {
|
||||
tokens.push(text);
|
||||
}
|
||||
return original(scope, text);
|
||||
};
|
||||
|
||||
buffer.setText('aa.bbb = cc(d.eee());');
|
||||
|
||||
const languageMode = new TreeSitterLanguageMode({ buffer, grammar });
|
||||
buffer.setLanguageMode(languageMode);
|
||||
|
||||
expectTokensToEqual(editor, [
|
||||
[
|
||||
{ text: 'aa.', scopes: ['source'] },
|
||||
{ text: 'bbb', scopes: ['source', 'property'] },
|
||||
{ text: ' = ', scopes: ['source'] },
|
||||
{ text: 'cc', scopes: ['source', 'function'] },
|
||||
{ text: '(d.', scopes: ['source'] },
|
||||
{ text: 'eee', scopes: ['source', 'method'] },
|
||||
{ text: '());', scopes: ['source'] }
|
||||
]
|
||||
]);
|
||||
|
||||
expect(tokens).toEqual([
|
||||
'aa',
|
||||
'.',
|
||||
'bbb',
|
||||
'=',
|
||||
'cc',
|
||||
'(',
|
||||
'd',
|
||||
'.',
|
||||
'eee',
|
||||
'(',
|
||||
')',
|
||||
';'
|
||||
]);
|
||||
});
|
||||
|
||||
it('can start or end multiple scopes at the same position', async () => {
|
||||
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
|
||||
parser: 'tree-sitter-javascript',
|
||||
|
@ -71,6 +71,9 @@ module.exports = class TreeSitterGrammar {
|
||||
}
|
||||
|
||||
idForScope(scopeName) {
|
||||
if (!scopeName) {
|
||||
return undefined;
|
||||
}
|
||||
let id = this.idsByScope[scopeName];
|
||||
if (!id) {
|
||||
id = this.nextScopeId += 2;
|
||||
|
@ -1292,7 +1292,13 @@ class LayerHighlightIterator {
|
||||
this.treeCursor.nodeIsNamed
|
||||
);
|
||||
const scopeName = applyLeafRules(value, this.treeCursor);
|
||||
if (scopeName) {
|
||||
const node = this.treeCursor.currentNode;
|
||||
if (!node.childCount) {
|
||||
return this.languageLayer.languageMode.grammar.idForScope(
|
||||
scopeName,
|
||||
node.text
|
||||
);
|
||||
} else if (scopeName) {
|
||||
return this.languageLayer.languageMode.grammar.idForScope(scopeName);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user