NPE caused by ambiguous keys fixed.

This commit is contained in:
Kris De Volder
2016-12-16 17:56:22 -08:00
parent d867f71592
commit 05bd1dfcd6
7 changed files with 129 additions and 70 deletions

View File

@@ -17,6 +17,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import org.springframework.boot.configurationmetadata.Deprecation;
import org.springframework.ide.vscode.boot.common.InformationTemplates;
@@ -125,27 +126,6 @@ public abstract class ApplicationYamlAssistContext extends AbstractYamlAssistCon
return new IndexContext(doc, documentSelector, YamlPath.EMPTY, IndexNavigator.with(index), completionFactory, typeUtil, conf);
}
public static YamlAssistContext forPath(YamlDocument doc, YamlPath contextPath, FuzzyMap<PropertyInfo> index, PropertyCompletionFactory completionFactory, TypeUtil typeUtil, RelaxedNameConfig conf) {
try {
YamlPathSegment documentSelector = contextPath.getSegment(0);
if (documentSelector!=null) {
contextPath = contextPath.dropFirst(1);
YamlAssistContext context = ApplicationYamlAssistContext.subdocument(doc, documentSelector.toIndex(), index, completionFactory, typeUtil, conf);
for (YamlPathSegment s : contextPath.getSegments()) {
if (context==null) return null;
context = context.traverse(s);
}
return context;
}
} catch (Exception e) {
Log.log(e);
}
return null;
}
@Override
abstract public YamlAssistContext traverse(YamlPathSegment s) throws Exception;
private static class TypeContext extends ApplicationYamlAssistContext {
private PropertyCompletionFactory completionFactory;
@@ -415,7 +395,7 @@ public abstract class ApplicationYamlAssistContext extends AbstractYamlAssistCon
if (!matchingProps.isEmpty()) {
ArrayList<ICompletionProposal> completions = new ArrayList<ICompletionProposal>();
for (Match<PropertyInfo> match : matchingProps) {
DocumentEdits edits = createEdits(doc, offset, query, match);
DocumentEdits edits = createEdits(doc, node, offset, query, match);
ScoreableProposal completion = completionFactory.property(
doc.getDocument(), edits, match, typeUtil
);
@@ -430,7 +410,7 @@ public abstract class ApplicationYamlAssistContext extends AbstractYamlAssistCon
}
protected DocumentEdits createEdits(final YamlDocument file,
final int offset, final String query, final Match<PropertyInfo> match)
SNode node, final int offset, final String query, final Match<PropertyInfo> match)
throws Exception {
//Edits created lazyly as they are somwehat expensive to compute and mostly
// we need only the edits for the one proposal that user picks.

View File

@@ -3311,7 +3311,12 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
" activemq:\n" +
" broker-u<*>"
, // ==>
"fill it in later"
"spring:\n" +
" application:\n" +
" name: my-app\n" +
"spring:\n" +
" activemq:\n" +
" broker-url: <*>"
);
}