Avoid crashing language server for 'strange' content assist contexts.

When outside of a meaningful yaml document (i.e. somewhere before
the document marker that starts the first yaml document), invoking content
assist crashed the language server.

Now it just produces no completions instead.
This commit is contained in:
Kris De Volder
2017-03-03 14:56:54 -08:00
parent ff531d3a9b
commit 6dec704f3c
2 changed files with 18 additions and 3 deletions

View File

@@ -36,7 +36,7 @@ import org.springframework.ide.vscode.commons.yaml.util.YamlIndentUtil;
* @author Kris De Volder
*/
public class YamlCompletionEngine implements ICompletionEngine {
final static Logger logger = LoggerFactory.getLogger(YamlCompletionEngine.class);
@@ -142,9 +142,8 @@ public class YamlCompletionEngine implements ICompletionEngine {
}
} else if (node.getNodeType()==SNodeType.DOC) {
return node;
} else {
throw new IllegalStateException("Missing case");
}
return null;
}
protected YamlPath getContextPath(YamlDocument doc, SNode node, int offset) throws Exception {

View File

@@ -2474,6 +2474,22 @@ public class ConcourseEditorTest {
);
}
@Test public void PT_141050891_language_server_crashes_on_CA_before_first_document_marker() throws Exception {
Editor editor = harness.newEditor(
"%Y<*>\n" +
"#leading comment\n" +
"---\n" +
"resources:\n" +
"- name: my-repo\n" +
" type: git\n" +
" source:\n" +
" uri: https://github.com/spring-projects/sts4.git\n" +
" <*>"
);
//We don't expect completions, but this should at least not crash!
editor.assertCompletions(/*NONE*/);
}
//////////////////////////////////////////////////////////////////////////////
private void assertContextualCompletions(String conText, String textBefore, String... textAfter) throws Exception {