generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(completion): add support for code fence language detection and c…
…ompletion #101 This commit introduces a new feature that enhances the completion experience for code fences. It includes support for detecting the language of a code fence based on its info-string and provides completion suggestions accordingly. Additionally, the commit refactors the existing completion logic to ensure smoother integration with the new code fence language support.
- Loading branch information
Showing
4 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/CodeFenceLanguageAliases.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package cc.unitmesh.devti | ||
|
||
import com.intellij.openapi.util.text.StringUtil | ||
|
||
/** | ||
* Service to work with Markdown code fence's info-string. | ||
* | ||
* [CodeFenceLanguageAliases] is able to find possible IntelliJ Language ID | ||
* for info string (including resolution of standard aliases) and | ||
* (backwards) suggest correct info string for IntelliJ Language ID | ||
*/ | ||
object CodeFenceLanguageAliases { | ||
private data class Entry( | ||
val id: String, | ||
val main: String, | ||
val aliases: Set<String> | ||
) | ||
|
||
private val aliases = setOf( | ||
Entry("go", "go", setOf("golang")), | ||
Entry("HCL", "hcl", setOf("hcl")), | ||
Entry("ApacheConfig", "apacheconf", setOf("aconf", "apache", "apacheconfig")), | ||
Entry("Batch", "batch", setOf("bat", "batchfile")), | ||
Entry("CoffeeScript", "coffeescript", setOf("coffee", "coffee-script")), | ||
Entry("JavaScript", "javascript", setOf("js", "node")), | ||
Entry("Markdown", "markdown", setOf("md")), | ||
Entry("PowerShell", "powershell", setOf("posh", "pwsh")), | ||
Entry("Python", "python", setOf("python2", "python3", "py")), | ||
Entry("R", "r", setOf("rlang", "rscript")), | ||
Entry("RegExp", "regexp", setOf("regex")), | ||
Entry("Ruby", "ruby", setOf("ruby", "rb")), | ||
Entry("Yaml", "yaml", setOf("yml")), | ||
Entry("Kotlin", "kotlin", setOf("kt", "kts")), | ||
Entry("HCL-Terraform", "terraform", setOf("hcl-terraform", "tf")), | ||
Entry("C#", "csharp", setOf("cs", "c#")), | ||
Entry("F#", "fsharp", setOf("fs", "f#")), | ||
Entry("Shell Script", "shell", setOf("shell script", "bash", "zsh", "sh")) | ||
) | ||
|
||
fun findRegisteredEntry(value: String): String? { | ||
val lower = value.lowercase() | ||
val entry = aliases.singleOrNull { lower == it.main || lower in it.aliases } | ||
return entry?.id | ||
} | ||
|
||
/** | ||
* Get recommended alias for [id] | ||
* @return recommended alias if any or just [id] | ||
*/ | ||
fun findMainAlias(id: String): String { | ||
return findMainAliasIfRegistered(id) ?: StringUtil.toLowerCase(id) | ||
} | ||
|
||
fun findMainAliasIfRegistered(id: String): String? { | ||
return aliases.singleOrNull { id == it.id }?.main | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters