Search in sources :

Example 6 with MarkupContent

use of org.eclipse.lsp4j.MarkupContent in project eclipse.jdt.ls by eclipse.

the class SnippetUtilsTest method testWhenMarkDownSupported.

@Test
public void testWhenMarkDownSupported() {
    ClientPreferences mockCapabilies = mock(ClientPreferences.class);
    when(mockCapabilies.isSupportsCompletionDocumentationMarkdown()).thenReturn(Boolean.TRUE);
    when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
    String raw = "System.out.println(${0});";
    Either<String, MarkupContent> result = SnippetUtils.beautifyDocument(raw);
    assertNotNull(result);
    assertNull(result.getLeft());
    assertNotNull(result.getRight());
    assertEquals(result.getRight().getValue(), "```java\nSystem.out.println();\n```");
}
Also used : ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) MarkupContent(org.eclipse.lsp4j.MarkupContent) Test(org.junit.Test)

Example 7 with MarkupContent

use of org.eclipse.lsp4j.MarkupContent in project eclipse.jdt.ls by eclipse.

the class SnippetUtilsTest method testMultipleVariablesInput.

@Test
public void testMultipleVariablesInput() {
    ClientPreferences mockCapabilies = mock(ClientPreferences.class);
    when(mockCapabilies.isSupportsCompletionDocumentationMarkdown()).thenReturn(Boolean.FALSE);
    when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
    // @formatter:off
    String raw = "for (${1:int} ${2:i} = ${3:0}; ${2:i} < ${4:args.length}; ${2:i}++) {\n" + "\t${0}\n" + "}";
    // @formatter:on
    Either<String, MarkupContent> result = SnippetUtils.beautifyDocument(raw);
    // @formatter:off
    String expected = "for (int i = 0; i < args.length; i++) {\n" + "\t\n" + "}";
    // @formatter:on
    assertEquals(result.getLeft(), expected);
}
Also used : ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) MarkupContent(org.eclipse.lsp4j.MarkupContent) Test(org.junit.Test)

Example 8 with MarkupContent

use of org.eclipse.lsp4j.MarkupContent in project eclipse.jdt.ls by eclipse.

the class SnippetUtilsTest method testSelectedTextPlaceholder.

@Test
public void testSelectedTextPlaceholder() {
    ClientPreferences mockCapabilies = mock(ClientPreferences.class);
    when(mockCapabilies.isSupportsCompletionDocumentationMarkdown()).thenReturn(Boolean.FALSE);
    when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
    // @formatter:off
    String raw = "for (${1:int} ${2:i} = ${3:0}; ${2:i} < ${4:args.length}; ${2:i}++) {\n" + "\t$TM_SELECTED_TEXT${0}\n" + "}";
    // @formatter:on
    Either<String, MarkupContent> result = SnippetUtils.beautifyDocument(raw);
    // @formatter:off
    String expected = "for (int i = 0; i < args.length; i++) {\n" + "\t\n" + "}";
    // @formatter:on
    assertEquals(result.getLeft(), expected);
}
Also used : ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) MarkupContent(org.eclipse.lsp4j.MarkupContent) Test(org.junit.Test)

Example 9 with MarkupContent

use of org.eclipse.lsp4j.MarkupContent in project eclipse.jdt.ls by eclipse.

the class SnippetUtilsTest method testWhenMarkDownNotSupported.

@Test
public void testWhenMarkDownNotSupported() {
    ClientPreferences mockCapabilies = mock(ClientPreferences.class);
    when(mockCapabilies.isSupportsCompletionDocumentationMarkdown()).thenReturn(Boolean.FALSE);
    when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
    String raw = "System.out.println(${0});";
    Either<String, MarkupContent> result = SnippetUtils.beautifyDocument(raw);
    assertNotNull(result);
    assertNull(result.getRight());
    assertNotNull(result.getLeft());
    assertEquals(result.getLeft(), "System.out.println();");
}
Also used : ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) MarkupContent(org.eclipse.lsp4j.MarkupContent) Test(org.junit.Test)

Aggregations

MarkupContent (org.eclipse.lsp4j.MarkupContent)9 ClientPreferences (org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences)6 Test (org.junit.Test)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 Range (org.eclipse.lsp4j.Range)2 UncheckedTimeoutException (com.google.common.util.concurrent.UncheckedTimeoutException)1 Reader (java.io.Reader)1 TimeoutException (java.util.concurrent.TimeoutException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 CompletionContext (org.eclipse.jdt.core.CompletionContext)1 CompletionProposal (org.eclipse.jdt.core.CompletionProposal)1 IField (org.eclipse.jdt.core.IField)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IMember (org.eclipse.jdt.core.IMember)1 IMethod (org.eclipse.jdt.core.IMethod)1 ISourceRange (org.eclipse.jdt.core.ISourceRange)1 ISourceReference (org.eclipse.jdt.core.ISourceReference)1 IType (org.eclipse.jdt.core.IType)1 ITypeRoot (org.eclipse.jdt.core.ITypeRoot)1