mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge pull request #21753 from atom/mb-fix-tree-sitter-injection
Fix handling of "empty" language injections with Tree-sitter
This commit is contained in:
@@ -32,7 +32,7 @@ class TreeSitterLanguageMode {
|
||||
this.config = config;
|
||||
this.grammarRegistry = grammars;
|
||||
this.parser = new Parser();
|
||||
this.rootLanguageLayer = new LanguageLayer(this, grammar, 0);
|
||||
this.rootLanguageLayer = new LanguageLayer(null, this, grammar, 0);
|
||||
this.injectionsMarkerLayer = buffer.addMarkerLayer();
|
||||
|
||||
if (syncTimeoutMicros != null) {
|
||||
@@ -637,7 +637,8 @@ class TreeSitterLanguageMode {
|
||||
}
|
||||
|
||||
class LanguageLayer {
|
||||
constructor(languageMode, grammar, depth) {
|
||||
constructor(marker, languageMode, grammar, depth) {
|
||||
this.marker = marker;
|
||||
this.languageMode = languageMode;
|
||||
this.grammar = grammar;
|
||||
this.tree = null;
|
||||
@@ -687,10 +688,12 @@ class LanguageLayer {
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.tree = null;
|
||||
this.destroyed = true;
|
||||
this.marker.destroy();
|
||||
for (const marker of this.languageMode.injectionsMarkerLayer.getMarkers()) {
|
||||
if (marker.parentLanguageLayer === this) {
|
||||
marker.languageLayer.destroy();
|
||||
marker.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -726,8 +729,9 @@ class LanguageLayer {
|
||||
if (nodeRangeSet) {
|
||||
includedRanges = nodeRangeSet.getRanges(this.languageMode.buffer);
|
||||
if (includedRanges.length === 0) {
|
||||
this.tree = null;
|
||||
this.destroyed = true;
|
||||
const range = this.marker.getRange();
|
||||
this.destroy();
|
||||
this.languageMode.emitRangeUpdate(range);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -883,6 +887,7 @@ class LanguageLayer {
|
||||
injectionRange
|
||||
);
|
||||
marker.languageLayer = new LanguageLayer(
|
||||
marker,
|
||||
this.languageMode,
|
||||
grammar,
|
||||
this.depth + 1
|
||||
@@ -904,9 +909,8 @@ class LanguageLayer {
|
||||
|
||||
for (const marker of existingInjectionMarkers) {
|
||||
if (!markersToUpdate.has(marker)) {
|
||||
marker.languageLayer.destroy();
|
||||
this.languageMode.emitRangeUpdate(marker.getRange());
|
||||
marker.destroy();
|
||||
marker.languageLayer.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1335,7 +1339,7 @@ class NodeCursorAdaptor {
|
||||
|
||||
class NullHighlightIterator {
|
||||
seek() {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
compare() {
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user