Skip to content

Commit

Permalink
Merge #5579
Browse files Browse the repository at this point in the history
5579: IDE: show parent folder name in editor tab for lib.rs, main.rs and Cargo.toml r=mchernyavsky a=Kobzol

Fixes: #1410

Co-authored-by: Jakub Beránek <berykubik@gmail.com>
  • Loading branch information
bors[bot] and Kobzol committed Jun 16, 2020
2 parents 35f8d92 + e58c36e commit e52be04
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/

package org.rust.ide.miscExtensions

import com.intellij.ide.ui.UISettings
import com.intellij.openapi.fileEditor.UniqueVFilePathBuilder
import com.intellij.openapi.fileEditor.impl.UniqueNameEditorTabTitleProvider
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import org.rust.cargo.CargoConstants
import org.rust.lang.RsConstants
import org.rust.lang.core.psi.isRustFile
import java.io.File

class RsFileTabTitleProvider : UniqueNameEditorTabTitleProvider() {
override fun getEditorTabTitle(project: Project, file: VirtualFile): String? {
if (!((file.isRustFile && file.name in EXPLICIT_FILES) || file.name == CargoConstants.MANIFEST_FILE)) {
return null
}

val uiSettings = UISettings.instanceOrNull
if (uiSettings == null || !uiSettings.showDirectoryForNonUniqueFilenames || DumbService.isDumb(project)) {
return null
}

val uniqueName = UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(project, file)
val tabText = getEditorTabText(uniqueName, File.separator, uiSettings.hideKnownExtensionInTabs)
return tabText.takeUnless { it == file.name }
}

companion object {
private val EXPLICIT_FILES = setOf(
RsConstants.MOD_RS_FILE,
RsConstants.LIB_RS_FILE,
RsConstants.MAIN_RS_FILE
)
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/META-INF/rust-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@

<!-- Editor Tab Title Providers -->

<editorTabTitleProvider implementation="org.rust.ide.miscExtensions.RsModTabTitleProvider"/>
<editorTabTitleProvider implementation="org.rust.ide.miscExtensions.RsFileTabTitleProvider"/>

<!-- Refactoring -->

Expand Down

0 comments on commit e52be04

Please sign in to comment.