Skip to content

Commit f2884fa

Browse files
authored
Completion within markdown should escape array brackets #3773 (#2112)
Get the new display string for completion proposal via new API CompletionProposal#getDisplayString()
1 parent 9e01da0 commit f2884fa

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest23.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.jdt.text.tests.contentassist;
1515

1616
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertNotNull;
1718

1819
import java.util.Hashtable;
1920
import java.util.List;
@@ -218,5 +219,48 @@ void method() {}
218219
""";
219220
assertEquals(expectedContents, doc.get());
220221
}
222+
@Test
223+
public void testMarkdown_Escaped() throws CoreException {
224+
IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
225+
226+
IPackageFragment pack1= sourceFolder.createPackageFragment("javadoc", false, null);
227+
String contents=
228+
"""
229+
///
230+
/// see method [#ma
231+
///
232+
public class X {
233+
public static void main(String[] args) {}
234+
}""";
235+
ICompilationUnit cu= pack1.createCompilationUnit("X.java", contents, false, null);
236+
237+
238+
String str= "[#ma";
239+
240+
int offset= contents.indexOf(str) + str.length() - 1;
241+
242+
JavaTypeCompletionProposalComputer comp= new JavaAllCompletionProposalComputer();
243+
244+
List<ICompletionProposal> proposals= comp.computeCompletionProposals(createContext(offset, cu), null);
245+
ICompletionProposal proposal = proposals.get(0);
246+
247+
IEditorPart part= JavaUI.openInEditor(cu);
248+
IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput());
249+
if (proposal != null) {
250+
proposal.apply(doc);
251+
}
252+
253+
String expectedContents=
254+
"""
255+
///
256+
/// see method [#main(String\\[\\])
257+
///
258+
public class X {
259+
public static void main(String[] args) {}
260+
}""";
261+
assertEquals(expectedContents, doc.get());
262+
assertNotNull("Proposal is null", proposal);
263+
assertEquals("Incorrect display string", "main(String[]) - X", proposal.getDisplayString());
264+
}
221265

222266
}

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FillArgumentNamesCompletionProposalCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposa
6666
}
6767

6868
private IJavaCompletionProposal createMethodReferenceProposal(CompletionProposal methodProposal) {
69-
String completion= String.valueOf(methodProposal.getCompletion());
69+
String completion= String.valueOf(methodProposal.getDisplayString());
7070
// super class' behavior if this is not a normal completion or has no
7171
// parameters
7272
if ((completion.length() == 0) || ((completion.length() == 1) && completion.charAt(0) == ')') || Signature.getParameterCount(methodProposal.getSignature()) == 0 || getContext().isInJavadoc())

org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/CompletionProposalLabelProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ StyledString createJavadocMethodProposalLabel(CompletionProposal methodProposal)
319319
StyledString nameBuffer= new StyledString();
320320

321321
// method name
322-
nameBuffer.append(methodProposal.getCompletion());
322+
nameBuffer.append(methodProposal.getDisplayString());
323323

324324
// declaring type
325325
nameBuffer.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER);

0 commit comments

Comments
 (0)