mirror of https://github.com/AMT-Cheif/drift.git
Support moor file AST in the plugin
This commit is contained in:
parent
1b7721a98f
commit
a5cecd3ba6
|
@ -20,6 +20,20 @@ class _FoldingVisitor extends RecursiveVisitor<void> {
|
|||
|
||||
_FoldingVisitor(this.collector);
|
||||
|
||||
@override
|
||||
void visitMoorFile(MoorFile e) {
|
||||
// construct a folding region for import statements
|
||||
final imports = e.imports.toList();
|
||||
if (imports.isNotEmpty) {
|
||||
final first = imports.first.firstPosition;
|
||||
final last = imports.last.lastPosition;
|
||||
|
||||
collector.addRegion(first, last - first, FoldingKind.DIRECTIVES);
|
||||
}
|
||||
|
||||
super.visitChildren(e);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitCreateTableStatement(CreateTableStatement e) {
|
||||
final startBody = e.openingBracket;
|
||||
|
|
|
@ -21,7 +21,7 @@ class MoorHighlightContributor implements HighlightsContributor {
|
|||
result.parsedFile.accept(visitor);
|
||||
|
||||
for (var token in result.parseResult.tokens) {
|
||||
if (token is KeywordToken) {
|
||||
if (token is KeywordToken && !token.isIdentifier) {
|
||||
final start = token.span.start.offset;
|
||||
final length = token.span.length;
|
||||
collector.addRegion(start, length, HighlightRegionType.BUILT_IN);
|
||||
|
|
|
@ -11,16 +11,9 @@ class MoorOutlineContributor implements OutlineContributor {
|
|||
@override
|
||||
void computeOutline(OutlineRequest request, OutlineCollector collector) {
|
||||
final moorRequest = request as MoorRequest;
|
||||
final file = moorRequest.path;
|
||||
|
||||
final libraryElement = Element(ElementKind.FILE, file, _defaultFlags);
|
||||
collector.startElement(
|
||||
libraryElement, 0, moorRequest.resolvedTask.content.length);
|
||||
|
||||
final visitor = _OutlineVisitor(collector);
|
||||
moorRequest.resolvedTask.lastResult.parsedFile.accept(visitor);
|
||||
|
||||
collector.endElement();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +41,14 @@ class _OutlineVisitor extends RecursiveVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitColumnDefinition(ColumnDefinition e) {
|
||||
_startElement(ElementKind.FIELD, e.columnName, e);
|
||||
_startElement(ElementKind.FIELD, e.columnName, e)..returnType = e.typeName;
|
||||
super.visitChildren(e);
|
||||
collector.endElement();
|
||||
}
|
||||
|
||||
@override
|
||||
void visitMoorDeclaredStatement(DeclaredStatement e) {
|
||||
_startElement(ElementKind.TOP_LEVEL_VARIABLE, e.name, e);
|
||||
super.visitChildren(e);
|
||||
collector.endElement();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@ part of '../ast.dart';
|
|||
/// Something that can appear as a top-level declaration inside a `.moor` file.
|
||||
abstract class PartOfMoorFile implements Statement {}
|
||||
|
||||
/// A moor file.
|
||||
///
|
||||
/// A moor file consists of [ImportStatement], followed by ddl statements,
|
||||
/// followed by [DeclaredStatement]s.
|
||||
class MoorFile extends AstNode {
|
||||
final List<PartOfMoorFile> statements;
|
||||
|
||||
|
@ -14,6 +18,10 @@ class MoorFile extends AstNode {
|
|||
@override
|
||||
Iterable<AstNode> get childNodes => statements;
|
||||
|
||||
/// Returns the imports defined in this file.
|
||||
Iterable<ImportStatement> get imports =>
|
||||
childNodes.whereType<ImportStatement>();
|
||||
|
||||
@override
|
||||
bool contentEquals(MoorFile other) => true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue