Skip to content
Open
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
3 changes: 3 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if [ ! -e src/main/java/com/google/devtools/build/lib/analysis/AnalysisProtos.ja
./scripts/gen_proto.sh
fi

export JAVA_HOME=$(pwd)/jdks/linux/jdk-21
export PATH=$JAVA_HOME/bin:$PATH

mvn package -DskipTests

# Build vsix
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/javacs/InferConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,20 @@ Set<Path> classPath() {

// Bazel
var bazelWorkspaceRoot = bazelWorkspaceRoot();
if (Files.exists(bazelWorkspaceRoot.resolve("WORKSPACE"))) {
if (isBazelProject(bazelWorkspaceRoot)) {
return bazelClasspath(bazelWorkspaceRoot);
}

return Collections.emptySet();
}

private Path bazelWorkspaceRoot() {
boolean isBazelProject(Path root) {
return Files.exists(root.resolve("WORKSPACE")) || Files.exists(root.resolve("MODULE.bazel"));
}

Path bazelWorkspaceRoot() {
for (var current = workspaceRoot; current != null; current = current.getParent()) {
if (Files.exists(current.resolve("WORKSPACE"))) {
if (isBazelProject(current)) {
return current;
}
}
Expand Down Expand Up @@ -141,7 +145,7 @@ Set<Path> buildDocPath() {

// Bazel
var bazelWorkspaceRoot = bazelWorkspaceRoot();
if (Files.exists(bazelWorkspaceRoot.resolve("WORKSPACE"))) {
if (isBazelProject(bazelWorkspaceRoot)) {
return bazelSourcepath(bazelWorkspaceRoot);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/javacs/JavaLanguageServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public InitializeResult initialize(InitializeParams params) {
}

private static final String[] watchFiles = {
"**/*.java", "**/pom.xml", "**/BUILD", "**/javaconfig.json", "**/WORKSPACE"
"**/*.java", "**/pom.xml", "**/BUILD", "**/javaconfig.json", "**/WORKSPACE", "**/MODULE.bazel"
};

@Override
Expand Down Expand Up @@ -275,6 +275,8 @@ public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) {
switch (name) {
case "BUILD":
case "pom.xml":
case "WORKSPACE":
case "MODULE.bazel":
LOG.info("Compiler needs to be re-created because " + file + " has changed");
modifiedBuild = true;
}
Expand Down
Empty file.
7 changes: 6 additions & 1 deletion src/test/java/org/javacs/HoverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.List;
import java.util.StringJoiner;
import org.javacs.lsp.*;
import org.junit.Test;
Expand Down Expand Up @@ -78,8 +79,12 @@ private String symbolAt(String file, int line, int character) {
var pos =
new TextDocumentPositionParams(
new TextDocumentIdentifier(FindResource.uri(file)), new Position(line - 1, character - 1));
var hover = server.hover(pos).get();
if (hover.contents instanceof MarkupContent) {
return ((MarkupContent) hover.contents).value;
}
var result = new StringJoiner("\n");
for (var h : server.hover(pos).get().contents) {
for (var h : (List<MarkedString>) hover.contents) {
result.add(h.value);
}
return result.toString();
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/javacs/InferBazelBzlmodConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.javacs;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

import java.nio.file.Paths;
import java.nio.file.Files;
import org.junit.Test;
import org.junit.BeforeClass;
import java.io.IOException;

public class InferBazelBzlmodConfigTest {
private static final String EXAMPLE_PATH = "src/test/examples/bazel-bzlmod-project";

@BeforeClass
public static void setup() throws IOException {
var path = Paths.get(EXAMPLE_PATH);
if (!Files.exists(path)) {
Files.createDirectories(path);
}
var moduleFile = path.resolve("MODULE.bazel");
if (!Files.exists(moduleFile)) {
Files.createFile(moduleFile);
}
var subDir = path.resolve("subdir");
if (!Files.exists(subDir)) {
Files.createDirectories(subDir);
}
}

@Test
public void detectBzlmodRoot() {
var config = new InferConfig(Paths.get(EXAMPLE_PATH));
assertThat(config.isBazelProject(Paths.get(EXAMPLE_PATH)), is(true));
assertThat(config.bazelWorkspaceRoot(), equalTo(Paths.get(EXAMPLE_PATH)));
}

@Test
public void detectBzlmodRootFromSubdir() {
var config = new InferConfig(Paths.get(EXAMPLE_PATH).resolve("subdir"));
assertThat(config.bazelWorkspaceRoot(), equalTo(Paths.get(EXAMPLE_PATH)));
}
}