diff --git a/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandPartNodes.kt b/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandPartNodes.kt index 8b2339ffbbaf..7d4c88c202d1 100644 --- a/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandPartNodes.kt +++ b/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandPartNodes.kt @@ -6,7 +6,7 @@ import org.jetbrains.terminal.completion.ShellCommand import org.jetbrains.terminal.completion.ShellCommandParserDirectives import org.jetbrains.terminal.completion.ShellOption -abstract class CommandPartNode(val text: String, open val spec: T?, val parent: CommandPartNode<*>?) { +internal abstract class CommandPartNode(val text: String, open val spec: T?, val parent: CommandPartNode<*>?) { val children: MutableList> = mutableListOf() override fun toString(): String { @@ -14,7 +14,7 @@ abstract class CommandPartNode(val text: String, open val spec: T?, val paren } } -class SubcommandNode(text: String, +internal class SubcommandNode(text: String, override val spec: ShellCommand, parent: CommandPartNode<*>?) : CommandPartNode(text, spec, parent) { fun getMergedParserDirectives(): ShellCommandParserDirectives { @@ -37,12 +37,12 @@ class SubcommandNode(text: String, } } -class OptionNode(text: String, +internal class OptionNode(text: String, override val spec: ShellOption, parent: CommandPartNode<*>?) : CommandPartNode(text, spec, parent) -class ArgumentNode(text: String, +internal class ArgumentNode(text: String, override val spec: ShellArgument, parent: CommandPartNode<*>?) : CommandPartNode(text, spec, parent) -class UnknownNode(text: String, parent: CommandPartNode<*>?) : CommandPartNode(text, null, parent) \ No newline at end of file +internal class UnknownNode(text: String, parent: CommandPartNode<*>?) : CommandPartNode(text, null, parent) \ No newline at end of file diff --git a/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandSpecCompletionUtil.kt b/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandSpecCompletionUtil.kt new file mode 100644 index 000000000000..cc8932e30f7a --- /dev/null +++ b/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandSpecCompletionUtil.kt @@ -0,0 +1,13 @@ +package com.intellij.terminal.completion + +import org.jetbrains.terminal.completion.ShellArgument + +object CommandSpecCompletionUtil { + fun ShellArgument.isFilePath(): Boolean = isWithTemplate("filepaths") + + fun ShellArgument.isFolder(): Boolean = isWithTemplate("folders") + + private fun ShellArgument.isWithTemplate(template: String): Boolean { + return templates.contains(template) || generators.any { it.templates.contains(template) } + } +} \ No newline at end of file diff --git a/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandTreeBuilder.kt b/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandTreeBuilder.kt index 7ec065e2a792..7f02ec27f794 100644 --- a/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandTreeBuilder.kt +++ b/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandTreeBuilder.kt @@ -7,7 +7,7 @@ import org.jetbrains.terminal.completion.BaseSuggestion import org.jetbrains.terminal.completion.ShellCommand import org.jetbrains.terminal.completion.ShellOption -class CommandTreeBuilder private constructor( +internal class CommandTreeBuilder private constructor( private val suggestionsProvider: CommandTreeSuggestionsProvider, private val commandSpecManager: CommandSpecManager, private val arguments: List diff --git a/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandTreeSuggestionsProvider.kt b/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandTreeSuggestionsProvider.kt index 07e6aa7fca1b..8ccfee6d7415 100644 --- a/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandTreeSuggestionsProvider.kt +++ b/plugins/terminal/completion/src/com/intellij/terminal/completion/CommandTreeSuggestionsProvider.kt @@ -1,12 +1,14 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.terminal.completion +import com.intellij.terminal.completion.CommandSpecCompletionUtil.isFilePath +import com.intellij.terminal.completion.CommandSpecCompletionUtil.isFolder import org.jetbrains.terminal.completion.BaseSuggestion import org.jetbrains.terminal.completion.ShellArgument import org.jetbrains.terminal.completion.ShellOption import org.jetbrains.terminal.completion.ShellSuggestion -class CommandTreeSuggestionsProvider(private val runtimeDataProvider: ShellRuntimeDataProvider) { +internal class CommandTreeSuggestionsProvider(private val runtimeDataProvider: ShellRuntimeDataProvider) { suspend fun getSuggestionsOfNext(node: CommandPartNode<*>, nextNodeText: String): List { return when (node) { is SubcommandNode -> getSuggestionsForSubcommand(node, nextNodeText) @@ -134,14 +136,4 @@ class CommandTreeSuggestionsProvider(private val runtimeDataProvider: ShellRunti .let { if (basePath != ".") it.plus(ShellArgumentSuggestion(ShellSuggestion(names = listOf("")), arg)) else it } .toList() } - - companion object { - fun ShellArgument.isFilePath(): Boolean = isWithTemplate("filepaths") - - fun ShellArgument.isFolder(): Boolean = isWithTemplate("folders") - - private fun ShellArgument.isWithTemplate(template: String): Boolean { - return templates.contains(template) || generators.any { it.templates.contains(template) } - } - } } \ No newline at end of file diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/exp/completion/CommandSpecCompletionWeigher.kt b/plugins/terminal/src/org/jetbrains/plugins/terminal/exp/completion/CommandSpecCompletionWeigher.kt index 9cfd34109d1c..ecfa07394960 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/exp/completion/CommandSpecCompletionWeigher.kt +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/exp/completion/CommandSpecCompletionWeigher.kt @@ -4,8 +4,8 @@ package org.jetbrains.plugins.terminal.exp.completion import com.intellij.codeInsight.completion.CompletionLocation import com.intellij.codeInsight.completion.CompletionWeigher import com.intellij.codeInsight.lookup.LookupElement -import com.intellij.terminal.completion.CommandTreeSuggestionsProvider.Companion.isFilePath -import com.intellij.terminal.completion.CommandTreeSuggestionsProvider.Companion.isFolder +import com.intellij.terminal.completion.CommandSpecCompletionUtil.isFilePath +import com.intellij.terminal.completion.CommandSpecCompletionUtil.isFolder import com.intellij.terminal.completion.ShellArgumentSuggestion import org.jetbrains.terminal.completion.BaseSuggestion import org.jetbrains.terminal.completion.ShellCommand