Skip to content

Commit

Permalink
#227 - code assist: select the schema name for the additionalProperti…
Browse files Browse the repository at this point in the history
…es keywords
  • Loading branch information
tfesenko committed Sep 26, 2017
1 parent 9b18047 commit e839fab
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected Collection<Proposal> createObjectProposals(ObjectTypeDefinition type,
}
}
String schemaName = MultipleSwaggerErrorBuilder.getHumanFriendlyText(typeAsJson, "_key_");
proposals.add(new Proposal(schemaName + ":", schemaName, null, null));
proposals.add(new Proposal(schemaName + ":", schemaName, null, null, schemaName));
}

return proposals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Proposal {
public final String displayString;
public final String type;
public final String description;
private final String selection;

protected final Styler typeStyler = new StyledString.Styler() {
@Override
Expand All @@ -38,11 +39,16 @@ public void applyStyles(TextStyle textStyle) {
}
};

public Proposal(String replacementString, String displayString, String description, String type) {
public Proposal(String replacementString, String displayString, String description, String type, String selection) {
this.replacementString = replacementString;
this.displayString = displayString;
this.type = type;
this.description = description;
this.selection = selection;
}

public Proposal(String replacementString, String displayString, String description, String type) {
this(replacementString, displayString, description, type, "");
}

/**
Expand Down Expand Up @@ -93,9 +99,10 @@ public StyledCompletionProposal asStyledCompletionProposal(String prefix, int of

StyledCompletionProposal proposal = null;
if (Strings.emptyToNull(prefix) == null) {
proposal = new StyledCompletionProposal(replacementString, styledString, null, description, offset);
proposal = new StyledCompletionProposal(replacementString, styledString, null, description, offset,
selection);
} else if (rString.toLowerCase().contains(prefix.toLowerCase())) {
proposal = new StyledCompletionProposal(rString, styledString, prefix, description, offset);
proposal = new StyledCompletionProposal(rString, styledString, prefix, description, offset, selection);
}

return proposal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public class StyledCompletionProposal
private final String description;
/** Lower-cased prefix - content assist typeahead should be case-insensitive */
private final String prefix;
private final String selection;

public StyledCompletionProposal(String replacement, StyledString label, String prefix, String description,
int offset) {
int offset, String selection) {
this.label = label;
this.replacementString = replacement;
this.selection = selection == null ? "" : selection;
this.prefix = prefix != null ? prefix.toLowerCase() : null;
this.replacementOffset = offset;
this.description = description;
Expand Down Expand Up @@ -82,10 +84,9 @@ public Point getSelection(IDocument document) {
offset = replacementOffset - prefix.length();
}
}

int cursorPosition = offset + replacementString.length();

return new Point(cursorPosition, 0);
int replacementIndex = replacementString.indexOf(selection);
int selectionStart = offset + (replacementIndex < 0 ? 0 : replacementIndex);
return new Point(selectionStart, selection.length());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OpenApi3ContentAssistProcessorTest {

val proposals = test.apply(processor, "1")
assertThat(proposals.map[(it as StyledCompletionProposal).replacementString],
hasItems("_key_:")
hasItems("callback:")
)
}

Expand All @@ -49,7 +49,7 @@ class OpenApi3ContentAssistProcessorTest {

val proposals = test.apply(processor, "1")
assertThat(proposals.map[(it as StyledCompletionProposal).replacementString],
hasItems("_key_:")
hasItems("callback:")
)
}

Expand Down

0 comments on commit e839fab

Please sign in to comment.