This commit is contained in:
FalsePattern 2024-10-31 01:15:09 +01:00
parent d2093e81a9
commit 762ac05e11
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
22 changed files with 398 additions and 74 deletions

View file

@ -23,7 +23,9 @@
package com.falsepattern.zigbrains
import com.intellij.openapi.util.IconLoader
import org.jetbrains.annotations.NonNls
@NonNls
object Icons {
val ZIG = IconLoader.getIcon("/icons/zig.svg", Icons::class.java)
val ZON = IconLoader.getIcon("/icons/zon.svg", Icons::class.java)

View file

@ -0,0 +1,50 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains
import com.intellij.DynamicBundle
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey
import java.util.function.Supplier
@NonNls
private const val BUNDLE = "zigbrains.Bundle"
internal object ZigBrainsBundle {
private val INSTANCE = DynamicBundle(ZigBrainsBundle::class.java, BUNDLE)
fun message(
key: @PropertyKey(resourceBundle = BUNDLE) String,
vararg params: Any
): @Nls String {
return INSTANCE.getMessage(key, *params)
}
fun lazyMessage(
key: @PropertyKey(resourceBundle = BUNDLE) String,
vararg params: Any
): Supplier<@Nls String> {
return INSTANCE.getLazyMessage(key, *params)
}
}

View file

@ -22,20 +22,53 @@
package com.falsepattern.zigbrains.direnv
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.configurations.PathEnvironmentVariableUtil
import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.notification.Notifications
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.util.io.awaitExit
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.apache.commons.io.IOUtils
import java.nio.charset.StandardCharsets
import kotlinx.serialization.json.Json
import org.jetbrains.annotations.NonNls
import java.nio.file.Path
class DirenvCmd(val workingDirectory: Path) {
fun direnvInstalled() =
PathEnvironmentVariableUtil.findExecutableInPathOnAnyOS("direnv") != null
class DirenvCmd(private val workingDirectory: Path) {
suspend fun importDirenv(): Env {
if (!direnvInstalled())
return emptyEnv
val runOutput = run("export", "json")
if (runOutput.error) {
if (runOutput.output.contains("is blocked")) {
Notifications.Bus.notify(Notification(
GROUP_DISPLAY_ID,
ZigBrainsBundle.message("notification.title.direnv-blocked"),
ZigBrainsBundle.message("notification.content.direnv-blocked"),
NotificationType.ERROR
))
return emptyEnv
} else {
Notifications.Bus.notify(Notification(
GROUP_DISPLAY_ID,
ZigBrainsBundle.message("notification.title.direnv-error"),
ZigBrainsBundle.message("notification.content.direnv-error", runOutput.output),
NotificationType.ERROR
))
return emptyEnv
}
}
return Env(Json.decodeFromString<Map<String, String>>(runOutput.output))
}
@NonNls
private suspend fun run(vararg args: String): DirenvOutput {
@NonNls
val cli = GeneralCommandLine("direnv", *args)
.withWorkingDirectory(workingDirectory)
@ -48,4 +81,18 @@ class DirenvCmd(val workingDirectory: Path) {
val stdOut = process.errorStream.bufferedReader().use { it.readText() }
return DirenvOutput(stdOut, false)
}
companion object {
@NonNls
private const val GROUP_DISPLAY_ID = "zigbrains-direnv"
private val LOG = logger<DirenvCmd>()
fun direnvInstalled() =
// Using the builtin stuff here instead of Env because it should only scan for direnv on the process path
PathEnvironmentVariableUtil.findExecutableInPathOnAnyOS("direnv") != null
}
}
suspend fun Project?.getDirenv(): Env {
val dir = this?.guessProjectDir() ?: return emptyEnv
return DirenvCmd(dir.toNioPath()).importDirenv()
}

View file

@ -0,0 +1,35 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.direnv
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.util.application
import kotlinx.coroutines.CoroutineScope
@Service
class DirenvService(val cs: CoroutineScope) {
}
val direnvScope get() = application.service<DirenvService>().cs

View file

@ -0,0 +1,55 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.direnv
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.toNioPathOrNull
import com.intellij.util.EnvironmentUtil
import org.jetbrains.annotations.NonNls
import java.io.File
import java.nio.file.Path
import kotlin.io.path.*
data class Env(val env: Map<String, String>) {
private val path get() = getVariable("PATH")?.split(File.pathSeparatorChar)
private fun getVariable(name: @NonNls String) =
env.getOrElse(name) { EnvironmentUtil.getValue(name) }
fun findExecutableOnPATH(exe: @NonNls String): Path? {
val exeName = if (SystemInfo.isWindows) "$exe.exe" else exe
val paths = path ?: return null
for (dir in paths) {
val path = dir.toNioPathOrNull()?.absolute() ?: continue
if (path.notExists() || !path.isDirectory())
continue
val exePath = path.resolve(exeName).absolute()
if (!exePath.isRegularFile() || !exePath.isExecutable())
continue
return exePath
}
return null
}
}
val emptyEnv = Env(emptyMap())

View file

@ -0,0 +1,36 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.shared
import com.intellij.openapi.options.Configurable
import com.intellij.ui.dsl.builder.Panel
import com.intellij.ui.dsl.builder.panel
import javax.swing.JComponent
interface NestedConfigurable: Configurable {
override fun createComponent() = panel {
createComponent(this)
}
fun createComponent(panel: Panel)
}

View file

@ -23,12 +23,13 @@
package com.falsepattern.zigbrains.zig
import com.falsepattern.zigbrains.Icons
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.intellij.openapi.fileTypes.LanguageFileType
object ZigFileType : LanguageFileType(ZigLanguage) {
override fun getName() = "Zig File"
override fun getDescription() = "ZigLang file"
override fun getDescription() = ZigBrainsBundle.message("zig.file.description")
override fun getDefaultExtension() = "zig"

View file

@ -157,7 +157,7 @@ private val ASTNode.treePrevNonSpace: ASTNode? get() {
private val normalIndent: Indent get() = Indent.getNormalIndent()
private fun spaceIndent(spaces: Int) = Indent.getSpaceIndent(2)
private fun spaceIndent(spaces: Int) = Indent.getSpaceIndent(spaces)
private val noneIndent: Indent get() = Indent.getNoneIndent()

View file

@ -23,11 +23,13 @@
package com.falsepattern.zigbrains.zig.highlighter
import com.falsepattern.zigbrains.Icons
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.options.colors.AttributesDescriptor
import com.intellij.openapi.options.colors.ColorDescriptor
import com.intellij.openapi.options.colors.ColorSettingsPage
import kotlinx.collections.immutable.toImmutableMap
import org.jetbrains.annotations.NonNls
class ZigColorSettingsPage: ColorSettingsPage {
@ -35,7 +37,7 @@ class ZigColorSettingsPage: ColorSettingsPage {
override fun getColorDescriptors(): Array<ColorDescriptor> = ColorDescriptor.EMPTY_ARRAY
override fun getDisplayName() = "Zig"
override fun getDisplayName() = ZigBrainsBundle.message("configurable.name.zig-color-settings-page")
override fun getIcon() = Icons.ZIG
@ -92,6 +94,7 @@ class ZigColorSettingsPage: ColorSettingsPage {
ADD_HIGHLIGHT
}
@Suppress("HardCodedStringLiteral")
private val ADD_HIGHLIGHT = HashMap<String, TextAttributesKey>().apply {
this["enum"] = ZigSyntaxHighlighter.ENUM_REF
this["enum_decl"] = ZigSyntaxHighlighter.ENUM_DECL
@ -113,50 +116,51 @@ private val ADD_HIGHLIGHT = HashMap<String, TextAttributesKey>().apply {
this["variable_decl"] = ZigSyntaxHighlighter.VARIABLE_DECL
}.toImmutableMap()
private val DESCRIPTORS: Array<AttributesDescriptor> = arrayOf(
AttributesDescriptor("Bad character", ZigSyntaxHighlighter.BAD_CHAR),
AttributesDescriptor("Builtin", ZigSyntaxHighlighter.BUILTIN),
AttributesDescriptor("Character literal", ZigSyntaxHighlighter.CHAR),
AttributesDescriptor("Comment//Regular", ZigSyntaxHighlighter.COMMENT),
AttributesDescriptor("Comment//Documentation", ZigSyntaxHighlighter.COMMENT_DOC),
AttributesDescriptor("Enum//Reference", ZigSyntaxHighlighter.ENUM_REF),
AttributesDescriptor("Enum//Declaration", ZigSyntaxHighlighter.ENUM_DECL),
AttributesDescriptor("Enum//Member//Declaration", ZigSyntaxHighlighter.ENUM_MEMBER_DECL),
AttributesDescriptor("Enum//Member//Reference", ZigSyntaxHighlighter.ENUM_MEMBER_REF),
AttributesDescriptor("Error tag//Declaration", ZigSyntaxHighlighter.ERROR_TAG_DECL),
AttributesDescriptor("Error tag//Reference", ZigSyntaxHighlighter.ERROR_TAG_REF),
AttributesDescriptor("Function//Declaration", ZigSyntaxHighlighter.FUNCTION_DECL),
AttributesDescriptor("Function//Declaration//Generic", ZigSyntaxHighlighter.FUNCTION_DECL_GEN),
AttributesDescriptor("Function//Reference", ZigSyntaxHighlighter.FUNCTION_REF),
AttributesDescriptor("Function//Reference//Generic", ZigSyntaxHighlighter.FUNCTION_REF_GEN),
AttributesDescriptor("Keyword", ZigSyntaxHighlighter.KEYWORD),
AttributesDescriptor("Label//Declaration", ZigSyntaxHighlighter.LABEL_REF),
AttributesDescriptor("Label//Reference", ZigSyntaxHighlighter.LABEL_REF),
AttributesDescriptor("Method//Declaration", ZigSyntaxHighlighter.METHOD_DECL),
AttributesDescriptor("Method//Declaration//Generic", ZigSyntaxHighlighter.METHOD_DECL_GEN),
AttributesDescriptor("Method//Reference", ZigSyntaxHighlighter.METHOD_REF),
AttributesDescriptor("Method//Reference//Generic", ZigSyntaxHighlighter.METHOD_REF_GEN),
AttributesDescriptor("Namespace//Declaration", ZigSyntaxHighlighter.NAMESPACE_DECL),
AttributesDescriptor("Namespace//Reference", ZigSyntaxHighlighter.NAMESPACE_REF),
AttributesDescriptor("Number", ZigSyntaxHighlighter.NUMBER),
AttributesDescriptor("Operator", ZigSyntaxHighlighter.OPERATOR),
AttributesDescriptor("Parameter", ZigSyntaxHighlighter.PARAMETER),
AttributesDescriptor("Property//Declaration", ZigSyntaxHighlighter.PROPERTY_DECL),
AttributesDescriptor("Property//Reference", ZigSyntaxHighlighter.PROPERTY_REF),
AttributesDescriptor("String", ZigSyntaxHighlighter.STRING),
AttributesDescriptor("String//Escape", ZigSyntaxHighlighter.STRING_ESC_V),
AttributesDescriptor("String//Escape//Invalid char", ZigSyntaxHighlighter.STRING_ESC_I_C),
AttributesDescriptor("String//Escape//Invalid unicode", ZigSyntaxHighlighter.STRING_ESC_I_U),
AttributesDescriptor("Struct//Declaration", ZigSyntaxHighlighter.STRUCT_DECL),
AttributesDescriptor("Struct//Reference", ZigSyntaxHighlighter.STRUCT_REF),
AttributesDescriptor("Type//Declaration", ZigSyntaxHighlighter.TYPE_DECL),
AttributesDescriptor("Type//Declaration//Generic", ZigSyntaxHighlighter.TYPE_DECL_GEN),
AttributesDescriptor("Type//Reference", ZigSyntaxHighlighter.TYPE_REF),
AttributesDescriptor("Type//Reference//Generic", ZigSyntaxHighlighter.TYPE_REF_GEN),
AttributesDescriptor("Type parameter//Reference", ZigSyntaxHighlighter.TYPE_PARAM),
AttributesDescriptor("Type parameter//Declaration", ZigSyntaxHighlighter.TYPE_PARAM_DECL),
AttributesDescriptor("Variable//Declaration", ZigSyntaxHighlighter.VARIABLE_DECL),
AttributesDescriptor("Variable//Declaration//Deprecated", ZigSyntaxHighlighter.VARIABLE_DECL_DEPR),
AttributesDescriptor("Variable//Reference", ZigSyntaxHighlighter.VARIABLE_REF),
AttributesDescriptor("Variable//Reference//Deprecated", ZigSyntaxHighlighter.VARIABLE_REF_DEPR),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.builtin"), ZigSyntaxHighlighter.BUILTIN),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.char"), ZigSyntaxHighlighter.CHAR),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.comment"), ZigSyntaxHighlighter.COMMENT),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.comment-doc"), ZigSyntaxHighlighter.COMMENT_DOC),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.enum-ref"), ZigSyntaxHighlighter.ENUM_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.enum-decl"), ZigSyntaxHighlighter.ENUM_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.enum-member-decl"), ZigSyntaxHighlighter.ENUM_MEMBER_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.enum-member-ref"), ZigSyntaxHighlighter.ENUM_MEMBER_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.error-tag-decl"), ZigSyntaxHighlighter.ERROR_TAG_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.error-tag-ref"), ZigSyntaxHighlighter.ERROR_TAG_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.function-decl"), ZigSyntaxHighlighter.FUNCTION_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.function-decl-gen"), ZigSyntaxHighlighter.FUNCTION_DECL_GEN),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.function-ref"), ZigSyntaxHighlighter.FUNCTION_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.function-ref-gen"), ZigSyntaxHighlighter.FUNCTION_REF_GEN),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.keyword"), ZigSyntaxHighlighter.KEYWORD),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.label-decl"), ZigSyntaxHighlighter.LABEL_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.label-ref"), ZigSyntaxHighlighter.LABEL_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.method-decl"), ZigSyntaxHighlighter.METHOD_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.method-decl-gen"), ZigSyntaxHighlighter.METHOD_DECL_GEN),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.method-ref"), ZigSyntaxHighlighter.METHOD_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.method-ref-gen"), ZigSyntaxHighlighter.METHOD_REF_GEN),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.namespace-decl"), ZigSyntaxHighlighter.NAMESPACE_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.namespace-ref"), ZigSyntaxHighlighter.NAMESPACE_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.number"), ZigSyntaxHighlighter.NUMBER),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.operator"), ZigSyntaxHighlighter.OPERATOR),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.parameter"), ZigSyntaxHighlighter.PARAMETER),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.property-decl"), ZigSyntaxHighlighter.PROPERTY_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.property-ref"), ZigSyntaxHighlighter.PROPERTY_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.string"), ZigSyntaxHighlighter.STRING),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.string-esc-v"), ZigSyntaxHighlighter.STRING_ESC_V),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.string-esc-i-c"), ZigSyntaxHighlighter.STRING_ESC_I_C),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.string-esc-i-u"), ZigSyntaxHighlighter.STRING_ESC_I_U),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.struct-decl"), ZigSyntaxHighlighter.STRUCT_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.struct-ref"), ZigSyntaxHighlighter.STRUCT_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.type-decl"), ZigSyntaxHighlighter.TYPE_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.type-decl-gen"), ZigSyntaxHighlighter.TYPE_DECL_GEN),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.type-ref"), ZigSyntaxHighlighter.TYPE_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.type-ref-gen"), ZigSyntaxHighlighter.TYPE_REF_GEN),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.type-param"), ZigSyntaxHighlighter.TYPE_PARAM),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.type-param-decl"), ZigSyntaxHighlighter.TYPE_PARAM_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.variable-decl"), ZigSyntaxHighlighter.VARIABLE_DECL),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.variable-decl-depr"), ZigSyntaxHighlighter.VARIABLE_DECL_DEPR),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.variable-ref"), ZigSyntaxHighlighter.VARIABLE_REF),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.variable-ref-depr"), ZigSyntaxHighlighter.VARIABLE_REF_DEPR),
AttributesDescriptor(ZigBrainsBundle.message("zig.color-settings.bad-char"), ZigSyntaxHighlighter.BAD_CHAR),
)

View file

@ -31,6 +31,7 @@ import com.intellij.openapi.fileTypes.SyntaxHighlighterBase
import com.intellij.psi.StringEscapesTokenTypes
import com.intellij.psi.TokenType
import com.intellij.psi.tree.IElementType
import org.jetbrains.annotations.NonNls
class ZigSyntaxHighlighter: SyntaxHighlighterBase() {
override fun getHighlightingLexer() = ZigHighlightingLexer()
@ -38,6 +39,7 @@ class ZigSyntaxHighlighter: SyntaxHighlighterBase() {
override fun getTokenHighlights(tokenType: IElementType?) =
KEYMAP.getOrDefault(tokenType, EMPTY_KEYS)
@NonNls
companion object {
// @formatter:off
@ -99,7 +101,10 @@ class ZigSyntaxHighlighter: SyntaxHighlighterBase() {
KEYWORD,
*ZigTypes::class.java
.fields
.filter { it.name.startsWith("KEYWORD_") }
.filter {
@Suppress("HardCodedStringLiteral")
it.name.startsWith("KEYWORD_")
}
.map { it.get(null) as IElementType }
.toTypedArray()
)

View file

@ -35,6 +35,7 @@ import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.TextRange
import com.intellij.psi.AbstractElementManipulator
import com.intellij.psi.PsiFileFactory
import org.jetbrains.annotations.NonNls
class ZigStringElementManipulator: AbstractElementManipulator<ZigStringLiteral>() {
override fun handleContentChange(
@ -44,6 +45,7 @@ class ZigStringElementManipulator: AbstractElementManipulator<ZigStringLiteral>(
): ZigStringLiteral {
val originalContext = element.text!!
val isMultiline = element.isMultiline
@NonNls
val prefix = "const x = \n";
val suffix = "\n;"
val sbFactory: (Int) -> StringBuilder = {
@ -78,6 +80,7 @@ class ZigStringElementManipulator: AbstractElementManipulator<ZigStringLiteral>(
getTextRangeBounds(element.contentRanges)
}
@NonNls
private val fileName = "dummy." + ZigFileType.defaultExtension
private fun ZigStringElementManipulator.replaceQuotedContent(

View file

@ -22,6 +22,7 @@
package com.falsepattern.zigbrains.zig.intentions
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.falsepattern.zigbrains.zig.psi.ZigStringLiteral
import com.falsepattern.zigbrains.zig.psi.splitString
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
@ -34,7 +35,7 @@ class MakeStringMultiline: PsiElementBaseIntentionAction() {
init {
text = familyName
}
override fun getFamilyName() = "Convert to multiline"
override fun getFamilyName() = ZigBrainsBundle.message("intention.family.name.make-string-multiline")
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement) =
editor != null && element.parentOfType<ZigStringLiteral>()?.isMultiline?.not() ?: false

View file

@ -22,6 +22,7 @@
package com.falsepattern.zigbrains.zig.intentions
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.falsepattern.zigbrains.zig.psi.ZigStringLiteral
import com.falsepattern.zigbrains.zig.util.escape
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
@ -37,7 +38,7 @@ class MakeStringQuoted: PsiElementBaseIntentionAction() {
init {
text = familyName
}
override fun getFamilyName() = "Convert to quoted"
override fun getFamilyName() = ZigBrainsBundle.message("intention.family.name.make-string-quoted")
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement) =
editor != null && element.parentOfType<ZigStringLiteral>()?.isMultiline ?: false

View file

@ -96,11 +96,10 @@ val PsiElement.indentSize: Int get() = StringUtil.offsetToLineColumn(containingF
fun splitString(
editor: Editor,
psiAtOffset: PsiElement,
caretOffset: Int,
initialCaretOffset: Int,
insertNewlineAtCaret: Boolean
) {
@Suppress("NAME_SHADOWING")
var caretOffset = caretOffset
var caretOffset = initialCaretOffset
val document = editor.document
val token = psiAtOffset.node
val text = document.charsSequence

View file

@ -20,14 +20,18 @@
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
@file:Suppress("HardCodedStringLiteral")
package com.falsepattern.zigbrains.zig.util
import com.intellij.openapi.util.TextRange
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap
import org.jetbrains.annotations.NonNls
import java.util.regex.Pattern
import java.util.stream.Collectors
import kotlin.math.min
fun CharSequence.escape(): CharSequence {
val sb = StringBuilder(length)
this.codePoints().forEachOrdered {

View file

@ -23,12 +23,13 @@
package com.falsepattern.zigbrains.zon
import com.falsepattern.zigbrains.Icons
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.intellij.openapi.fileTypes.LanguageFileType
object ZonFileType: LanguageFileType(ZonLanguage) {
override fun getName() = "Zon File"
override fun getDescription() = "Zig object notation file"
override fun getDescription() = ZigBrainsBundle.message("zon.file.description")
override fun getDefaultExtension() = "zon"

View file

@ -36,6 +36,7 @@ import com.intellij.patterns.PsiElementPattern
import com.intellij.psi.PsiElement
import com.intellij.psi.util.parentOfType
import com.intellij.util.ProcessingContext
import org.jetbrains.annotations.NonNls
class ZonCompletionContributor : CompletionContributor() {
init {
@ -118,8 +119,10 @@ private typealias Processor = (
parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet
) -> Unit
@NonNls
private val ZON_ROOT_KEYS: List<String> =
listOf("name", "version", "minimum_zig_version", "dependencies", "paths")
@NonNls
private val ZON_DEP_KEYS: List<String> = listOf("url", "hash", "path", "lazy")
private fun doAddCompletions(

View file

@ -23,6 +23,7 @@
package com.falsepattern.zigbrains.zon.highlighting
import com.falsepattern.zigbrains.Icons
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.intellij.openapi.options.colors.AttributesDescriptor
import com.intellij.openapi.options.colors.ColorDescriptor
import com.intellij.openapi.options.colors.ColorSettingsPage
@ -32,7 +33,7 @@ class ZonColorSettingsPage: ColorSettingsPage {
override fun getColorDescriptors(): Array<ColorDescriptor> = ColorDescriptor.EMPTY_ARRAY
override fun getDisplayName() = "Zon"
override fun getDisplayName() = ZigBrainsBundle.message("configurable.name.zon-color-settings-page")
override fun getIcon() = Icons.ZON
@ -67,13 +68,13 @@ class ZonColorSettingsPage: ColorSettingsPage {
}
val DESCRIPTORS = arrayOf(
AttributesDescriptor("Equals", ZonSyntaxHighlighter.EQ),
AttributesDescriptor("Identifier", ZonSyntaxHighlighter.ID),
AttributesDescriptor("Comment", ZonSyntaxHighlighter.COMMENT),
AttributesDescriptor("Bad value", ZonSyntaxHighlighter.BAD_CHAR),
AttributesDescriptor("String", ZonSyntaxHighlighter.STRING),
AttributesDescriptor("Comma", ZonSyntaxHighlighter.COMMA),
AttributesDescriptor("Dot", ZonSyntaxHighlighter.DOT),
AttributesDescriptor("Boolean", ZonSyntaxHighlighter.BOOLEAN),
AttributesDescriptor("Braces", ZonSyntaxHighlighter.BRACE)
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.eq"), ZonSyntaxHighlighter.EQ),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.id"), ZonSyntaxHighlighter.ID),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.comment"), ZonSyntaxHighlighter.COMMENT),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.bad_char"), ZonSyntaxHighlighter.BAD_CHAR),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.string"), ZonSyntaxHighlighter.STRING),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.comma"), ZonSyntaxHighlighter.COMMA),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.dot"), ZonSyntaxHighlighter.DOT),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.boolean"), ZonSyntaxHighlighter.BOOLEAN),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.brace"), ZonSyntaxHighlighter.BRACE)
)

View file

@ -29,6 +29,7 @@ import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase
import com.intellij.psi.TokenType
import com.intellij.psi.tree.IElementType
import org.jetbrains.annotations.NonNls
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors as DefaultColors
class ZonSyntaxHighlighter : SyntaxHighlighterBase() {
@ -52,7 +53,7 @@ class ZonSyntaxHighlighter : SyntaxHighlighterBase() {
private val EMPTY_KEYS = emptyArray<TextAttributesKey>()
private val KEYMAP = HashMap<IElementType, Array<TextAttributesKey>>()
private fun createKey(name: String, fallback: TextAttributesKey) =
private fun createKey(name: @NonNls String, fallback: TextAttributesKey) =
TextAttributesKey.createTextAttributesKey("ZON_$name", fallback)
private fun addMapping(key: TextAttributesKey, vararg types: IElementType) = types.forEach { KEYMAP[it] = arrayOf(key) }

View file

@ -23,7 +23,8 @@
package com.falsepattern.zigbrains.zon.psi.mixins
import com.intellij.psi.PsiElement
import org.jetbrains.annotations.NonNls
interface ZonIdentifierMixin: PsiElement {
val value: String
val value: @NonNls String
}

View file

@ -0,0 +1,65 @@
notification.group.zigbrains-direnv=ZigBrains direnv
notification.title.direnv-blocked=Direnv not allowed
notification.content.direnv-blocked=Run `direnv allow in a terminal inside the project directory to allow ZigBrains to run direnv
notification.title.direnv-error=Direnv error
notification.content.direnv-error=Could not import direnv: {0}
intention.family.name.make-string-multiline=Convert to multiline
intention.family.name.make-string-quoted=Convert to quoted
zig.file.description=ZigLang file
configurable.name.zig-color-settings-page=Zig
zig.color-settings.bad-char=Bad character
zig.color-settings.builtin=Builtin
zig.color-settings.char=Character literal
zig.color-settings.comment=Comment//Regular
zig.color-settings.comment-doc=Comment//Documentation
zig.color-settings.enum-ref=Enum//Reference
zig.color-settings.enum-decl=Enum//Declaration
zig.color-settings.enum-member-decl=Enum//Member//Declaration
zig.color-settings.enum-member-ref=Enum//Member//Reference
zig.color-settings.error-tag-decl=Error tag//Declaration
zig.color-settings.error-tag-ref=Error tag//Reference
zig.color-settings.function-decl=Function//Declaration
zig.color-settings.function-decl-gen=Function//Declaration//Generic
zig.color-settings.function-ref=Function//Reference
zig.color-settings.function-ref-gen=Function//Reference//Generic
zig.color-settings.keyword=Keyword
zig.color-settings.label-decl=Label//Declaration
zig.color-settings.label-ref=Label//Reference
zig.color-settings.method-decl=Method//Declaration
zig.color-settings.method-decl-gen=Method//Declaration//Generic
zig.color-settings.method-ref=Method//Reference
zig.color-settings.method-ref-gen=Method//Reference//Generic
zig.color-settings.namespace-decl=Namespace//Declaration
zig.color-settings.namespace-ref=Namespace//Reference
zig.color-settings.number=Number
zig.color-settings.operator=Operator
zig.color-settings.parameter=Parameter
zig.color-settings.property-decl=Property//Declaration
zig.color-settings.property-ref=Property//Reference
zig.color-settings.string=String
zig.color-settings.string-esc-v=String//Escape
zig.color-settings.string-esc-i-c=String//Escape//Invalid char
zig.color-settings.string-esc-i-u=String//Escape//Invalid unicode
zig.color-settings.struct-decl=Struct//Declaration
zig.color-settings.struct-ref=Struct//Reference
zig.color-settings.type-decl=Type//Declaration
zig.color-settings.type-decl-gen=Type//Declaration//Generic
zig.color-settings.type-ref=Type//Reference
zig.color-settings.type-ref-gen=Type//Reference//Generic
zig.color-settings.type-param=Type parameter//Reference
zig.color-settings.type-param-decl=Type parameter//Declaration
zig.color-settings.variable-decl=Variable//Declaration
zig.color-settings.variable-decl-depr=Variable//Declaration//Deprecated
zig.color-settings.variable-ref=Variable//Reference
zig.color-settings.variable-ref-depr=Variable//Reference//Deprecated
zon.file.description=Zig object notation file
configurable.name.zon-color-settings-page=Zon
zon.color-settings.eq=Equals
zon.color-settings.id=Identifier
zon.color-settings.comment=Comment
zon.color-settings.bad_char=Bad value
zon.color-settings.string=String
zon.color-settings.comma=Comma
zon.color-settings.dot=Dot
zon.color-settings.boolean=Boolean
zon.color-settings.brace=Braces

View file

@ -96,4 +96,13 @@
</extensions>
<!-- endregion Zon -->
<!-- region direnv -->
<extensions defaultExtensionNs="com.intellij">
<notificationGroup displayType="BALLOON"
id="zigbrains-direnv"
bundle="zigbrains.Bundle"
key="notification.group.zigbrains-direnv"/>
</extensions>
<!-- endregion direnv -->
</idea-plugin>