diff --git a/duchain/astredux.h b/duchain/astredux.h index 13bb6e4..39aad79 100644 --- a/duchain/astredux.h +++ b/duchain/astredux.h @@ -1,66 +1,67 @@ #ifndef ASTREDUX_H #define ASTREDUX_H extern "C" { enum RSNodeKind { Crate, StructDecl, EnumDecl, TraitDecl, ImplDecl, TypeAliasDecl, FieldDecl, EnumVariantDecl, FunctionDecl, ParmDecl, VarDecl, - PathUse, + Path, + PathSegment, Unexposed }; enum RSVisitResult { Break, Continue, Recurse }; struct RSLocation { int line; int column; }; struct RSRange { RSLocation start; RSLocation end; }; struct RSCrate; struct RSNode; typedef RSVisitResult (*CallbackFn)(RSNode *node, RSNode *parent, void *data); RSCrate *parse_crate(const char *name, const char *source); void destroy_crate(RSCrate *crate); RSNode *node_from_crate(RSCrate *crate); void destroy_node(RSNode *node); RSCrate *node_get_crate(RSNode *node); RSNodeKind node_get_kind(RSNode *node); const char *node_get_spelling_name(RSNode *node); RSRange node_get_spelling_range(RSNode *node); RSRange node_get_extent(RSNode *node); void destroy_string(const char *str); void visit_children(RSNode *node, CallbackFn callback, void *data); } #endif // ASTREDUX_H diff --git a/duchain/usebuilder.cpp b/duchain/usebuilder.cpp index a51d285..13f6dd8 100644 --- a/duchain/usebuilder.cpp +++ b/duchain/usebuilder.cpp @@ -1,51 +1,57 @@ #include "usebuilder.h" #include #include #include #include #include "rustdebug.h" namespace Rust { RSVisitResult UseBuilder::visitNode(RustNode *node, RustNode *parent) { using namespace KDevelop; RSNodeKind kind = node_get_kind(node->data()); - if (kind == PathUse) { - RustPath path(node); - + if (kind == PathSegment) { + RustPath segment(node); + RustPath path(parent); + QualifiedIdentifier qualifiedPath = identifierForNode(&path); + IndexedIdentifier pathSegment = IndexedIdentifier(Identifier(segment.value)); + + // eh, this feels way too much like a hack + while (qualifiedPath.last() != pathSegment) { + qualifiedPath.pop(); + } - RustPath name(node); - RangeInRevision useRange = editorFindSpellingRange(node, name.value); + RangeInRevision useRange = editorFindSpellingRange(node, segment.value); - qCDebug(KDEV_RUST) << "USE:" << name.value << "; spelling range: (" + qCDebug(KDEV_RUST) << "USE:" << segment.value << "; spelling range: (" << useRange.start.line + 1 << ":" << useRange.start.column << "-" << useRange.end.line + 1 << ":" << useRange.end.column << ")"; DUContext *context = topContext()->findContextAt(useRange.start); - QList declarations = context->findDeclarations(identifierForNode(&path)); + QList declarations = context->findDeclarations(qualifiedPath); if (declarations.isEmpty()) { Problem *p = new Problem(); p->setFinalLocation(DocumentRange(document(), useRange.castToSimpleRange())); p->setSource(IProblem::SemanticAnalysis); p->setSeverity(IProblem::Hint); p->setDescription(i18n("Undefined %1", path.value)); { DUChainWriteLocker wlock(DUChain::lock()); ProblemPointer ptr(p); topContext()->addProblem(ptr); } } else if (declarations.first() && declarations.first()->range() != useRange) { UseBuilderBase::newUse(node, useRange, DeclarationPointer(declarations.first())); } } return Recurse; } }