use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl in project intellij by bazelbuild.
the class ProjectViewParserTest method initTest.
@Override
protected void initTest(@NotNull Container applicationServices, @NotNull Container projectServices) {
super.initTest(applicationServices, projectServices);
context = new BlazeContext();
errorCollector = new ErrorCollector();
context.addOutputSink(IssueOutput.class, errorCollector);
projectViewParser = new ProjectViewParser(context, new WorkspacePathResolverImpl(workspaceRoot));
projectViewStorageManager = new MockProjectViewStorageManager();
applicationServices.register(ProjectViewStorageManager.class, projectViewStorageManager);
applicationServices.register(ExperimentService.class, new MockExperimentService());
registerExtensionPoint(BlazeSyncPlugin.EP_NAME, BlazeSyncPlugin.class);
}
use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl in project intellij by bazelbuild.
the class BlazeGoGotoDeclarationHandlerTest method testResolveGoDirectories.
@Test
public void testResolveGoDirectories() {
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(src("foo/bar/BUILD")).setLabel("//foo/bar:binary").setKind("go_binary").addSource(src("foo/bar/binary.go")).addDependency("//one/two:library").setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/binary.go"))).setImportPath("prefix/foo/bar/binary"))).addTarget(TargetIdeInfo.builder().setBuildFile(src("one/two/BUILD")).setLabel("//one/two:library").setKind("go_library").addSource(src("one/two/library.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("one/two/library.go"))).setImportPath("prefix/one/two/library"))).build();
BlazeProjectData projectData = new BlazeProjectData(0L, targetMap, null, null, new WorkspacePathResolverImpl(workspaceRoot), location -> workspaceRoot.fileForPath(new WorkspacePath(location.getRelativePath())), new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null);
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(projectData));
GoFile fooBarBinary = (GoFile) workspace.createPsiFile(new WorkspacePath("foo/bar/binary.go"), "package main", "import \"p<caret>refix/one<caret>/<caret>two/lib<caret>rary\"", "func foo(a library.One<caret>Two) {}", "func main() {}");
GoFile oneTwoLibrary = (GoFile) workspace.createPsiFile(new WorkspacePath("one/two/library.go"), "package library", "type OneTwo struct {}");
GoTypeSpec oneTwoStruct = PsiTreeUtil.findChildOfType(oneTwoLibrary, GoTypeSpec.class);
PsiDirectory oneTwoDirectory = oneTwoLibrary.getParent();
assertThat(oneTwoDirectory).isNotNull();
PsiDirectory oneDirectory = oneTwoDirectory.getParent();
assertThat(oneDirectory).isNotNull();
BuildFile oneTwoBUILD = (BuildFile) workspace.createPsiFile(new WorkspacePath("one/two/BUILD"), "go_library(", " name = 'library',", " srcs = ['library.go'],", ")");
FuncallExpression oneTwoLibraryRule = PsiUtils.findFirstChildOfClassRecursive(oneTwoBUILD, FuncallExpression.class);
BlazeGoRootsProvider.createGoPathSourceRoot(getProject(), projectData);
testFixture.configureFromExistingVirtualFile(fooBarBinary.getVirtualFile());
List<Caret> carets = testFixture.getEditor().getCaretModel().getAllCarets();
assertThat(carets).hasSize(5);
PsiElement gotoPrefix = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(0).getOffset());
assertThat(gotoPrefix).isEqualTo(oneTwoLibraryRule);
PsiElement gotoOne = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(1).getOffset());
assertThat(gotoOne).isEqualTo(oneDirectory);
PsiElement gotoTwo = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(2).getOffset());
assertThat(gotoTwo).isEqualTo(oneTwoDirectory);
PsiElement gotoLibrary = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(3).getOffset());
assertThat(gotoLibrary).isEqualTo(oneTwoLibraryRule);
PsiElement gotoOneTwoType = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(4).getOffset());
assertThat(gotoOneTwoType).isEqualTo(oneTwoStruct);
}
use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl in project intellij by bazelbuild.
the class ProjectStateSyncTask method computeWorkspacePathResolverAndProjectView.
private WorkspacePathResolverAndProjectView computeWorkspacePathResolverAndProjectView(BlazeContext context, BlazeVcsHandler vcsHandler, ListeningExecutorService executor) {
context.output(new StatusOutput("Updating VCS..."));
for (int i = 0; i < 3; ++i) {
WorkspacePathResolver vcsWorkspacePathResolver = null;
BlazeVcsHandler.BlazeVcsSyncHandler vcsSyncHandler = vcsHandler.createSyncHandler(project, workspaceRoot);
if (vcsSyncHandler != null) {
boolean ok = Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("UpdateVcs", EventType.Other));
return vcsSyncHandler.update(context, executor);
});
if (!ok) {
return null;
}
vcsWorkspacePathResolver = vcsSyncHandler.getWorkspacePathResolver();
}
WorkspacePathResolver workspacePathResolver = vcsWorkspacePathResolver != null ? vcsWorkspacePathResolver : new WorkspacePathResolverImpl(workspaceRoot);
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).reloadProjectView(context, workspacePathResolver);
if (projectViewSet == null) {
return null;
}
if (vcsSyncHandler != null) {
BlazeVcsHandler.BlazeVcsSyncHandler.ValidationResult validationResult = vcsSyncHandler.validateProjectView(context, projectViewSet);
switch(validationResult) {
case OK:
// Fall-through and return
break;
case Error:
return null;
case RestartSync:
continue;
default:
// Cannot happen
return null;
}
}
return new WorkspacePathResolverAndProjectView(workspacePathResolver, projectViewSet);
}
return null;
}
use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl in project intellij by bazelbuild.
the class UseExistingBazelWorkspaceOption method getWorkspaceData.
@Override
public WorkspaceTypeData getWorkspaceData() throws ConfigurationException {
String directory = getDirectory();
if (directory.isEmpty()) {
throw new ConfigurationException("Please select a workspace");
}
File workspaceRootFile = new File(directory);
if (!workspaceRootFile.exists()) {
throw new ConfigurationException("Workspace does not exist");
}
if (!isWorkspaceRoot(workspaceRootFile)) {
throw new ConfigurationException("Invalid workspace root: choose a bazel workspace directory " + "(containing a WORKSPACE file)");
}
WorkspaceRoot root = new WorkspaceRoot(workspaceRootFile);
return WorkspaceTypeData.builder().setWorkspaceName(workspaceRootFile.getName()).setWorkspaceRoot(root).setCanonicalProjectDataLocation(workspaceRootFile).setFileBrowserRoot(workspaceRootFile).setWorkspacePathResolver(new WorkspacePathResolverImpl(root)).setBuildSystem(BuildSystem.Bazel).build();
}
use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl in project intellij by bazelbuild.
the class BlazeDlvPositionConverterTest method init.
@Before
public void init() {
GoSdkService.getInstance(getProject()).setSdk(new GoSdkImpl("/usr/lib/golang", null, null));
registerApplicationService(VirtualFileSystemProvider.class, () -> mockFileSystem);
BlazeProjectData projectData = MockBlazeProjectDataBuilder.builder().setWorkspacePathResolver(new WorkspacePathResolverImpl(workspaceRoot)).build();
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(projectData));
executionRoot = projectData.getBlazeInfo().getExecutionRoot();
mockFileSystem = new PartialMockLocalFileSystem();
}
Aggregations