use of org.eclipse.lsp4j.Diagnostic in project sts4 by spring-projects.
the class BoshEditorTest method releasesAdvancedValidations.
@Test
public void releasesAdvancedValidations() throws Exception {
Editor editor = harness.newEditor("releases:\n" + "- name: some-release\n" + " url: https://my.releases.com/funky.tar.gz\n" + "- name: other-relase\n" + " version: other-version\n" + " url: file:///root/releases/a-nice-file.tar.gz\n" + "- name: bad-url\n" + " version: more-version\n" + " url: proto://something.com\n" + "#x");
editor.assertProblems("^-^ name: some-release|'version' is required", "url|'sha1' is recommended when the 'url' is http(s)", "proto|Url scheme must be one of [http, https, file]", "x|are required");
Diagnostic missingSha1Problem = editor.assertProblem("url");
assertContains("'sha1' is recommended", missingSha1Problem.getMessage());
assertEquals(DiagnosticSeverity.Warning, missingSha1Problem.getSeverity());
}
use of org.eclipse.lsp4j.Diagnostic in project sts4 by spring-projects.
the class BoshEditorTest method missingPropertiesQuickfix.
@Test
public void missingPropertiesQuickfix() throws Exception {
Editor editor = harness.newEditor("name: blah\n" + "stemcells:\n" + "- alias: ubuntu\n" + " os: ubuntu-trusty\n" + " version: 3421.11\n" + "- alias: centos\n" + " os: centos-7\n" + " version: latest");
Diagnostic problem = editor.assertProblems("t|Properties [instance_groups, releases, update] are required").get(0);
CodeAction quickfix = editor.assertCodeAction(problem);
assertEquals("Add properties: [instance_groups, releases, update]", quickfix.getLabel());
quickfix.perform();
editor.assertText("name: blah\n" + "stemcells:\n" + "- alias: ubuntu\n" + " os: ubuntu-trusty\n" + " version: 3421.11\n" + "- alias: centos\n" + " os: centos-7\n" + " version: latest\n" + "releases:\n" + "- name: <*>\n" + " version: \n" + "update:\n" + " canaries: \n" + " max_in_flight: \n" + " canary_watch_time: \n" + " update_watch_time: \n" + "instance_groups:\n" + "- name: \n" + " azs:\n" + " - \n" + " instances: \n" + " jobs:\n" + " - name: \n" + " release: \n" + " vm_type: \n" + " stemcell: \n" + " networks:\n" + " - name: ");
}
use of org.eclipse.lsp4j.Diagnostic in project sts4 by spring-projects.
the class Editor method assertProblems.
/**
* Check that a 'expectedProblems' are found by the reconciler. Expected problems are
* specified by string of the form "${badSnippet}|${messageSnippet}" or
* "${badSnippet}^${followSnippet}|${messageSnippet}"
* <p>
* The badSnippet is the text expected to be covered by the marker's region and the message snippet must
* be found in the error marker's message.
* <p>
* In addition, if followSnippet is specified, the text that comes right after the error marker must match it.
* <p>
* The expected problems are matched one-to-one in the order given (so markers in the
* editor must appear in the expected order for the assert to pass).
*
* @param editor
* @param expectedProblems
* @throws BadLocationException
*/
public List<Diagnostic> assertProblems(String... expectedProblems) throws Exception {
Editor editor = this;
List<Diagnostic> actualProblems = new ArrayList<>(editor.reconcile().stream().filter(d -> {
return !ignoredTypes.contains(d.getCode());
}).collect(Collectors.toList()));
Collections.sort(actualProblems, PROBLEM_COMPARATOR);
String bad = null;
if (actualProblems.size() != expectedProblems.length) {
bad = "Wrong number of problems (expecting " + expectedProblems.length + " but found " + actualProblems.size() + ")";
} else {
for (int i = 0; i < expectedProblems.length; i++) {
if (!matchProblem(actualProblems.get(i), expectedProblems[i])) {
bad = "First mismatch at index " + i + ": " + expectedProblems[i] + "\n";
break;
}
}
}
if (bad != null) {
fail(bad + problemSumary(editor, actualProblems));
}
return ImmutableList.copyOf(actualProblems);
}
use of org.eclipse.lsp4j.Diagnostic in project sts4 by spring-projects.
the class Editor method problemSumary.
private String problemSumary(Editor editor, List<Diagnostic> actualProblems) throws Exception {
StringBuilder buf = new StringBuilder();
for (Diagnostic p : actualProblems) {
buf.append("\n----------------------\n");
String snippet = editor.getText(p.getRange());
buf.append("(" + p.getRange().getStart().getLine() + ", " + p.getRange().getStart().getCharacter() + ")[" + snippet + "]:\n");
buf.append(" " + p.getMessage());
}
return buf.toString();
}
use of org.eclipse.lsp4j.Diagnostic in project sts4 by spring-projects.
the class LanguageServerHarness method getCodeActions.
public List<CodeAction> getCodeActions(TextDocumentInfo doc, Diagnostic problem) throws Exception {
CodeActionContext context = new CodeActionContext(ImmutableList.of(problem));
List<? extends Command> actions = getServer().getTextDocumentService().codeAction(new CodeActionParams(doc.getId(), problem.getRange(), context)).get();
return actions.stream().map((command) -> new CodeAction(this, command)).collect(Collectors.toList());
}
Aggregations