Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Added

- **Rakefile support (no extension)** — all annotators, actions, and intention actions now accept
a file named `Rakefile` (without `.rb` or `.rake` extension) in addition to `.rb` and `.rake`
files. This ensures the plugin works on standard Rakefiles that have no file extension.
- **Graceful handling when docscribe gem not installed** — `DocscribeDaemon` now runs
`bundle exec docscribe --version` once on first use and caches the result. If the gem is missing, a
user-friendly notification (with "Open Gemfile" action) is shown once, and all operations return a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class AggressiveFixAction : AnAction() {
*/
override fun update(e: AnActionEvent) {
val file = e.getData(CommonDataKeys.VIRTUAL_FILE)
e.presentation.isEnabledAndVisible = file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake"))
e.presentation.isEnabledAndVisible =
file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake") || file.name == "Rakefile")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class CheckFileAction : AnAction() {
*/
override fun update(e: AnActionEvent) {
val file = e.getData(CommonDataKeys.VIRTUAL_FILE)
e.presentation.isEnabledAndVisible = file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake"))
e.presentation.isEnabledAndVisible =
file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake") || file.name == "Rakefile")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class SafeFixAction : AnAction() {
*/
override fun update(e: AnActionEvent) {
val file = e.getData(CommonDataKeys.VIRTUAL_FILE)
e.presentation.isEnabledAndVisible = file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake"))
e.presentation.isEnabledAndVisible =
file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake") || file.name == "Rakefile")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DocscribeAggressiveFixIntention : IntentionAction {
project: Project,
editor: Editor?,
file: PsiFile?,
): Boolean = file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake"))
): Boolean = file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake") || file.name == "Rakefile")

/**
* Run docscribe aggressive fix in a background task, then refresh the file on success.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DocscribeAnnotator : ExternalAnnotator<AnnotatorFileInfo, DocscribeOutput>
editor: Editor,
hasErrors: Boolean,
): AnnotatorFileInfo? {
if (!file.name.endsWith(".rb") && !file.name.endsWith(".rake")) return null
if (!file.name.endsWith(".rb") && !file.name.endsWith(".rake") && file.name != "Rakefile") return null
val vFile = file.virtualFile ?: return null
val projectDir = file.project.basePath ?: return null

Expand All @@ -86,7 +86,7 @@ class DocscribeAnnotator : ExternalAnnotator<AnnotatorFileInfo, DocscribeOutput>
* @return [AnnotatorFileInfo] if the file should be checked, or `null` to skip.
*/
override fun collectInformation(file: PsiFile): AnnotatorFileInfo? {
if (!file.name.endsWith(".rb") && !file.name.endsWith(".rake")) return null
if (!file.name.endsWith(".rb") && !file.name.endsWith(".rake") && file.name != "Rakefile") return null
val vFile = file.virtualFile ?: return null
val projectDir = file.project.basePath ?: return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DocscribeCheckIntention : IntentionAction {
project: Project,
editor: Editor?,
file: PsiFile?,
): Boolean = file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake"))
): Boolean = file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake") || file.name == "Rakefile")

/**
* Run docscribe check in a background task and show a notification on completion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DocscribeFixIntention : IntentionAction {
project: Project,
editor: Editor?,
file: PsiFile?,
): Boolean = file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake"))
): Boolean = file != null && (file.name.endsWith(".rb") || file.name.endsWith(".rake") || file.name == "Rakefile")

/**
* Save the editor, find the project root, and run docscribe safe fix in a background task.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ class AggressiveFixActionTest : BasePlatformTestCase() {
assertTrue(presentation.isEnabledAndVisible)
}

fun testAggressiveFixActionIsEnabledForRakefile() {
val file = myFixture.configureByText("Rakefile", "task :test do\nend").virtualFile
val dataContext =
SimpleDataContext
.builder()
.add(CommonDataKeys.VIRTUAL_FILE, file)
.add(CommonDataKeys.PROJECT, myFixture.project)
.build()
val presentation = Presentation()
val event = AnActionEvent.createEvent(dataContext, presentation, "test", ActionUiKind.NONE, null)
action.update(event)
assertTrue(presentation.isEnabledAndVisible)
}

fun testAggressiveFixActionIsDisabledForNonRubyFile() {
val file = myFixture.configureByText("foo.txt", "plain text").virtualFile
val dataContext =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ class CheckFileActionTest : BasePlatformTestCase() {
assertTrue(presentation.isEnabledAndVisible)
}

fun testActionIsEnabledForRakefile() {
val file = myFixture.configureByText("Rakefile", "task :test do\nend").virtualFile
val dataContext =
SimpleDataContext
.builder()
.add(CommonDataKeys.VIRTUAL_FILE, file)
.add(CommonDataKeys.PROJECT, myFixture.project)
.build()
val presentation = Presentation()
val event = AnActionEvent.createEvent(dataContext, presentation, "test", ActionUiKind.NONE, null)
action.update(event)
assertTrue(presentation.isEnabledAndVisible)
}

fun testActionIsDisabledForNonRubyFile() {
val file = myFixture.configureByText("foo.txt", "plain text").virtualFile
val dataContext =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ class SafeFixActionTest : BasePlatformTestCase() {
assertTrue(presentation.isEnabledAndVisible)
}

fun testSafeFixActionIsEnabledForRakefile() {
val file = myFixture.configureByText("Rakefile", "task :test do\nend").virtualFile
val dataContext =
SimpleDataContext
.builder()
.add(CommonDataKeys.VIRTUAL_FILE, file)
.add(CommonDataKeys.PROJECT, myFixture.project)
.build()
val presentation = Presentation()
val event = AnActionEvent.createEvent(dataContext, presentation, "test", ActionUiKind.NONE, null)
action.update(event)
assertTrue(presentation.isEnabledAndVisible)
}

fun testSafeFixActionIsDisabledForNonRubyFile() {
val file = myFixture.configureByText("foo.txt", "plain text").virtualFile
val dataContext =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class DocscribeAnnotatorTest : BasePlatformTestCase() {
assertNotNull(info)
}

fun testAnnotatorReturnsInfoForPlainRakefile() {
val file = myFixture.configureByText("Rakefile", "task :test do\nend")
val info = DocscribeAnnotator().collectInformation(file)
assertNotNull(info)
}

fun testNoEditorOverloadReturnsInfo() {
val file = myFixture.configureByText("test.rb", "class Foo\nend")
val info = DocscribeAnnotator().collectInformation(file)
Expand Down
Loading