Skip to content

Commit fa81188

Browse files
authored
Merge pull request #612 from sourcegraph/olafurpg/followup-review
Address leftover review comments
2 parents 9dbad49 + 0e325f0 commit fa81188

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/NoRelativePathMode.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.sourcegraph.semanticdb_javac;
22

3+
import java.util.Arrays;
4+
import java.util.stream.Collectors;
5+
36
/**
47
* Configuration options to determine how semanticdb-javac should handle files that have no good
58
* relative paths.
@@ -24,5 +27,18 @@ public enum NoRelativePathMode {
2427
ERROR,
2528

2629
/** Ignore the file, but print a message explaining it's ignored. */
27-
WARNING
30+
WARNING;
31+
32+
public static String validStringValuesWithoutError() {
33+
return Arrays.stream(NoRelativePathMode.values())
34+
.filter(mode -> !mode.equals(ERROR))
35+
.map(NoRelativePathMode::toString)
36+
.collect(Collectors.joining(", "));
37+
}
38+
39+
public static String validStringValues() {
40+
return Arrays.stream(NoRelativePathMode.values())
41+
.map(NoRelativePathMode::toString)
42+
.collect(Collectors.joining(", "));
43+
}
2844
}

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbJavacOptions.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,10 @@ public static SemanticdbJavacOptions parse(String[] args, Context ctx) {
7979
result.noRelativePath = NoRelativePathMode.WARNING;
8080
break;
8181
default:
82-
String validValues =
83-
Arrays.stream(NoRelativePathMode.values())
84-
.map(NoRelativePathMode::toString)
85-
.collect(Collectors.joining(", "));
8682
result.errors.add(
8783
String.format(
8884
"unknown -no-relative-path mode '%s'. Valid values are %s.",
89-
value, validValues));
85+
value, NoRelativePathMode.validStringValues()));
9086
}
9187
} else if (arg.equals("-build-tool:bazel")) {
9288
result.uriScheme = UriScheme.BAZEL;

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTaskListener.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,18 @@ private Result<Path, String> semanticdbOutputPath(SemanticdbJavacOptions options
233233
return null;
234234
case ERROR:
235235
default:
236-
return Result.error(
236+
String baseMessage =
237237
String.format(
238238
"Unable to detect the relative path of '%s'. A common reason for this error is that the file is that this file is auto-generated. "
239-
+ "To fix this problem, either configure the -sourceroot:PATH flag to be the parent directory of all indexed files, or "
240-
+ "configure -no-relative-path:VALUE flag to have one of the following values: index_anyway, skip, warning.",
241-
absolutePath));
239+
+ "To fix this problem update the flag -no-relative-path:VALUE to have one of the following values: %s.",
240+
absolutePath, NoRelativePathMode.validStringValuesWithoutError());
241+
if (options.uriScheme == UriScheme.BAZEL) {
242+
return Result.error(baseMessage);
243+
}
244+
245+
return Result.error(
246+
baseMessage
247+
+ " Alternatively, configure the -sourceroot:PATH flag to point to a directory path that is the parent of all indexed files.");
242248
}
243249
}
244250
}

0 commit comments

Comments
 (0)