Skip to content

Commit

Permalink
use placeholder only when client supports snippet
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Zhang <[email protected]>
  • Loading branch information
Eskibear authored and fbricon committed Jun 30, 2020
1 parent 1f24ad8 commit b963827
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public AnonymousTypeCompletionProposal(ICompilationUnit cu, int replacementOffse
public String updateReplacementString(IDocument document, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException {
// Construct empty body for performance concern
// See https://github.com/microsoft/language-server-protocol/issues/1032#issuecomment-648748013
String newBody = "{\n\t${0}\n}";
String newBody = fSnippetSupport ? "{\n\t${0}\n}" : "{\n\n}";

StringBuffer buf = new StringBuffer("new A()"); //$NON-NLS-1$
StringBuilder buf = new StringBuilder("new A()"); //$NON-NLS-1$
buf.append(newBody);
// use the code formatter
String lineDelim = TextUtilities.getDefaultLineDelimiter(document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,37 @@ public void testCompletion_AnonymousDeclarationType5() throws Exception {
"}", ci.getTextEdit());
}

@Test
public void testCompletion_AnonymousDeclarationType_noSnippet() throws Exception {
ClientPreferences mockCapabilies = mock(ClientPreferences.class);
when(mockCapabilies.isCompletionSnippetsSupported()).thenReturn(false);
when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);

ICompilationUnit unit = getWorkingCopy(
"src/java/Foo.java",
"public class Foo {\n"+
" public static void main(String[] args) {\n" +
" new Runnable()\n" +
" }\n" +
"}\n");
waitForBackgroundJobs();
int[] loc = findCompletionLocation(unit, "Runnable(");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
CompletionItem ci = list.getItems().stream()
.filter(item -> item.getLabel().startsWith("Runnable() Anonymous Inner Type"))
.findFirst().orElse(null);
assertNotNull(ci);

assertEquals("Runnable", ci.getInsertText());
assertEquals(CompletionItemKind.Class, ci.getKind());
assertEquals("999999372", ci.getSortText());
assertNotNull(ci.getTextEdit());
assertTextEdit(2, 20, 22, "() {\n" +
"\n" +
"}", ci.getTextEdit());
}

@Test
public void testCompletion_type() throws Exception {
ICompilationUnit unit = getWorkingCopy(
Expand Down

0 comments on commit b963827

Please sign in to comment.