Skip to content

Commit

Permalink
Add missing license and fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Aug 1, 2024
1 parent f3d3406 commit 40d6b84
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,31 @@ object ModsTomlKeyCompletionProvider : CompletionProvider<CompletionParameters>(
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<TomlKeyValue>().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))
}
)
}
}

Expand Down
22 changes: 21 additions & 1 deletion src/main/kotlin/toml/toml/TomlKeyInsertionHandler.kt
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

package com.demonwav.mcdev.toml.toml

import com.intellij.codeInsight.AutoPopupController
Expand All @@ -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)
}
}
}

0 comments on commit 40d6b84

Please sign in to comment.