From 40d6b84a3fa360e29658da71a9c557ac5cf7923d Mon Sep 17 00:00:00 2001 From: RedNesto Date: Thu, 1 Aug 2024 17:29:01 +0200 Subject: [PATCH] Add missing license and fix style --- .../ModsTomlCompletionContributor.kt | 12 +++++++--- .../toml/toml/TomlKeyInsertionHandler.kt | 22 ++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/toml/platform/forge/completion/ModsTomlCompletionContributor.kt b/src/main/kotlin/toml/platform/forge/completion/ModsTomlCompletionContributor.kt index c41653703..d670e7e45 100644 --- a/src/main/kotlin/toml/platform/forge/completion/ModsTomlCompletionContributor.kt +++ b/src/main/kotlin/toml/platform/forge/completion/ModsTomlCompletionContributor.kt @@ -104,25 +104,31 @@ object ModsTomlKeyCompletionProvider : CompletionProvider( val existingKeys = table.entries.mapTo(HashSet()) { it.key.text } schema.topLevelEntries(isArray).filter { it.key !in existingKeys } } + is TomlKeyValue -> when (table) { null -> { val existingKeys = key.containingFile.children.filterIsInstance().mapTo(HashSet()) { it.key.text } schema.topLevelEntries.filter { it.key !in existingKeys } } + is TomlHeaderOwner -> { val tableName = table.header.key?.segments?.firstOrNull()?.text ?: return val existingKeys = table.entries.mapTo(HashSet()) { it.key.text } schema.entriesForTable(tableName).filter { it.key !in existingKeys } } + else -> return } + else -> return } - result.addAllElements(variants.map { entry -> - LookupElementBuilder.create(entry, entry.key).withInsertHandler(TomlKeyInsertionHandler(keyValue)) - }) + result.addAllElements( + variants.map { entry -> + LookupElementBuilder.create(entry, entry.key).withInsertHandler(TomlKeyInsertionHandler(keyValue)) + } + ) } } diff --git a/src/main/kotlin/toml/toml/TomlKeyInsertionHandler.kt b/src/main/kotlin/toml/toml/TomlKeyInsertionHandler.kt index c69caddd9..e06ee50ea 100644 --- a/src/main/kotlin/toml/toml/TomlKeyInsertionHandler.kt +++ b/src/main/kotlin/toml/toml/TomlKeyInsertionHandler.kt @@ -1,3 +1,23 @@ +/* + * Minecraft Development for IntelliJ + * + * https://mcdev.io/ + * + * Copyright (C) 2024 minecraft-dev + * + * This program 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, version 3.0 only. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + package com.demonwav.mcdev.toml.toml import com.intellij.codeInsight.AutoPopupController @@ -17,7 +37,7 @@ class TomlKeyInsertionHandler(private val keyValue: TomlKeyValue) : InsertHandle context.document.insertString(context.tailOffset, " = ") PsiDocumentManager.getInstance(context.project).commitDocument(context.document) context.editor.caretModel.moveToOffset(context.tailOffset) // The tail offset is tracked automatically - AutoPopupController.getInstance(context.project).scheduleAutoPopup(context.editor); + AutoPopupController.getInstance(context.project).scheduleAutoPopup(context.editor) } } }