feat: live templates

This commit is contained in:
FalsePattern 2025-01-21 15:38:54 +01:00
parent 993930fa99
commit dcce9a8b28
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
4 changed files with 60 additions and 1 deletions

View file

@ -17,6 +17,11 @@ Changelog structure reference:
## [Unreleased]
### Added
- Zig
- Live template support
## [20.1.3]
### Added

View file

@ -0,0 +1,48 @@
/*
* 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.zig.codeInsight
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.falsepattern.zigbrains.zig.psi.ZigFile
import com.falsepattern.zigbrains.zig.psi.ZigTypes
import com.intellij.codeInsight.template.TemplateActionContext
import com.intellij.codeInsight.template.TemplateContextType
import com.intellij.psi.util.elementType
class ZigContext: TemplateContextType(ZigBrainsBundle.message("zig")) {
override fun isInContext(templateActionContext: TemplateActionContext): Boolean {
val file = templateActionContext.file
val offset = templateActionContext.startOffset
if (file !is ZigFile)
return false
val element = file.findElementAt(offset) ?: return true
return when (element.elementType) {
ZigTypes.LINE_COMMENT, ZigTypes.CONTAINER_DOC_COMMENT, ZigTypes.DOC_COMMENT -> false
ZigTypes.STRING_LITERAL_SINGLE, ZigTypes.STRING_LITERAL_MULTI -> false
else -> true
}
}
}

View file

@ -170,6 +170,11 @@
icon="/icons/zig_build_tool.svg"
id="zigbrains.build"
/>
<liveTemplateContext
contextId="ZIG"
implementation="com.falsepattern.zigbrains.zig.codeInsight.ZigContext"
/>
</extensions>
<extensions defaultExtensionNs="com.falsepattern.zigbrains">

View file

@ -114,4 +114,5 @@ build.tool.window.status.loading=Running zig build -l
build.tool.window.status.error.missing-build-zig=No build.zig file found
build.tool.window.status.error.missing-toolchain=No zig toolchain configured
build.tool.window.status.error.general=Error while running zig build -l
build.tool.window.status.timeout=zig build -l timed out after {0} seconds.
build.tool.window.status.timeout=zig build -l timed out after {0} seconds.
zig=Zig