mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
gradle: configurations completion
This commit is contained in:
+41
-23
@@ -21,12 +21,13 @@ import com.intellij.patterns.PlatformPatterns.psiElement
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.util.ProcessingContext
|
||||
import icons.GradleIcons
|
||||
import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames.GRADLE_API_CONFIGURATION
|
||||
import org.jetbrains.plugins.gradle.service.resolve.GradleDependenciesContributor.Companion.dependenciesClosure
|
||||
import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames.*
|
||||
import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributor
|
||||
import org.jetbrains.plugins.groovy.dsl.holders.NonCodeMembersHolder
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightVariable
|
||||
import org.jetbrains.plugins.groovy.lang.psi.patterns.groovyClosure
|
||||
import org.jetbrains.plugins.groovy.lang.psi.patterns.psiMethod
|
||||
import java.lang.Double.MAX_VALUE
|
||||
|
||||
/**
|
||||
@@ -34,34 +35,51 @@ import java.lang.Double.MAX_VALUE
|
||||
* @since 12/7/2016
|
||||
*/
|
||||
class ConfigurationsCompletionContributor : AbstractGradleCompletionContributor() {
|
||||
init {
|
||||
extend(CompletionType.BASIC, PLACE_PATTERN, object : CompletionProvider<CompletionParameters>() {
|
||||
override fun addCompletions(params: CompletionParameters,
|
||||
context: ProcessingContext,
|
||||
result: CompletionResultSet) {
|
||||
val position = params.position
|
||||
val extensionsData = GradleExtensionsContributor.getExtensionsFor(position) ?: return
|
||||
for (configuration in extensionsData.configurations) {
|
||||
val confVar = object : GrLightVariable(position.manager, configuration.name, GRADLE_API_CONFIGURATION, position) {
|
||||
override fun getNavigationElement(): PsiElement {
|
||||
val navigationElement = super.getNavigationElement()
|
||||
navigationElement.putUserData(NonCodeMembersHolder.DOCUMENTATION, configuration.description)
|
||||
return navigationElement
|
||||
}
|
||||
|
||||
class ConfigurationsCompletionProvider(val isScriptClasspath: Boolean = false) : CompletionProvider<CompletionParameters>() {
|
||||
|
||||
override fun addCompletions(params: CompletionParameters,
|
||||
context: ProcessingContext,
|
||||
result: CompletionResultSet) {
|
||||
val position = params.position
|
||||
val extensionsData = GradleExtensionsContributor.getExtensionsFor(position) ?: return
|
||||
for (configuration in extensionsData.configurations) {
|
||||
if (isScriptClasspath != configuration.scriptClasspath) continue
|
||||
|
||||
val confVar = object : GrLightVariable(position.manager, configuration.name, GRADLE_API_CONFIGURATION, position) {
|
||||
override fun getNavigationElement(): PsiElement {
|
||||
val navigationElement = super.getNavigationElement()
|
||||
val description = if (isScriptClasspath && configuration.description == null) DEFAULT_SCRIPT_CLASSPATH_DESCRIPTION else configuration.description
|
||||
navigationElement.putUserData(NonCodeMembersHolder.DOCUMENTATION, description)
|
||||
return navigationElement
|
||||
}
|
||||
val elementBuilder = LookupElementBuilder.create(confVar, configuration.name)
|
||||
.withIcon(GradleIcons.Gradle)
|
||||
.withTypeText("Configuration")
|
||||
result.addElement(PrioritizedLookupElement.withPriority(elementBuilder, MAX_VALUE))
|
||||
}
|
||||
val elementBuilder = LookupElementBuilder.create(confVar, configuration.name)
|
||||
.withIcon(GradleIcons.Gradle)
|
||||
.withTypeText("Configuration")
|
||||
result.addElement(PrioritizedLookupElement.withPriority(elementBuilder, MAX_VALUE))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
extend(CompletionType.BASIC, PROJECT_DEPENDENCIES_PLACE_PATTERN, ConfigurationsCompletionProvider())
|
||||
extend(CompletionType.BASIC, SCRIPT_DEPENDENCIES_PLACE_PATTERN, ConfigurationsCompletionProvider(true))
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val PLACE_PATTERN = psiElement()
|
||||
|
||||
private val DEFAULT_SCRIPT_CLASSPATH_DESCRIPTION = "The script classpath configuration used to compile and execute a build script. " +
|
||||
"This classpath is also used to load the plugins which the build script uses."
|
||||
|
||||
private val PROJECT_DEPENDENCIES_PLACE_PATTERN = psiElement()
|
||||
.and(GRADLE_FILE_PATTERN)
|
||||
.withParent(GrReferenceExpression::class.java)
|
||||
.withAncestor(4, dependenciesClosure)
|
||||
.withAncestor(4, groovyClosure().inMethod(psiMethod(GRADLE_API_PROJECT, "dependencies")))
|
||||
|
||||
private val SCRIPT_DEPENDENCIES_PLACE_PATTERN = psiElement()
|
||||
.and(GRADLE_FILE_PATTERN)
|
||||
.withParent(GrReferenceExpression::class.java)
|
||||
.withAncestor(4, groovyClosure().inMethod(psiMethod(GRADLE_API_SCRIPT_HANDLER, "dependencies")))
|
||||
}
|
||||
}
|
||||
@@ -148,6 +148,7 @@ public class GradleExtensionsSettings implements PersistentStateComponent<Gradle
|
||||
gradleConfiguration.name = configuration.getName();
|
||||
gradleConfiguration.description = configuration.getDescription();
|
||||
gradleConfiguration.visible = configuration.isVisible();
|
||||
gradleConfiguration.scriptClasspath = configuration.isScriptClasspathConfiguration();
|
||||
extensionsData.configurations.add(gradleConfiguration);
|
||||
}
|
||||
gradleProject.extensions.put(entry.getKey(), extensionsData);
|
||||
@@ -299,6 +300,8 @@ public class GradleExtensionsSettings implements PersistentStateComponent<Gradle
|
||||
public String name;
|
||||
@Attribute("visible")
|
||||
public boolean visible = true;
|
||||
@Attribute("scriptClasspath")
|
||||
public boolean scriptClasspath;
|
||||
@Text
|
||||
public String description;
|
||||
}
|
||||
|
||||
+4
-1
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.plugins.gradle.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -27,8 +28,10 @@ public interface GradleConfiguration extends Serializable {
|
||||
@NotNull
|
||||
String getName();
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
String getDescription();
|
||||
|
||||
boolean isVisible();
|
||||
|
||||
boolean isScriptClasspathConfiguration();
|
||||
}
|
||||
|
||||
+15
-2
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.plugins.gradle.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
@@ -26,15 +27,22 @@ public class DefaultGradleConfiguration implements GradleConfiguration {
|
||||
private String myName;
|
||||
private String myDescription;
|
||||
private boolean myVisible;
|
||||
private boolean myScriptClasspathConfiguration;
|
||||
|
||||
public DefaultGradleConfiguration(String name, String description, boolean visible) {
|
||||
this(name, description, visible, false);
|
||||
}
|
||||
|
||||
public DefaultGradleConfiguration(@NotNull String name, @Nullable String description, boolean visible, boolean scriptClasspathConfiguration) {
|
||||
myName = name;
|
||||
myDescription = description;
|
||||
myVisible = visible;
|
||||
myScriptClasspathConfiguration = scriptClasspathConfiguration;
|
||||
}
|
||||
|
||||
public DefaultGradleConfiguration(GradleConfiguration configuration) {
|
||||
this(configuration.getName(), configuration.getDescription(), configuration.isVisible());
|
||||
this(configuration.getName(), configuration.getDescription(), configuration.isVisible(),
|
||||
configuration.isScriptClasspathConfiguration());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -43,7 +51,7 @@ public class DefaultGradleConfiguration implements GradleConfiguration {
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return myDescription;
|
||||
@@ -53,4 +61,9 @@ public class DefaultGradleConfiguration implements GradleConfiguration {
|
||||
public boolean isVisible() {
|
||||
return myVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isScriptClasspathConfiguration() {
|
||||
return myScriptClasspathConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -43,6 +43,9 @@ class ProjectExtensionsDataBuilderImpl implements ModelBuilderService {
|
||||
for (it in project.configurations) {
|
||||
result.configurations.add(new DefaultGradleConfiguration(it.name, it.description, it.visible))
|
||||
}
|
||||
for (it in project.buildscript.configurations) {
|
||||
result.configurations.add(new DefaultGradleConfiguration(it.name, it.description, it.visible, true))
|
||||
}
|
||||
|
||||
def conventions = project.extensions as DefaultConvention
|
||||
conventions.extraProperties.properties.each { name, value ->
|
||||
|
||||
Reference in New Issue
Block a user