Search in sources :

Example 16 with Diagnostic

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());
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) Test(org.junit.Test)

Example 17 with Diagnostic

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: ");
}
Also used : CodeAction(org.springframework.ide.vscode.languageserver.testharness.CodeAction) Diagnostic(org.eclipse.lsp4j.Diagnostic) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) Test(org.junit.Test)

Example 18 with Diagnostic

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);
}
Also used : ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) MarkedString(org.eclipse.lsp4j.MarkedString)

Example 19 with Diagnostic

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();
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) MarkedString(org.eclipse.lsp4j.MarkedString)

Example 20 with Diagnostic

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());
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) Arrays(java.util.Arrays) MultimapBuilder(com.google.common.collect.MultimapBuilder) LanguageServerTestListener(org.springframework.ide.vscode.commons.languageserver.util.LanguageServerTestListener) DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) MessageActionItem(org.eclipse.lsp4j.MessageActionItem) Future(java.util.concurrent.Future) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Duration(java.time.Duration) Map(java.util.Map) Path(java.nio.file.Path) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) ExceptionUtil(org.springframework.ide.vscode.commons.util.ExceptionUtil) IOUtil(org.springframework.ide.vscode.commons.util.IOUtil) HighlightParams(org.springframework.ide.vscode.commons.languageserver.HighlightParams) Assert(org.springframework.ide.vscode.commons.util.Assert) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) Assert.assertFalse(org.junit.Assert.assertFalse) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) LanguageClientAware(org.eclipse.lsp4j.services.LanguageClientAware) ApplyWorkspaceEditParams(org.eclipse.lsp4j.ApplyWorkspaceEditParams) Callable(java.util.concurrent.Callable) Diagnostic(org.eclipse.lsp4j.Diagnostic) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) FileChangeType(org.eclipse.lsp4j.FileChangeType) TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) TextEdit(org.eclipse.lsp4j.TextEdit) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) UriUtil(org.springframework.ide.vscode.commons.util.UriUtil) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent) InitializeResult(org.eclipse.lsp4j.InitializeResult) Files(java.nio.file.Files) ProgressParams(org.springframework.ide.vscode.commons.languageserver.ProgressParams) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) Assert.assertTrue(org.junit.Assert.assertTrue) ClasspathListenerParams(org.springframework.ide.vscode.commons.languageserver.jdt.ls.ClasspathListenerParams) Mono(reactor.core.publisher.Mono) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) File(java.io.File) TextDocumentSyncOptions(org.eclipse.lsp4j.TextDocumentSyncOptions) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) STS4LanguageClient(org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient) Paths(java.nio.file.Paths) Condition(org.assertj.core.api.Condition) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) Assert.assertEquals(org.junit.Assert.assertEquals) ApplyWorkspaceEditResponse(org.eclipse.lsp4j.ApplyWorkspaceEditResponse) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) Random(java.util.Random) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) FileEvent(org.eclipse.lsp4j.FileEvent) ShowMessageRequestParams(org.eclipse.lsp4j.ShowMessageRequestParams) CodeLens(org.eclipse.lsp4j.CodeLens) Location(org.eclipse.lsp4j.Location) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Assert.fail(org.junit.Assert.fail) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) URI(java.net.URI) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) ProjectResponse(org.springframework.ide.vscode.commons.languageserver.ProjectResponse) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) CompletionItem(org.eclipse.lsp4j.CompletionItem) List(java.util.List) Command(org.eclipse.lsp4j.Command) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) Entry(java.util.Map.Entry) SimpleLanguageServerWrapper(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServerWrapper) InitializeParams(org.eclipse.lsp4j.InitializeParams) Settings(org.springframework.ide.vscode.commons.languageserver.util.Settings) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Range(org.eclipse.lsp4j.Range) Multimap(com.google.common.collect.Multimap) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) Charset(java.nio.charset.Charset) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) ImmutableList(com.google.common.collect.ImmutableList) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) MessageParams(org.eclipse.lsp4j.MessageParams) CursorMovement(org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixEdit.CursorMovement) Position(org.eclipse.lsp4j.Position) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) CompletionItemCapabilities(org.eclipse.lsp4j.CompletionItemCapabilities) CompletionList(org.eclipse.lsp4j.CompletionList) DidChangeConfigurationParams(org.eclipse.lsp4j.DidChangeConfigurationParams) CompletionCapabilities(org.eclipse.lsp4j.CompletionCapabilities) TextDocumentSyncKind(org.eclipse.lsp4j.TextDocumentSyncKind) LanguageId(org.springframework.ide.vscode.commons.util.text.LanguageId) RegistrationParams(org.eclipse.lsp4j.RegistrationParams) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TimeUnit(java.util.concurrent.TimeUnit) Collections(java.util.Collections) InputStream(java.io.InputStream) CodeActionContext(org.eclipse.lsp4j.CodeActionContext)

Aggregations

Diagnostic (org.eclipse.lsp4j.Diagnostic)56 Test (org.junit.Test)31 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)22 Range (org.eclipse.lsp4j.Range)13 ArrayList (java.util.ArrayList)12 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)11 List (java.util.List)8 Position (org.eclipse.lsp4j.Position)8 DiagnosticSeverity (org.eclipse.lsp4j.DiagnosticSeverity)7 URI (java.net.URI)5 Path (java.nio.file.Path)5 Map (java.util.Map)5 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)5 Command (org.eclipse.lsp4j.Command)5 MarkedString (org.eclipse.lsp4j.MarkedString)5 CodeAction (org.springframework.ide.vscode.languageserver.testharness.CodeAction)5 IOException (java.io.IOException)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 ImmutableList (com.google.common.collect.ImmutableList)3