From b17e6f08ecd65608db27afa3798b05b4d4efcd1b Mon Sep 17 00:00:00 2001 From: Anton Lobov Date: Wed, 22 Aug 2018 17:12:32 +0200 Subject: [PATCH] json schema completion: don't reformat ": " for whitespace-sensitive case (e.g., yaml) --- .../impl/JsonSchemaCompletionContributor.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaCompletionContributor.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaCompletionContributor.java index dec162d3ef67..60c91e9fa387 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaCompletionContributor.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaCompletionContributor.java @@ -353,8 +353,10 @@ public class JsonSchemaCompletionContributor extends CompletionContributor { if (hasSameType(variants)) { final JsonSchemaType type = jsonSchemaObject.getType(); final List values = jsonSchemaObject.getEnum(); + Object defaultValue = jsonSchemaObject.getDefault(); + boolean hasValues = !ContainerUtil.isEmpty(values); - if (type != null || hasValues || jsonSchemaObject.getDefault() != null) { + if (type != null || hasValues || defaultValue != null) { builder = builder.withInsertHandler( !hasValues || values.stream().map(v -> v.getClass()).distinct().count() == 1 ? createPropertyInsertHandler(jsonSchemaObject, hasValue, insertComma) : @@ -432,21 +434,12 @@ public class JsonSchemaCompletionContributor extends CompletionContributor { boolean insertComma) { JsonSchemaType type = jsonSchemaObject.getType(); List values = jsonSchemaObject.getEnum(); - if (type == null || values == null) { - MatchResult result = new JsonSchemaResolver(jsonSchemaObject).detailedResolve(); - if (result.mySchemas.size() == 1) { - JsonSchemaObject object = result.mySchemas.get(0); - if (type == null) type = object.getType(); - if (values == null) values = object.getEnum(); - } - } if (type == null && values != null && !values.isEmpty()) type = detectType(values); final Object defaultValue = jsonSchemaObject.getDefault(); final String defaultValueAsString = defaultValue == null || defaultValue instanceof JsonSchemaObject ? null : (defaultValue instanceof String ? "\"" + defaultValue + "\"" : String.valueOf(defaultValue)); JsonSchemaType finalType = type; - List finalValues = values; return new InsertHandler() { @Override public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) { @@ -521,13 +514,13 @@ public class JsonSchemaCompletionContributor extends CompletionContributor { break; case _string: case _integer: - insertPropertyWithEnum(context, editor, defaultValueAsString, finalValues, finalType, comma, myWalker); + insertPropertyWithEnum(context, editor, defaultValueAsString, values, finalType, comma, myWalker); break; default: } } else { - insertPropertyWithEnum(context, editor, defaultValueAsString, finalValues, null, comma, myWalker); + insertPropertyWithEnum(context, editor, defaultValueAsString, values, null, comma, myWalker); } } }; @@ -616,7 +609,9 @@ public class JsonSchemaCompletionContributor extends CompletionContributor { editor.getCaretModel().moveToOffset(newOffset); } - formatInsertedString(context, stringToInsert.length()); + if (!walker.invokeEnterBeforeObjectAndArray()) { + formatInsertedString(context, stringToInsert.length()); + } if (hasValues) { AutoPopupController.getInstance(context.getProject()).autoPopupMemberLookup(context.getEditor(), null);