Fix NPE in hover info.

This commit is contained in:
Kris De Volder
2016-11-23 11:12:29 -08:00
parent d63bb4949e
commit 45e1155cf3

View File

@@ -63,30 +63,32 @@ public class YamlHoverInfoProvider implements HoverInfoProvider {
YamlFileAST ast = getAst(doc);
if (ast != null) {
IRegion region = getHoverRegion(ast, offset);
YamlDocument ymlDoc = new YamlDocument(doc, structureProvider);
YamlAssistContext assistContext = assistContextProvider.getGlobalAssistContext(ymlDoc);
if (assistContext != null) {
List<NodeRef<?>> astPath = ast.findPath(offset);
final YamlPath path = YamlPath.fromASTPath(astPath);
if (path != null) {
YamlPath assistPath = path;
if (assistPath.pointsAtKey()) {
// When a path points at a key we must tramsform it to a
// 'value-terminating path'
// to be able to reuse the 'getHoverInfo' method on
// YamlAssistContext (as navigation
// into 'key' is not defined for YamlAssistContext.
String key = path.getLastSegment().toPropString();
assistPath = path.dropLast().append(YamlPathSegment.valueAt(key));
}
assistContext = assistPath.traverse(assistContext);
if (assistContext != null) {
if (path.pointsAtValue()) {
Renderable info = assistContext.getValueHoverInfo(ymlDoc, new DocumentRegion(doc, region));
if (region!=null) {
YamlDocument ymlDoc = new YamlDocument(doc, structureProvider);
YamlAssistContext assistContext = assistContextProvider.getGlobalAssistContext(ymlDoc);
if (assistContext != null) {
List<NodeRef<?>> astPath = ast.findPath(offset);
final YamlPath path = YamlPath.fromASTPath(astPath);
if (path != null) {
YamlPath assistPath = path;
if (assistPath.pointsAtKey()) {
// When a path points at a key we must tramsform it to a
// 'value-terminating path'
// to be able to reuse the 'getHoverInfo' method on
// YamlAssistContext (as navigation
// into 'key' is not defined for YamlAssistContext.
String key = path.getLastSegment().toPropString();
assistPath = path.dropLast().append(YamlPathSegment.valueAt(key));
}
assistContext = assistPath.traverse(assistContext);
if (assistContext != null) {
if (path.pointsAtValue()) {
Renderable info = assistContext.getValueHoverInfo(ymlDoc, new DocumentRegion(doc, region));
return Tuples.of(info, region);
}
Renderable info = assistContext.getHoverInfo();
return Tuples.of(info, region);
}
Renderable info = assistContext.getHoverInfo();
return Tuples.of(info, region);
}
}
}