Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions packages/language-javascript/grammars/tree-sitter/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -845,20 +845,33 @@

; The "Foo" in `<Foo />`.
(jsx_self_closing_element
name: (_) @entity.name.tag.js
name: (_) @entity.name.tag.jsx.js
) @meta.tag.jsx.js

; The "Foo" in `<Foo>`.
(jsx_opening_element
name: (_) @entity.name.tag.js)
name: (_) @entity.name.tag.jsx.js)

; The "Foo" in `</Foo>`.
(jsx_closing_element
name: (_) @entity.name.tag.js)
name: (_) @entity.name.tag.jsx.js)

; The "bar" in `<Foo bar={true} />`.
(jsx_attribute
(property_identifier) @entity.other.attribute-name.js)
(property_identifier) @entity.other.attribute-name.jsx.js)

; The "wat:bar" in `<Foo wat:bar={true} />`.
(jsx_attribute
(jsx_namespace_name
(identifier)) @entity.other.attribute-name.namespaced.jsx.js)

; The "wat" in `<Foo wat:bar={true} />`. Worth tagging with its own scope name
; just in case a theme wants to highlight the namespace differently from the
; rest of the attribute.
(jsx_attribute
(jsx_namespace_name
(identifier) @meta.attribute-namespace.jsx.js
(#is-not? test.last)))

; All JSX expressions/interpolations within braces.
((jsx_expression) @meta.embedded.block.jsx.js
Expand Down
1 change: 1 addition & 0 deletions packages/language-javascript/spec/fixtures/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sample.js
10 changes: 10 additions & 0 deletions packages/language-javascript/spec/fixtures/sample.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
/* eslint-disable */
function diff(obj1, obj2, pathConverter) {
// ^ storage.type.function
Expand Down Expand Up @@ -234,3 +235,12 @@ module.exports = diff;
// ^ punctuation.terminator.statement

/* eslint-enable */

function SomeComponent () {
return <Button icon="code" on:click={props.openFile} />;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.jsx.js
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.jsx.inside-tag.js
// ^^^^^^ entity.name.tag.jsx.js
// ^^ meta.attribute-namespace.jsx.js
// ^^^^^^^^ entity.other.attribute-name.namespaced.jsx.js
}
6 changes: 6 additions & 0 deletions packages/language-python/grammars/ts/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
"try"
] @keyword.control.exception._TYPE_.python

("except*" @keyword.control.exception.group-clause.python)

[
"global"
"nonlocal"
Expand Down Expand Up @@ -312,6 +314,10 @@
(identifier) @variable.parameter.function.python))


; The "foo" in `except TypeError as foo:`.
(as_pattern_target
(identifier) @variable.other.exception.python)

; `self` and `cls` are just conventions, but they are _strong_ conventions.
((identifier) @variable.language.self.python
(#eq? @variable.language.self.python "self")
Expand Down
49 changes: 48 additions & 1 deletion packages/language-typescript/grammars/common/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@
; Any other type identifiers; the "Bar" in `const foo: Bar`.
(type_identifier) @support.storage.other.type._LANG_


; SUPPORT
; =======

Expand Down Expand Up @@ -786,7 +787,53 @@
(template_substitution
"${" @punctuation.section.embedded.begin._LANG_
"}" @punctuation.section.embedded.end._LANG_
) @meta.embedded.line.interpolation._LANG_
)

; Scope interpolations with `meta.embedded.line` if they start and end on the
; same line…
((template_substitution) @meta.embedded.line.interpolation._LANG_
(#is? test.startsOnSameRowAs endPosition))

; …or `meta.embedded.block` if they start and end on different lines.
((template_substitution) @meta.embedded.block.interpolation._LANG_
(#is-not? test.startsOnSameRowAs endPosition))


; Template literal types allow you to do string manipulation on values. They're
; basically strings, so let's highlight them that way.
;
; Example:
;
; type World = "world";
; type Greeting = `hello ${World}`;
(template_literal_type) @string.quoted.backtick._LANG_
(template_literal_type "`" @punctuation.delimiter.string.begin._LANG_
(#is? test.first))
(template_literal_type "`" @punctuation.delimiter.string.end._LANG_
(#is? test.last))

; The `template_type` node is used when there's an interpolation within a
; template literal type.
(template_literal_type
(template_type
"${" @punctuation.section.embedded.begin._LANG_
"}" @punctuation.section.embedded.end._LANG_
)
)

; Scope interpolations with `meta.embedded.line` if they start and end on the
; same line…
(template_literal_type
(template_type) @meta.embedded.line.interpolation._LANG_
(#is? test.startsOnSameRowAs endPosition)
)

; …or `meta.embedded.block` if they start and end on different lines.
(template_literal_type
(template_type) @meta.embedded.block.interpolation._LANG_
(#is-not? test.startsOnSameRowAs endPosition)
)


(string
(escape_sequence) @constant.character.escape._LANG_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@
(jsx_attribute
(property_identifier) @entity.other.attribute-name.ts.tsx)

; The "wat:bar" in `<Foo wat:bar={true} />`.
(jsx_attribute
(jsx_namespace_name
(identifier)) @entity.other.attribute-name.namespaced.ts.tsx)

; The "wat" in `<Foo wat:bar={true} />`. Worth tagging with its own scope name
; just in case a theme wants to highlight the namespace differently from the
; rest of the attribute.
(jsx_attribute
(jsx_namespace_name
(identifier) @meta.attribute-namespace.ts.tsx
(#is-not? test.last)))

; All JSX expressions/interpolations within braces.
((jsx_expression) @meta.embedded.block.ts.tsx
(#match? @meta.embedded.block.ts.tsx "\\n")
Expand Down
14 changes: 14 additions & 0 deletions packages/language-typescript/spec/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
env: { jasmine: true },
globals: {
waitsForPromise: true,
runGrammarTests: true,
runFoldsTests: true
},
rules: {
"node/no-unpublished-require": "off",
"node/no-extraneous-require": "off",
"no-unused-vars": "off",
"no-empty": "off"
}
};
2 changes: 2 additions & 0 deletions packages/language-typescript/spec/fixtures/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sample.ts
sample.tsx
14 changes: 14 additions & 0 deletions packages/language-typescript/spec/fixtures/sample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-nocheck
/* eslint-disable */

type World = "world";
// <- storage.type.ts
// ^^^^^ support.storage.other.type.ts
// ^^^^^^^ string.quoted.double.ts


type Greeting = `hello ${World}`;
// ^^^^^^^^^^^^^^^^ string.quoted.backtick.ts
// ^^^^^^^^ meta.embedded.line.interpolation.ts
// ^^ punctuation.section.embedded.begin.ts
// ^ punctuation.section.embedded.end.ts
9 changes: 9 additions & 0 deletions packages/language-typescript/spec/fixtures/sample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-nocheck
function SomeComponent () {
return <Button icon="code" on:click={props.openFile} />;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.ts.tsx
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.jsx.inside-tag.ts.tsx
// ^^^^^^ entity.name.tag.ts.tsx
// ^^ meta.attribute-namespace.ts.tsx
// ^^^^^^^^ entity.other.attribute-name.namespaced.ts.tsx
}
20 changes: 20 additions & 0 deletions packages/language-typescript/spec/tree-sitter-grammar-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const path = require('path');

describe('WASM Tree-sitter TypeScript grammar', () => {

beforeEach(async () => {
await atom.packages.activatePackage('language-typescript');
});

describe('regular grammar', () => {
it('passes grammar tests', async () => {
await runGrammarTests(path.join(__dirname, 'fixtures', 'sample.ts'), /\/\//)
});
});

describe('TSX grammar', () => {
it('passes grammar tests', async () => {
await runGrammarTests(path.join(__dirname, 'fixtures', 'sample.tsx'), /\/\//)
});
});
});
21 changes: 19 additions & 2 deletions src/wasm-tree-sitter-language-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5256,9 +5256,26 @@ class IndentResolver {
//
// Use the position of the first text on the line as the reference point.
let rowStartingColumn = Math.max(line.search(/\S/), 0);
let rowStartingPoint = new Point(row, rowStartingColumn)
let controllingLayer = languageMode.controllingLayerAtPoint(
new Point(row, rowStartingColumn),
(layer) => !!layer.queries.indentsQuery
rowStartingPoint,
(layer) => {
if (!layer.queries.indentsQuery) return false;
// We're using the same logic here that we used in the dedent phase of
// `suggestedIndentForBufferRow`: allow layers that _begin_ at the
// cursor, but exclude layers that _end_ at the cursor.
//
// So first we test for containment exclusive of endpoints…
if (layer.containsPoint(rowStartingPoint, true)) {
return true;
}

// …but we'll still accept layers that have a content range which
// _starts_ at the cursor position.
return layer.getCurrentRanges()?.some(r => {
return r.start.compare(rowStartingPoint) === 0;
});
}
);

if (!controllingLayer) { return undefined; }
Expand Down
Loading