Skip to content

Commit

Permalink
install both "godot-tools" and "godot-files", unfortunately they don'…
Browse files Browse the repository at this point in the history
…t play nice with each other, godot-tools gets preference
  • Loading branch information
van800 committed Jan 12, 2024
1 parent d4e047b commit 00cbb06
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 27 deletions.
42 changes: 25 additions & 17 deletions rider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,20 @@ apply {
}

val baseVersion = "2024.1"
var godotVscodePluginVersion = "1.3.1" // https://github.com/godotengine/godot-vscode-plugin/releases

// alternative val url = URL("https://marketplace.visualstudio.com/_apis/public/gallery/publishers/geequlim/vsextensions/godot-tools/$godotVscodePluginVersion/vspackage")
// https://github.com/godotengine/godot-vscode-plugin/releases/download
val cachedLink = "https://cache-redirector.jetbrains.com/github.com/godotengine/godot-vscode-plugin/releases/download"
data class PluginDescription(val name: String, val url: String)

val godotVscodePluginVersion = "1.3.1" // https://github.com/godotengine/godot-vscode-plugin/releases
val alfishPluginVerion = "0.0.7" // https://github.com/AlfishSoftware/godot-files-vscode/releases/download/v0.0.7/alfish.godot-files-0.0.7.vsix

val plugins = listOf(
PluginDescription("godot-tools", "https://cache-redirector.jetbrains.com/github.com/godotengine/godot-vscode-plugin/releases/download/$godotVscodePluginVersion/godot-tools-$godotVscodePluginVersion.vsix"),
PluginDescription("godot-files", "https://github.com/AlfishSoftware/godot-files-vscode/releases/download/v$alfishPluginVerion/alfish.godot-files-$alfishPluginVerion.vsix")
)

val buildCounter = ext.properties["build.number"] ?: "9999"
version = "$baseVersion.$buildCounter"

Expand Down Expand Up @@ -106,13 +119,8 @@ fun File.writeTextIfChanged(content: String) {
}
}

fun download(temp:File){
// alternative val url = URL("https://marketplace.visualstudio.com/_apis/public/gallery/publishers/geequlim/vsextensions/godot-tools/$godotVscodePluginVersion/vspackage")

// https://github.com/godotengine/godot-vscode-plugin/releases/download
val cachedLink = "https://cache-redirector.jetbrains.com/github.com/godotengine/godot-vscode-plugin/releases/download"
val url = URL("$cachedLink/$godotVscodePluginVersion/godot-tools-$godotVscodePluginVersion.vsix")

fun download(temp:File, spec:String){
val url = URL(spec)
val connection = url.openConnection()
connection.setRequestProperty(
"User-Agent",
Expand Down Expand Up @@ -223,22 +231,22 @@ tasks {
from("../resharper/src/annotations")
}

val configDir = destinationDir.resolve(File("${intellij.pluginName.get()}/godot-tools"))

doLast {
files.forEach {
val file = file(it)
if (!file.exists()) throw RuntimeException("File $file does not exist")
logger.warn("$name: ${file.name} -> $destinationDir/${intellij.pluginName.get()}/dotnet")
}

logger.lifecycle("downloading godot-tools TextMate bundle")
val temp = FileUtil.createTempFile("godot-tools", ".tmp")
download(temp)

FileUtil.createDirectory(configDir)
logger.lifecycle("Unzipping ${temp.path} to $configDir")
unzipTo(configDir, temp)
logger.lifecycle("downloading TextMate bundles")
plugins.forEach {
val configDir = destinationDir.resolve(intellij.pluginName.get()).resolve("bundles").resolve(it.name)
val temp = FileUtil.createTempFile("download", ".tmp")
download(temp, it.url)
FileUtil.createDirectory(configDir)
logger.lifecycle("Unzipping ${temp.path} to $configDir")
unzipTo(configDir, temp)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
package com.jetbrains.rider.plugins.godot.textMate

import com.intellij.openapi.application.PathManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import org.jetbrains.plugins.textmate.TextMateService
import org.jetbrains.plugins.textmate.actions.Plugin
import org.jetbrains.plugins.textmate.configuration.TextMateUserBundlesSettings
import kotlin.io.path.pathString
import java.io.FileFilter

class TextmateActivator : ProjectActivity {

private val logger = Logger.getInstance(TextmateActivator::class.java)
override suspend fun execute(project: Project) {
val extensionDir = PathManager.getPluginsDir().resolve("rider-godot").resolve("godot-tools").resolve("extension")
val settings = TextMateUserBundlesSettings.instance ?: return
val directories = PathManager.getPluginsDir().resolve("rider-godot").resolve("bundles").toFile()
.listFiles(FileFilter { it.isDirectory })?.toSortedSet()?.sorted()?: return
directories.forEach {
if (it != null && it.isDirectory) {
val extensionDir = it.resolve("extension")
if (extensionDir.exists() && !settings.bundles.any { bundle-> bundle.key == extensionDir.path }) {
val plugin = Plugin(it.name, "", "")

// workaround for IDEA-342823 Apply 2 textmate bundles
// ".gdshader", ".gdshaderinc", "*.gdshader", "*.gdshaderinc"
if (it.name == "godot-tools") {
val packageJson = extensionDir.resolve("package.json")
if (packageJson.exists()) {
val text = packageJson.readText()
.replace("\".gdshader\"", "\".gdshader2\"")
.replace("\".gdshaderinc\"", "\".gdshaderinc2\"")
.replace("\"*.gdshader\"", "\"*.gdshader2\"")
.replace("\"*.gdshader\"", "\"*.gdshader2\"")

packageJson.writeText(text)
}
}
// end workaround

if (!settings.bundles.any { it.key == extensionDir.pathString }) {
logger.info("Attempt to apply Textmate bundle $extensionDir")
val plugin = Plugin("godot-tools", "geequlim", "")
TextMateUserBundlesSettings.instance!!.addBundle(extensionDir.pathString, plugin.toString())
TextMateService.getInstance().reloadEnabledBundles()
TextMateUserBundlesSettings.instance!!.addBundle(extensionDir.path, plugin.toString())
TextMateService.getInstance().reloadEnabledBundles()
}
}
}
}
}

0 comments on commit 00cbb06

Please sign in to comment.