Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Do not generate debug messages if debug is off.
Browse files Browse the repository at this point in the history
Minor improvement in TerraformConfigCompletionContributor
  • Loading branch information
VladRassokhin committed Mar 10, 2017
1 parent a4cdace commit 604bf19
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<root>
<item name='com.intellij.openapi.diagnostic.Logger void debug(java.lang.String)'>
<annotation name='java.lang.Deprecated'/>
</item>
<item name='com.intellij.openapi.diagnostic.Logger void debug(java.lang.String, java.lang.Object...)'>
<annotation name='java.lang.Deprecated'/>
</item>
<item name='com.intellij.openapi.diagnostic.Logger void debug(java.lang.String, java.lang.Throwable)'>
<annotation name='java.lang.Deprecated'/>
</item>
<item name='com.intellij.openapi.diagnostic.Logger void debug(java.lang.Throwable)'>
<annotation name='java.lang.Deprecated'/>
</item>
</root>
2 changes: 2 additions & 0 deletions src/kotlin/org/intellij/plugins/hcl/HCLParserDefinition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ open class HCLParserDefinition : ParserDefinition {
val WHITE_SPACES: TokenSet = TokenSet.create(TokenType.WHITE_SPACE)
val STRING_LITERALS: TokenSet = TokenSet.create(SINGLE_QUOTED_STRING, DOUBLE_QUOTED_STRING)

val IDENTIFYING_LITERALS: TokenSet = TokenSet.create(SINGLE_QUOTED_STRING, DOUBLE_QUOTED_STRING, ID)

val FILE: IFileElementType = IFileElementType(HCLLanguage)

val HCL_BRACES: TokenSet = TokenSet.create(L_CURLY, R_CURLY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.intellij.psi.impl.DebugUtil
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.ProcessingContext
import com.intellij.util.SmartList
import org.intellij.plugins.debug
import org.intellij.plugins.hcl.HCLElementTypes
import org.intellij.plugins.hcl.HCLParserDefinition
import org.intellij.plugins.hcl.codeinsight.HCLCompletionContributor
Expand Down Expand Up @@ -284,7 +285,7 @@ public class TerraformConfigCompletionContributor : HCLCompletionContributor() {
val position = parameters.position
val parent = position.parent
val leftNWS = position.getPrevSiblingNonWhiteSpace()
LOG.debug("TF.BlockKeywordCompletionProvider{position=$position, parent=$parent, left=${position.prevSibling}, lnws=$leftNWS}")
LOG.debug { "TF.BlockKeywordCompletionProvider{position=$position, parent=$parent, left=${position.prevSibling}, lnws=$leftNWS}" }
if (leftNWS is HCLIdentifier || leftNWS?.node?.elementType == HCLElementTypes.ID) {
return assert(false, DumpPsiFileModel(position))
}
Expand All @@ -303,19 +304,16 @@ public class TerraformConfigCompletionContributor : HCLCompletionContributor() {

public fun doCompletion(position: PsiElement, consumer: MutableList<LookupElementBuilder>) {
val parent = position.parent
LOG.debug("TF.BlockTypeOrNameCompletionProvider{position=$position, parent=$parent}")
LOG.debug { "TF.BlockTypeOrNameCompletionProvider{position=$position, parent=$parent}" }
val obj = when {
parent is HCLIdentifier -> parent
parent is HCLStringLiteral -> parent
// Next two cases in case of two IDs (not Identifiers) nearby (start of block in empty file)
position.node.elementType == HCLElementTypes.ID -> position
position.node.elementType == HCLElementTypes.STRING_LITERAL -> position
position.node.elementType == HCLElementTypes.DOUBLE_QUOTED_STRING -> position
position.node.elementType == HCLElementTypes.SINGLE_QUOTED_STRING -> position
// Next line for the case of two IDs (not Identifiers) nearby (start of block in empty file) TODO: check that
HCLParserDefinition.IDENTIFYING_LITERALS.contains(position.node.elementType) -> position
else -> return failIfInUnitTestsMode(position)
}
val leftNWS = obj.getPrevSiblingNonWhiteSpace()
LOG.debug("TF.BlockTypeOrNameCompletionProvider{position=$position, parent=$parent, obj=$obj, lnws=$leftNWS}")
LOG.debug { "TF.BlockTypeOrNameCompletionProvider{position=$position, parent=$parent, obj=$obj, lnws=$leftNWS}" }
val type: String = when {
leftNWS is HCLIdentifier -> leftNWS.id
leftNWS?.node?.elementType == HCLElementTypes.ID -> leftNWS!!.text
Expand Down Expand Up @@ -373,9 +371,9 @@ public class TerraformConfigCompletionContributor : HCLCompletionContributor() {
if (isBlock || isProperty) {
_parent = pob?.parent // Object
}
LOG.debug("TF.BlockPropertiesCompletionProvider{position=$position, parent=$_parent, right=$right, isBlock=$isBlock, isProperty=$isProperty}")
LOG.debug { "TF.BlockPropertiesCompletionProvider{position=$position, parent=$_parent, right=$right, isBlock=$isBlock, isProperty=$isProperty}" }
} else {
LOG.debug("TF.BlockPropertiesCompletionProvider{position=$position, parent=$_parent, no right part}")
LOG.debug { "TF.BlockPropertiesCompletionProvider{position=$position, parent=$_parent, no right part}" }
}
val parent: PsiElement = _parent ?: return failIfInUnitTestsMode(position);
if (parent !is HCLObject) {
Expand Down Expand Up @@ -417,7 +415,7 @@ public class TerraformConfigCompletionContributor : HCLCompletionContributor() {
val position = parameters.position
val parent = position.parent
val inArray = (parent.parent is HCLArray)
LOG.debug("TF.PropertyValueCompletionProvider{position=$position, parent=$parent}")
LOG.debug { "TF.PropertyValueCompletionProvider{position=$position, parent=$parent}" }
val property = PsiTreeUtil.getParentOfType(position, HCLProperty::class.java) ?: return
val block = PsiTreeUtil.getParentOfType(property, HCLBlock::class.java) ?: return

Expand Down Expand Up @@ -455,7 +453,7 @@ public class TerraformConfigCompletionContributor : HCLCompletionContributor() {
override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext?, result: CompletionResultSet) {
val position = parameters.position
val parent = position.parent
LOG.debug("TF.VariableNameTFVARSCompletionProvider{position=$position, parent=$parent}")
LOG.debug { "TF.VariableNameTFVARSCompletionProvider{position=$position, parent=$parent}" }
val module: Module
if (parent is HCLFile) {
module = parent.getTerraformModule()
Expand All @@ -474,7 +472,7 @@ public class TerraformConfigCompletionContributor : HCLCompletionContributor() {
override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext?, result: CompletionResultSet) {
val position = parameters.position
val parent = position.parent
LOG.debug("TF.MappedVariableTFVARSCompletionProvider{position=$position, parent=$parent}")
LOG.debug { "TF.MappedVariableTFVARSCompletionProvider{position=$position, parent=$parent}" }
val varProperty: HCLProperty
if (parent is HCLObject) {
val pp = parent.parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiPolyVariantReference
import com.intellij.util.ProcessingContext
import com.intellij.util.SmartList
import org.intellij.plugins.debug
import org.intellij.plugins.hcl.psi.*
import org.intellij.plugins.hcl.terraform.config.codeinsight.ModelHelper
import org.intellij.plugins.hcl.terraform.config.codeinsight.TerraformConfigCompletionContributor
Expand Down Expand Up @@ -152,7 +153,7 @@ class HILCompletionContributor : CompletionContributor() {
val parent = position.parent
if (parent !is ILExpression) return
val leftNWS = position.getPrevSiblingNonWhiteSpace()
LOG.debug("HIL.MethodsCompletionProvider{position=$position, parent=$parent, left=${position.prevSibling}, lnws=$leftNWS}")
LOG.debug { "HIL.MethodsCompletionProvider{position=$position, parent=$parent, left=${position.prevSibling}, lnws=$leftNWS}" }
result.addAllElements(FUNCTIONS.map { create(it) })
result.addAllElements(GLOBAL_SCOPES.map { createScope(it) })
if (getProvisionerResource(parent) != null) result.addElement(createScope("self"))
Expand All @@ -170,7 +171,7 @@ class HILCompletionContributor : CompletionContributor() {
val from = pp.from
if (from !is ILVariable) return
if (scope != from.name) return
LOG.debug("HIL.SelectFromScopeCompletionProvider($scope){position=$position, parent=$parent, pp=$pp}")
LOG.debug { "HIL.SelectFromScopeCompletionProvider($scope){position=$position, parent=$parent, pp=$pp}" }
doAddCompletions(parent, parameters, context, result)
}

Expand All @@ -187,7 +188,7 @@ class HILCompletionContributor : CompletionContributor() {
val from = pp.from
if (from !is ILVariable) return
val provider = SCOPE_PROVIDERS[from.name] ?: return
LOG.debug("HIL.SelectFromScopeCompletionProviderAny($from.name){position=$position, parent=$parent, pp=$pp}")
LOG.debug { "HIL.SelectFromScopeCompletionProviderAny($from.name){position=$position, parent=$parent, pp=$pp}" }
provider.doAddCompletions(parent, parameters, context, result)
}
}
Expand Down Expand Up @@ -364,7 +365,7 @@ class HILCompletionContributor : CompletionContributor() {
val parent = position.parent
if (parent !is ILExpression) return
val leftNWS = position.getPrevSiblingNonWhiteSpace()
LOG.debug("HIL.ResourceTypesCompletionProvider{position=$position, parent=$parent, left=${position.prevSibling}, lnws=$leftNWS}")
LOG.debug { "HIL.ResourceTypesCompletionProvider{position=$position, parent=$parent, left=${position.prevSibling}, lnws=$leftNWS}" }

val host = InjectedLanguageManager.getInstance(parent.project).getInjectionHost(parent) ?: return
if (host !is HCLElement) return
Expand Down
24 changes: 24 additions & 0 deletions src/kotlin/org/intellij/plugins/util.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.intellij.plugins

import com.intellij.openapi.diagnostic.Logger


inline fun Logger.debug(message: () -> String) {
@Suppress("DEPRECATION")
if (this.isDebugEnabled) this.debug(message())
}

0 comments on commit 604bf19

Please sign in to comment.