Skip to content

Commit 0e325f0

Browse files
committed
Address leftover review comments
This commit addresses unresolved comments from the PR #611
1 parent 00c8ed5 commit 0e325f0

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
@@ -222,12 +222,18 @@ private Result<Path, String> semanticdbOutputPath(SemanticdbJavacOptions options
222222
return null;
223223
case ERROR:
224224
default:
225-
return Result.error(
225+
String baseMessage =
226226
String.format(
227227
"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. "
228-
+ "To fix this problem, either configure the -sourceroot:PATH flag to be the parent directory of all indexed files, or "
229-
+ "configure -no-relative-path:VALUE flag to have one of the following values: index_anyway, skip, warning.",
230-
absolutePath));
228+
+ "To fix this problem update the flag -no-relative-path:VALUE to have one of the following values: %s.",
229+
absolutePath, NoRelativePathMode.validStringValuesWithoutError());
230+
if (options.uriScheme == UriScheme.BAZEL) {
231+
return Result.error(baseMessage);
232+
}
233+
234+
return Result.error(
235+
baseMessage
236+
+ " Alternatively, configure the -sourceroot:PATH flag to point to a directory path that is the parent of all indexed files.");
231237
}
232238
}
233239
}

0 commit comments

Comments
 (0)