Skip to content

Commit b3b5cac

Browse files
authored
Merge pull request #87 from atom-ide-community/upstream_master
2 parents 022ae82 + b4909a9 commit b3b5cac

File tree

6 files changed

+75
-9
lines changed

6 files changed

+75
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "atom",
33
"productName": "Atom",
4-
"version": "1.51.0-dev",
4+
"version": "1.52.0-dev",
55
"description": "A hackable text editor for the 21st Century.",
66
"main": "./src/main-process/main.js",
77
"repository": {
@@ -97,7 +97,7 @@
9797
"language-mustache": "https://www.atom.io/api/packages/language-mustache/versions/0.14.5/tarball",
9898
"language-objective-c": "https://www.atom.io/api/packages/language-objective-c/versions/0.16.0/tarball",
9999
"language-perl": "https://www.atom.io/api/packages/language-perl/versions/0.38.1/tarball",
100-
"language-php": "https://www.atom.io/api/packages/language-php/versions/0.44.5/tarball",
100+
"language-php": "https://www.atom.io/api/packages/language-php/versions/0.44.6/tarball",
101101
"language-property-list": "https://www.atom.io/api/packages/language-property-list/versions/0.9.1/tarball",
102102
"language-python": "https://www.atom.io/api/packages/language-python/versions/0.53.4/tarball",
103103
"language-ruby": "https://www.atom.io/api/packages/language-ruby/versions/0.72.23/tarball",
@@ -249,7 +249,7 @@
249249
"language-mustache": "0.14.5",
250250
"language-objective-c": "0.16.0",
251251
"language-perl": "0.38.1",
252-
"language-php": "0.44.5",
252+
"language-php": "0.44.6",
253253
"language-property-list": "0.9.1",
254254
"language-python": "0.53.4",
255255
"language-ruby": "0.72.23",

script/test

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,24 @@ const CONFIG = require('./config')
4545
const backupNodeModules = require('./lib/backup-node-modules')
4646
const runApmInstall = require('./lib/run-apm-install')
4747

48+
function assertExecutablePaths(executablePaths) {
49+
assert(executablePaths.length !== 0, `No atom build found. Please run "script/build" and try again.`)
50+
assert(executablePaths.length === 1, `More than one application to run tests against was found. ${executablePaths.join(',')}`)
51+
}
52+
4853
const resourcePath = CONFIG.repositoryRootPath
4954
let executablePath
5055
if (process.platform === 'darwin') {
5156
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, '*.app'))
52-
assert(executablePaths.length === 1, `A single application to run tests against was not found. ${executablePaths.join(',')}`)
57+
assertExecutablePaths(executablePaths)
5358
executablePath = path.join(executablePaths[0], 'Contents', 'MacOS', path.basename(executablePaths[0], '.app'))
5459
} else if (process.platform === 'linux') {
5560
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, 'atom-*', 'atom'))
56-
assert(executablePaths.length === 1, `A single application to run tests against was not found. ${executablePaths.join(',')}`)
61+
assertExecutablePaths(executablePaths)
5762
executablePath = executablePaths[0]
5863
} else if (process.platform === 'win32') {
5964
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, '**', 'atom*.exe'))
60-
assert(executablePaths.length === 1, `A single application to run tests against was not found. ${executablePaths.join(',')}`)
65+
assertExecutablePaths(executablePaths)
6166
executablePath = executablePaths[0]
6267
} else {
6368
throw new Error('##[error] Running tests on this platform is not supported.')

spec/tree-sitter-language-mode-spec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,58 @@ describe('TreeSitterLanguageMode', () => {
7373
]);
7474
});
7575

76+
it('provides the grammar with the text of leaf nodes only', async () => {
77+
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
78+
parser: 'tree-sitter-javascript',
79+
scopes: {
80+
program: 'source',
81+
'call_expression > identifier': 'function',
82+
property_identifier: 'property',
83+
'call_expression > member_expression > property_identifier': 'method'
84+
}
85+
});
86+
const original = grammar.idForScope.bind(grammar);
87+
let tokens = [];
88+
grammar.idForScope = function(scope, text) {
89+
if (text && tokens[tokens.length - 1] !== text) {
90+
tokens.push(text);
91+
}
92+
return original(scope, text);
93+
};
94+
95+
buffer.setText('aa.bbb = cc(d.eee());');
96+
97+
const languageMode = new TreeSitterLanguageMode({ buffer, grammar });
98+
buffer.setLanguageMode(languageMode);
99+
100+
expectTokensToEqual(editor, [
101+
[
102+
{ text: 'aa.', scopes: ['source'] },
103+
{ text: 'bbb', scopes: ['source', 'property'] },
104+
{ text: ' = ', scopes: ['source'] },
105+
{ text: 'cc', scopes: ['source', 'function'] },
106+
{ text: '(d.', scopes: ['source'] },
107+
{ text: 'eee', scopes: ['source', 'method'] },
108+
{ text: '());', scopes: ['source'] }
109+
]
110+
]);
111+
112+
expect(tokens).toEqual([
113+
'aa',
114+
'.',
115+
'bbb',
116+
'=',
117+
'cc',
118+
'(',
119+
'd',
120+
'.',
121+
'eee',
122+
'(',
123+
')',
124+
';'
125+
]);
126+
});
127+
76128
it('can start or end multiple scopes at the same position', async () => {
77129
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
78130
parser: 'tree-sitter-javascript',

src/tree-sitter-grammar.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ module.exports = class TreeSitterGrammar {
7171
}
7272

7373
idForScope(scopeName) {
74+
if (!scopeName) {
75+
return undefined;
76+
}
7477
let id = this.idsByScope[scopeName];
7578
if (!id) {
7679
id = this.nextScopeId += 2;

src/tree-sitter-language-mode.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,13 @@ class LayerHighlightIterator {
12921292
this.treeCursor.nodeIsNamed
12931293
);
12941294
const scopeName = applyLeafRules(value, this.treeCursor);
1295-
if (scopeName) {
1295+
const node = this.treeCursor.currentNode;
1296+
if (!node.childCount) {
1297+
return this.languageLayer.languageMode.grammar.idForScope(
1298+
scopeName,
1299+
node.text
1300+
);
1301+
} else if (scopeName) {
12961302
return this.languageLayer.languageMode.grammar.idForScope(scopeName);
12971303
}
12981304
}

0 commit comments

Comments
 (0)