Fixed some issues with CF proposals

Proposals for CF still returning empty value hints rather than throwing
exception.
This commit is contained in:
nsingh
2017-01-19 19:04:05 -08:00
parent d62b58beb0
commit c1b5ff1021
7 changed files with 61 additions and 48 deletions

View File

@@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
*/
public class CfCliParamsProvider implements ClientParamsProvider {
public static final String NO_CLI_TARGETS_FOUND_MESSAGE = "Unable to fetch information from Cloud Foundry. Please use cf CLI to configure and login to Cloud Foundry.";
public static final String TARGET = "Target";
public static final String REFRESH_TOKEN = "RefreshToken";
public static final String ORGANIZATION_FIELDS = "OrganizationFields";
@@ -74,7 +75,7 @@ public class CfCliParamsProvider implements ClientParamsProvider {
if (params.isEmpty()) {
throw new NoTargetsException(
"Unable to fetch information from Cloud Foundry. Please use cf CLI to configure and login to Cloud Foundry.");
NO_CLI_TARGETS_FOUND_MESSAGE);
} else {
return params;
}

View File

@@ -35,5 +35,5 @@ public interface CompletionFactory {
* @param edits
* @return non-null proposal
*/
ICompletionProposal errorMessage(String message, String query, YType type, DocumentEdits edits);
ICompletionProposal errorMessage(String message, String query, YType type, DocumentEdits edits, YTypeUtil typeUtil);
}

View File

@@ -136,6 +136,59 @@ public class DefaultCompletionFactory implements CompletionFactory {
return null;
}
}
public static final class ErrorProposal extends ScoreableProposal {
private final String value;
private final double score;
private final String label;
private DocumentEdits edits;
private YTypeUtil typeUtil;
private YType type;
public ErrorProposal(String value, String label, YType type, double score, DocumentEdits edits, YTypeUtil typeUtil) {
this.value = value;
this.score = score;
this.label = label;
this.edits = edits;
this.typeUtil = typeUtil;
this.type = type;
}
@Override
public DocumentEdits getTextEdit() {
return edits;
}
@Override
public String getLabel() {
return label;
}
@Override
public CompletionItemKind getKind() {
return CompletionItemKind.Value;
}
@Override
public Renderable getDocumentation() {
return null;
}
@Override
public double getBaseScore() {
return score;
}
@Override
public String toString() {
return "ErrorProposal("+value+")";
}
@Override
public String getDetail() {
return typeUtil.niceTypeName(type);
}
}
@Override
public ICompletionProposal beanProperty(IDocument doc, String contextProperty, YType contextType, String query, YTypedProperty p, double score, DocumentEdits edits, YTypeUtil typeUtil) {
@@ -148,42 +201,10 @@ public class DefaultCompletionFactory implements CompletionFactory {
}
@Override
public ICompletionProposal errorMessage(String message, String query, YType type, DocumentEdits edits) {
final String value = EMPTY_VALUE; // Empty value for the proposal. Purpose is to show a message with no value to fill in.
public ICompletionProposal errorMessage(String message, String query, YType type, DocumentEdits edits, YTypeUtil typeUtil) {
final double score = ERROR_COMPLETION_SCORE;
final Renderable documentation = null;
final String niceDescription = message;
return new ScoreableProposal() {
@Override
public DocumentEdits getTextEdit() {
return edits;
}
@Override
public String getLabel() {
return value;
}
@Override
public CompletionItemKind getKind() {
return CompletionItemKind.Value;
}
@Override
public Renderable getDocumentation() {
return documentation;
}
@Override
public String getDetail() {
return niceDescription;
}
@Override
public double getBaseScore() {
return score;
}
};
final String value = EMPTY_VALUE;
final String label = message;
return new ErrorProposal(value, label, type, score, edits, typeUtil);
}
}

View File

@@ -155,7 +155,7 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
values = typeUtil.getHintValues(type, getSchemaContext());
} catch (Exception e) {
DocumentEdits edits = new DocumentEdits(doc.getDocument());
return ImmutableList.of(completionFactory().errorMessage(ExceptionUtil.getMessage(e), query, type, edits));
return ImmutableList.of(completionFactory().errorMessage(ExceptionUtil.getMessage(e), query, type, edits, typeUtil));
}
if (values!=null) {
ArrayList<ICompletionProposal> completions = new ArrayList<>();

View File

@@ -41,9 +41,6 @@ public abstract class AbstractCFHintsProvider implements Callable<Collection<YVa
@Override
public Collection<YValueHint> call() throws Exception {
Collection<YValueHint> hints = new ArrayList<>();
// TODO: Probably not the most ideal thing to do, but for now show any
// CF errors
// in the CA UI, as well as cases where there are no targets
try {
List<CFTarget> targets = targetCache.getOrCreate();
Collection<YValueHint> resolvedHints = getHints(targets);

View File

@@ -44,9 +44,6 @@ public class ManifestYamlCFBuildpacksProvider extends AbstractCFHintsProvider {
}
}
if (hints.isEmpty()) {
hints.add(new BasicYValueHint(EMPTY_VALUE, "No Cloud Foundry buildpacks found."));
}
return hints;
}

View File

@@ -44,9 +44,6 @@ public class ManifestYamlCFServicesProvider extends AbstractCFHintsProvider {
}
}
if (hints.isEmpty()) {
hints.add(new BasicYValueHint(EMPTY_VALUE, "No Cloud Foundry service instances available"));
}
return hints;
}