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
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,23 @@ private static boolean hasParentSection(URIResolverRegistry reg, ISourceLocation
}
}

/**
* Infers the root of the project that `member` is in.
*/
private static ISourceLocation inferProjectRoot(ISourceLocation member) {
ISourceLocation lastRoot = member;
ISourceLocation root;
do {
root = lastRoot;
lastRoot = inferDeepestProjectRoot(URIUtil.getParentLocation(root));
} while (!lastRoot.equals(URIUtil.getParentLocation(root)));
return root;
}

/**
* Infers the longest project root-like path that `member` is in. Might return a sub-directory of `target/`.
*/
private static ISourceLocation inferDeepestProjectRoot(ISourceLocation member) {
ISourceLocation current = member;
URIResolverRegistry reg = URIResolverRegistry.getInstance();
if (!reg.isDirectory(current)) {
Expand All @@ -254,13 +270,13 @@ private static ISourceLocation inferProjectRoot(ISourceLocation member) {
if (reg.exists(URIUtil.getChildLocation(current, "META-INF/RASCAL.MF"))) {
return current;
}

if (URIUtil.getParentLocation(current).equals(current)) {
var parent = URIUtil.getParentLocation(current);
if (parent.equals(current)) {
// we went all the way up to the root
return reg.isDirectory(member) ? member : URIUtil.getParentLocation(member);
}

current = URIUtil.getParentLocation(current);
current = parent;
}

return current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,21 @@ loc targetToProject(loc l) {
}

@memo
@synopsis{Infers the root of the project that `member` is in.}
loc inferProjectRoot(loc member) {
parentRoot = member;
root = parentRoot;

do {
root = parentRoot;
parentRoot = inferDeepestProjectRoot(root.parent);
} while (root.parent? && parentRoot != root.parent);
return root;
}

@synopsis{Infers the longest project root-like path that `member` is in.}
@pitfalls{Might return a sub-directory of `target/`.}
loc inferDeepestProjectRoot(loc member) {
current = targetToProject(member);
if (!isDirectory(current)) {
current = current.parent;
Expand Down
Loading