Search in sources :

Example 6 with WorkspacePathResolverImpl

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);
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) ErrorCollector(com.google.idea.blaze.base.scope.ErrorCollector)

Example 7 with WorkspacePathResolverImpl

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);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) GoFile(com.goide.psi.GoFile) GoTypeSpec(com.goide.psi.GoTypeSpec) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) PsiDirectory(com.intellij.psi.PsiDirectory) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Caret(com.intellij.openapi.editor.Caret) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 8 with WorkspacePathResolverImpl

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;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) BlazeVcsHandler(com.google.idea.blaze.base.vcs.BlazeVcsHandler)

Example 9 with WorkspacePathResolverImpl

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();
}
Also used : WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) ConfigurationException(com.intellij.openapi.options.ConfigurationException) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 10 with WorkspacePathResolverImpl

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();
}
Also used : WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) GoSdkImpl(com.goide.sdk.GoSdkImpl) Before(org.junit.Before)

Aggregations

WorkspacePathResolverImpl (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl)15 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)6 ProjectViewParser (com.google.idea.blaze.base.projectview.parser.ProjectViewParser)5 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)4 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 WorkspacePathResolver (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver)3 BlazeVcsHandler (com.google.idea.blaze.base.vcs.BlazeVcsHandler)3 BlazeInfo (com.google.idea.blaze.base.command.info.BlazeInfo)2 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)2 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)2 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)2 TimingScope (com.google.idea.blaze.base.scope.scopes.TimingScope)2 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)2 ArtifactLocationDecoderImpl (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoderImpl)2 File (java.io.File)2 Before (org.junit.Before)2 GoFile (com.goide.psi.GoFile)1 GoTypeSpec (com.goide.psi.GoTypeSpec)1 GoSdkImpl (com.goide.sdk.GoSdkImpl)1