FIR IDE: Always insert additional spaces into lambda brackets
The customization of this with `INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD` will be supported later
This commit is contained in:
committed by
TeamCityServer
parent
415d52fe54
commit
4c0cab4756
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
// ELEMENT: foo
|
// ELEMENT: foo
|
||||||
// CHAR: '\t'
|
// CHAR: '\t'
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
// ELEMENT: foo
|
// ELEMENT: foo
|
||||||
// CHAR: '\t'
|
// CHAR: '\t'
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
class Cn<T>
|
class Cn<T>
|
||||||
|
|
||||||
fun <T, C: Cn<T>> C.some(arg: (T) -> Unit): C {
|
fun <T, C: Cn<T>> C.some(arg: (T) -> Unit): C {
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
class Cn<T>
|
class Cn<T>
|
||||||
|
|
||||||
fun <T, C: Cn<T>> C.some(arg: (T) -> Unit): C {
|
fun <T, C: Cn<T>> C.some(arg: (T) -> Unit): C {
|
||||||
|
|||||||
Vendored
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
class Some
|
class Some
|
||||||
|
|
||||||
fun <T> Some.filter(predicate : (T) -> Boolean) = throw UnsupportedOperationException()
|
fun <T> Some.filter(predicate : (T) -> Boolean) = throw UnsupportedOperationException()
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
class Some
|
class Some
|
||||||
|
|
||||||
fun <T> Some.filter(predicate : (T) -> Boolean) = throw UnsupportedOperationException()
|
fun <T> Some.filter(predicate : (T) -> Boolean) = throw UnsupportedOperationException()
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// FIR_COMPARISON
|
|
||||||
// CODE_STYLE_SETTING: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD = false
|
// CODE_STYLE_SETTING: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD = false
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// FIR_COMPARISON
|
|
||||||
// CODE_STYLE_SETTING: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD = false
|
// CODE_STYLE_SETTING: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD = false
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
fun <T> Array<T>.filter(predicate : (T) -> Boolean) : java.util.List<T> = throw UnsupportedOperationException()
|
fun <T> Array<T>.filter(predicate : (T) -> Boolean) : java.util.List<T> = throw UnsupportedOperationException()
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|||||||
Vendored
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
fun <T> Array<T>.filter(predicate : (T) -> Boolean) : java.util.List<T> = throw UnsupportedOperationException()
|
fun <T> Array<T>.filter(predicate : (T) -> Boolean) : java.util.List<T> = throw UnsupportedOperationException()
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
fun usage() {
|
fun usage() {
|
||||||
fun myLocalFun(action: () -> Unit) {}
|
fun myLocalFun(action: () -> Unit) {}
|
||||||
|
|
||||||
myLocalFun {<caret>}
|
myLocalFun { <caret> }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ELEMENT: myLocalFun
|
// ELEMENT: myLocalFun
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
fun some(f: () -> Unit) { f() }
|
fun some(f: () -> Unit) { f() }
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
fun some(f: () -> Unit) { f() }
|
fun some(f: () -> Unit) { f() }
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// FIR_COMPARISON
|
|
||||||
package p
|
package p
|
||||||
|
|
||||||
val vvv = 1
|
val vvv = 1
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// FIR_COMPARISON
|
|
||||||
package p
|
package p
|
||||||
|
|
||||||
val vvv = 1
|
val vvv = 1
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
fun f(list: List<String>) {
|
fun f(list: List<String>) {
|
||||||
list.<caret>
|
list.<caret>
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
fun f(list: List<String>) {
|
fun f(list: List<String>) {
|
||||||
list.map { <caret> }
|
list.map { <caret> }
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-2
@@ -247,6 +247,7 @@ private object FunctionInsertionHandler : QuotedNamesAwareInsertionHandler() {
|
|||||||
|
|
||||||
var openingBracketOffset = chars.indexOfSkippingSpace(openingBracket, offset)
|
var openingBracketOffset = chars.indexOfSkippingSpace(openingBracket, offset)
|
||||||
var closeBracketOffset = openingBracketOffset?.let { chars.indexOfSkippingSpace(closingBracket, it + 1) }
|
var closeBracketOffset = openingBracketOffset?.let { chars.indexOfSkippingSpace(closingBracket, it + 1) }
|
||||||
|
var inBracketsShift = 0
|
||||||
|
|
||||||
if (openingBracketOffset == null) {
|
if (openingBracketOffset == null) {
|
||||||
if (lookupObject.insertEmptyLambda) {
|
if (lookupObject.insertEmptyLambda) {
|
||||||
@@ -254,7 +255,12 @@ private object FunctionInsertionHandler : QuotedNamesAwareInsertionHandler() {
|
|||||||
context.setAddCompletionChar(false)
|
context.setAddCompletionChar(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
document.insertString(offset, " {}")
|
if (isInsertSpacesInOneLineFunctionEnabled(context.file)) {
|
||||||
|
document.insertString(offset, " { }")
|
||||||
|
inBracketsShift = 1
|
||||||
|
} else {
|
||||||
|
document.insertString(offset, " {}")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isSmartEnterCompletion) {
|
if (isSmartEnterCompletion) {
|
||||||
document.insertString(offset, "(")
|
document.insertString(offset, "(")
|
||||||
@@ -269,7 +275,7 @@ private object FunctionInsertionHandler : QuotedNamesAwareInsertionHandler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldPlaceCaretInBrackets(completionChar, lookupObject) || closeBracketOffset == null) {
|
if (shouldPlaceCaretInBrackets(completionChar, lookupObject) || closeBracketOffset == null) {
|
||||||
editor.caretModel.moveToOffset(openingBracketOffset + 1)
|
editor.caretModel.moveToOffset(openingBracketOffset + 1 + inBracketsShift)
|
||||||
AutoPopupController.getInstance(project)?.autoPopupParameterInfo(editor, offsetElement)
|
AutoPopupController.getInstance(project)?.autoPopupParameterInfo(editor, offsetElement)
|
||||||
} else {
|
} else {
|
||||||
editor.caretModel.moveToOffset(closeBracketOffset + 1)
|
editor.caretModel.moveToOffset(closeBracketOffset + 1)
|
||||||
@@ -282,6 +288,9 @@ private object FunctionInsertionHandler : QuotedNamesAwareInsertionHandler() {
|
|||||||
return lookupObject.inputValueArguments || lookupObject.insertEmptyLambda
|
return lookupObject.inputValueArguments || lookupObject.insertEmptyLambda
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME Should be fetched from language settings (INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD), but we do not have them right now
|
||||||
|
private fun isInsertSpacesInOneLineFunctionEnabled(file: PsiElement) = true
|
||||||
|
|
||||||
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||||
val targetFile = context.file as? KtFile ?: return
|
val targetFile = context.file as? KtFile ?: return
|
||||||
val lookupObject = item.`object` as FunctionLookupObject
|
val lookupObject = item.`object` as FunctionLookupObject
|
||||||
|
|||||||
+8
-8
@@ -536,6 +536,14 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
add(FirErrors.WRONG_MODIFIER_TARGET) { firDiagnostic ->
|
||||||
|
WrongModifierTargetImpl(
|
||||||
|
firDiagnostic.a,
|
||||||
|
firDiagnostic.b,
|
||||||
|
firDiagnostic as FirPsiDiagnostic<*>,
|
||||||
|
token,
|
||||||
|
)
|
||||||
|
}
|
||||||
add(FirErrors.INLINE_CLASS_NOT_TOP_LEVEL) { firDiagnostic ->
|
add(FirErrors.INLINE_CLASS_NOT_TOP_LEVEL) { firDiagnostic ->
|
||||||
InlineClassNotTopLevelImpl(
|
InlineClassNotTopLevelImpl(
|
||||||
firDiagnostic as FirPsiDiagnostic<*>,
|
firDiagnostic as FirPsiDiagnostic<*>,
|
||||||
@@ -628,14 +636,6 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
add(FirErrors.WRONG_MODIFIER_TARGET) { firDiagnostic ->
|
|
||||||
WrongModifierTargetImpl(
|
|
||||||
firDiagnostic.a,
|
|
||||||
firDiagnostic.b,
|
|
||||||
firDiagnostic as FirPsiDiagnostic<*>,
|
|
||||||
token,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
add(FirErrors.NONE_APPLICABLE) { firDiagnostic ->
|
add(FirErrors.NONE_APPLICABLE) { firDiagnostic ->
|
||||||
NoneApplicableImpl(
|
NoneApplicableImpl(
|
||||||
firDiagnostic.a.map { abstractFirBasedSymbol ->
|
firDiagnostic.a.map { abstractFirBasedSymbol ->
|
||||||
|
|||||||
+6
-6
@@ -389,6 +389,12 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
override val diagnosticClass get() = RedundantOpenInInterface::class
|
override val diagnosticClass get() = RedundantOpenInInterface::class
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class WrongModifierTarget : KtFirDiagnostic<PsiElement>() {
|
||||||
|
override val diagnosticClass get() = WrongModifierTarget::class
|
||||||
|
abstract val modifier: KtModifierKeywordToken
|
||||||
|
abstract val target: String
|
||||||
|
}
|
||||||
|
|
||||||
abstract class InlineClassNotTopLevel : KtFirDiagnostic<KtDeclaration>() {
|
abstract class InlineClassNotTopLevel : KtFirDiagnostic<KtDeclaration>() {
|
||||||
override val diagnosticClass get() = InlineClassNotTopLevel::class
|
override val diagnosticClass get() = InlineClassNotTopLevel::class
|
||||||
}
|
}
|
||||||
@@ -451,12 +457,6 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
override val diagnosticClass get() = ValueClassCannotBeCloneable::class
|
override val diagnosticClass get() = ValueClassCannotBeCloneable::class
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class WrongModifierTarget : KtFirDiagnostic<PsiElement>() {
|
|
||||||
override val diagnosticClass get() = WrongModifierTarget::class
|
|
||||||
abstract val modifier: KtModifierKeywordToken
|
|
||||||
abstract val target: String
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class NoneApplicable : KtFirDiagnostic<PsiElement>() {
|
abstract class NoneApplicable : KtFirDiagnostic<PsiElement>() {
|
||||||
override val diagnosticClass get() = NoneApplicable::class
|
override val diagnosticClass get() = NoneApplicable::class
|
||||||
abstract val candidates: List<KtSymbol>
|
abstract val candidates: List<KtSymbol>
|
||||||
|
|||||||
+9
-9
@@ -618,6 +618,15 @@ internal class RedundantOpenInInterfaceImpl(
|
|||||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class WrongModifierTargetImpl(
|
||||||
|
override val modifier: KtModifierKeywordToken,
|
||||||
|
override val target: String,
|
||||||
|
firDiagnostic: FirPsiDiagnostic<*>,
|
||||||
|
override val token: ValidityToken,
|
||||||
|
) : KtFirDiagnostic.WrongModifierTarget(), KtAbstractFirDiagnostic<PsiElement> {
|
||||||
|
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||||
|
}
|
||||||
|
|
||||||
internal class InlineClassNotTopLevelImpl(
|
internal class InlineClassNotTopLevelImpl(
|
||||||
firDiagnostic: FirPsiDiagnostic<*>,
|
firDiagnostic: FirPsiDiagnostic<*>,
|
||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
@@ -725,15 +734,6 @@ internal class ValueClassCannotBeCloneableImpl(
|
|||||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class WrongModifierTargetImpl(
|
|
||||||
override val modifier: KtModifierKeywordToken,
|
|
||||||
override val target: String,
|
|
||||||
firDiagnostic: FirPsiDiagnostic<*>,
|
|
||||||
override val token: ValidityToken,
|
|
||||||
) : KtFirDiagnostic.WrongModifierTarget(), KtAbstractFirDiagnostic<PsiElement> {
|
|
||||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class NoneApplicableImpl(
|
internal class NoneApplicableImpl(
|
||||||
override val candidates: List<KtSymbol>,
|
override val candidates: List<KtSymbol>,
|
||||||
firDiagnostic: FirPsiDiagnostic<*>,
|
firDiagnostic: FirPsiDiagnostic<*>,
|
||||||
|
|||||||
Reference in New Issue
Block a user