Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support sting type tasks.depends code completion #127

Merged
merged 2 commits into from
Jan 5, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package com.github.l34130.mise.core.lang.completion
import com.github.l34130.mise.core.lang.psi.MiseTomlPsiPatterns
import com.intellij.codeInsight.completion.CompletionContributor
import com.intellij.codeInsight.completion.CompletionType
import com.intellij.patterns.StandardPatterns

class MiseTomlCompletionContributor : CompletionContributor() {
init {
extend(CompletionType.BASIC, MiseTomlPsiPatterns.inTaskDependsArray, MiseTomlTaskCompletionProvider())
extend(
CompletionType.BASIC,
StandardPatterns.or(MiseTomlPsiPatterns.inTaskDependsArray, MiseTomlPsiPatterns.inTaskDependsString),
MiseTomlTaskCompletionProvider(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@ import org.toml.lang.psi.TomlTable
/**
* ```
* [tasks.foo]
* ...
* run = "..."
* ```
*
* then
*
* ```
* [tasks.<task-name>]
* depends = [ "f<caret>" ]
* #^ Provides completion for "foo"
* ```
*
* or
*
* ```
* [tasks.<task-name>]
* depends = "f<caret>"
* #^ Provides completion for "foo"
* ```
*/
class MiseTomlTaskCompletionProvider : CompletionProvider<CompletionParameters>() {
override fun addCompletions(
Expand All @@ -31,14 +44,14 @@ class MiseTomlTaskCompletionProvider : CompletionProvider<CompletionParameters>(
val element = parameters.position
val miseTomlFile = element.containingFile as? MiseTomlFile ?: return

val dependsArray = (element.parent.parent as? TomlArray) ?: return
val dependsArray = (element.parent.parent as? TomlArray)

val parentTable = element.parentOfType<TomlTable>() ?: return
val parentTaskName = parentTable.taskName

for (task in miseTomlFile.allTasks()) {
val taskName = task.name ?: continue
if (dependsArray.elements.any { it.stringValue == taskName }) continue
if (dependsArray?.elements?.any { it.stringValue == taskName } == true) continue
if (taskName == parentTaskName) continue

result.addElement(
Expand All @@ -48,6 +61,4 @@ class MiseTomlTaskCompletionProvider : CompletionProvider<CompletionParameters>(
)
}
}

// TODO: Need to support literal string completion
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
VirtualFilePattern().ofType(MiseTomlFileType),
)

fun miseTomlStringLiteral() = miseTomlPsiElement<TomlLiteral>().with("stringLiteral") { e, _ -> e.kind is TomlLiteralKind.String }

Check notice on line 27 in modules/core/src/main/kotlin/com/github/l34130/mise/core/lang/psi/MiseTomlPsiPatterns.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Function or property has platform type

Declaration has type inferred from a platform call, which can lead to unchecked nullability issues. Specify type explicitly as nullable or non-nullable.

Check notice on line 27 in modules/core/src/main/kotlin/com/github/l34130/mise/core/lang/psi/MiseTomlPsiPatterns.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Function 'miseTomlStringLiteral' could be private

private val onSpecificTaskTable =
miseTomlPsiElement<TomlTable>()
Expand Down Expand Up @@ -78,11 +78,33 @@
psiElement<TomlArray>()
.withParent(taskProperty("depends_post")),
)
val inTaskDependsArray = miseTomlPsiElement<PsiElement>().inside(onTaskDependsArray)

Check notice on line 81 in modules/core/src/main/kotlin/com/github/l34130/mise/core/lang/psi/MiseTomlPsiPatterns.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Function or property has platform type

Declaration has type inferred from a platform call, which can lead to unchecked nullability issues. Specify type explicitly as nullable or non-nullable.

/**
* ```
* [tasks]
* foo = { version = "*", depends = "" }
* #^
* ```
*
* ```
* [tasks.foo]
* depends = ""
* #^
* ```
*/
private val onTaskDependsString =
StandardPatterns.or(
miseTomlStringLiteral()
.withParent(taskProperty("depends")),
miseTomlStringLiteral()
.withParent(taskProperty("depends_post")),
)
val inTaskDependsString = miseTomlPsiElement<PsiElement>().inside(onTaskDependsString)

Check notice on line 103 in modules/core/src/main/kotlin/com/github/l34130/mise/core/lang/psi/MiseTomlPsiPatterns.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Function or property has platform type

Declaration has type inferred from a platform call, which can lead to unchecked nullability issues. Specify type explicitly as nullable or non-nullable.

inline fun <reified I : PsiElement> psiElement() = PlatformPatterns.psiElement(I::class.java)

Check notice on line 105 in modules/core/src/main/kotlin/com/github/l34130/mise/core/lang/psi/MiseTomlPsiPatterns.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Function or property has platform type

Declaration has type inferred from a platform call, which can lead to unchecked nullability issues. Specify type explicitly as nullable or non-nullable.

Check notice on line 105 in modules/core/src/main/kotlin/com/github/l34130/mise/core/lang/psi/MiseTomlPsiPatterns.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Function 'psiElement' could be private

fun <T : Any, Self : ObjectPattern<T, Self>> ObjectPattern<T, Self>.with(

Check notice on line 107 in modules/core/src/main/kotlin/com/github/l34130/mise/core/lang/psi/MiseTomlPsiPatterns.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Function 'with' could be private
name: String,
cond: (T, ProcessingContext?) -> Boolean,
): Self =
Expand Down
Loading