Skip to content

Commit

Permalink
injections
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Sep 17, 2023
1 parent ef67f18 commit d6a65e2
Show file tree
Hide file tree
Showing 23 changed files with 445 additions and 150 deletions.
26 changes: 3 additions & 23 deletions atom/src/bracket-matcher-view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "text-editor.h"
#include "selection.h"
#include "tree-sitter-language-mode.h"
#include <tree-sitter.h>
#include <display-marker.h>
#include <cstring>

Expand Down Expand Up @@ -99,27 +100,6 @@ optional<Point> BracketMatcherView::findMatchingStartBracket(Point endBracketPos
}
}

static Point PointToJS(TSPoint point) {
return Point(point.row, point.column / 2);
}
static Point startPosition(TSNode node) {
return PointToJS(ts_node_start_point(node));
}
static Point endPosition(TSNode node) {
return PointToJS(ts_node_end_point(node));
}
static std::vector<TSNode> children(TSNode node) {
static TSTreeCursor scratch_cursor = {nullptr, nullptr, {0, 0}};
std::vector<TSNode> result;
ts_tree_cursor_reset(&scratch_cursor, node);
if (ts_tree_cursor_goto_first_child(&scratch_cursor)) {
do {
TSNode child = ts_tree_cursor_current_node(&scratch_cursor);
result.push_back(child);
} while (ts_tree_cursor_goto_next_sibling(&scratch_cursor));
}
return result;
}
static TSNode ts_node_first_child(TSNode node) {
return ts_node_child(node, 0);
}
Expand All @@ -142,7 +122,7 @@ optional<Point> BracketMatcherView::findMatchingEndBracketWithSyntaxTree(Point b
auto matchNode = std::find_if(children.begin(), children.end(), [&](TSNode child) {
return bracketEndPosition.isLessThanOrEqual(startPosition(child)) && ts_node_type(child)[0] == endBracket;
});
if (matchNode != children.end()) result = startPosition(*matchNode);
if (matchNode != children.end()) result = Point(startPosition(*matchNode));
return true;
}
return false;
Expand All @@ -162,7 +142,7 @@ optional<Point> BracketMatcherView::findMatchingStartBracketWithSyntaxTree(Point
auto matchNode = std::find_if(children.begin(), children.end(), [&](TSNode child) {
return bracketPosition.isGreaterThanOrEqual(endPosition(child)) && ts_node_type(child)[0] == startBracket;
});
if (matchNode != children.end()) result = startPosition(*matchNode);
if (matchNode != children.end()) result = Point(startPosition(*matchNode));
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion atom/src/grammar-registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void GrammarRegistry::autoAssignLanguageMode(TextBuffer *buffer) {
}

LanguageMode *GrammarRegistry::languageModeForGrammarAndBuffer(Grammar *grammar, TextBuffer *buffer) {
return grammar->getLanguageMode(buffer);
return grammar->getLanguageMode(buffer, this);
}

/*selectGrammar(filePath, fileContents) {
Expand Down
3 changes: 2 additions & 1 deletion atom/src/grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

struct LanguageMode;
struct TextBuffer;
struct GrammarRegistry;

struct Grammar {
const char *name;
Expand All @@ -23,7 +24,7 @@ struct Grammar {
template <typename... T> void setFileTypes(T&&... t) {
addFileTypes(std::forward<T>(t)...);
}
virtual LanguageMode *getLanguageMode(TextBuffer *) = 0;
virtual LanguageMode *getLanguageMode(TextBuffer *, GrammarRegistry *) = 0;
};

#endif // GRAMMAR_H_
2 changes: 1 addition & 1 deletion atom/src/null-grammar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ NullGrammar::NullGrammar() : Grammar("Null Grammar", "text.plain.null-grammar")

NullGrammar::~NullGrammar() {}

LanguageMode *NullGrammar::getLanguageMode(TextBuffer *) {
LanguageMode *NullGrammar::getLanguageMode(TextBuffer *, GrammarRegistry *) {
return new TextMateLanguageMode(this);
}
2 changes: 1 addition & 1 deletion atom/src/null-grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct NullGrammar final : Grammar {
NullGrammar();
~NullGrammar();

LanguageMode *getLanguageMode(TextBuffer *) override;
LanguageMode *getLanguageMode(TextBuffer *, GrammarRegistry *) override;
};

#endif // NULL_GRAMMAR_H_
4 changes: 2 additions & 2 deletions atom/src/tree-sitter-grammar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ std::string TreeSitterGrammar::classNameForScopeId(int32_t id) {
return this->classNamesById[id];
}

LanguageMode *TreeSitterGrammar::getLanguageMode(TextBuffer *buffer) {
return new TreeSitterLanguageMode(buffer, this);
LanguageMode *TreeSitterGrammar::getLanguageMode(TextBuffer *buffer, GrammarRegistry *grammars) {
return new TreeSitterLanguageMode(buffer, this, grammars);
}
2 changes: 1 addition & 1 deletion atom/src/tree-sitter-grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct TreeSitterGrammar final : Grammar {
}
optional<int32_t> idForScope(const optional<std::string> &);
std::string classNameForScopeId(int32_t);
LanguageMode *getLanguageMode(TextBuffer *) override;
LanguageMode *getLanguageMode(TextBuffer *, GrammarRegistry *) override;
};

#endif // TREE_SITTER_GRAMMAR_H_
Loading

0 comments on commit d6a65e2

Please sign in to comment.