Skip to content

Commit

Permalink
Decorate tabs for BUILD files with package name
Browse files Browse the repository at this point in the history
Since BUILD files all have the same name it's hard
to distinguish them, so we can use EditorTabTitleProvider
to write full label in the editor tab title
  • Loading branch information
ujohnny committed Oct 16, 2024
1 parent 30b7a7a commit 839a672
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
<completion.confidence language="BUILD" implementationClass="com.google.idea.blaze.base.lang.buildfile.completion.BuildFileCompletionConfidence"/>
<spellchecker.support language="BUILD" implementationClass="com.google.idea.blaze.base.lang.buildfile.validation.BuildSpellcheckingStrategy"/>
<highlightVisitor implementation="com.google.idea.blaze.base.editor.HighlightingStatsCollector"/>
<editorTabTitleProvider implementation="com.google.idea.blaze.base.editor.BazelEditorTabTitleProvider"/>
<formattingService implementation="com.google.idea.blaze.base.buildmodifier.BuildifierFormattingService"/>
</extensions>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.google.idea.blaze.base.editor;

import com.google.idea.blaze.base.lang.buildfile.psi.BuildFile;
import com.google.idea.blaze.base.settings.Blaze;
import com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class BazelEditorTabTitleProvider implements EditorTabTitleProvider {
private static boolean requiresDecoration(Project project, String fileName) {
return Blaze.getBuildSystemProvider(project).possibleBuildFileNames().contains(fileName);
}
@Override
public @Nullable String getEditorTabTitle(@NotNull Project project,
@NotNull VirtualFile virtualFile) {
var fileName = virtualFile.getName();
if (!requiresDecoration(project, fileName)) {
return null;
}

return BuildFile.getBuildFileString(project, virtualFile.getPath());
}

@Override
public @Nullable String getEditorTabTooltipText(@NotNull Project project,
@NotNull VirtualFile virtualFile) {
return EditorTabTitleProvider.super.getEditorTabTooltipText(project, virtualFile);
}
}

0 comments on commit 839a672

Please sign in to comment.