private void createJavadocTypeProposalLabel(char[] fullName, CompletionItem item) { // only display innermost type name as type name, using any // enclosing types as qualification int qIndex= findSimpleNameStart(fullName); StringBuilder nameBuffer= new StringBuilder(); String name = new String(fullName, qIndex, fullName.length - qIndex); nameBuffer.append("{@link "); //$NON-NLS-1$ nameBuffer.append(name); nameBuffer.append('}'); item.setLabel(nameBuffer.toString()); item.setFilterText(name); if (qIndex > 0) { item.setDetail(new String(fullName, 0, qIndex - 1)); } }
void createTypeProposalLabel(char[] fullName, CompletionItem item) { // only display innermost type name as type name, using any // enclosing types as qualification int qIndex= findSimpleNameStart(fullName); String name = new String(fullName, qIndex, fullName.length - qIndex); StringBuilder nameBuffer= new StringBuilder(); nameBuffer.append(name); if (qIndex > 0) { nameBuffer.append(PACKAGE_NAME_SEPARATOR); nameBuffer.append(new String(fullName,0,qIndex-1)); } item.setFilterText(name); item.setInsertText(name); item.setLabel(nameBuffer.toString()); }
private void createOverrideMethodProposalLabel(CompletionProposal methodProposal, CompletionItem item) { StringBuilder nameBuffer= new StringBuilder(); // method name String name = new String(methodProposal.getName()); item.setInsertText(name); nameBuffer.append(name); // parameters nameBuffer.append('('); appendUnboundedParameterList(nameBuffer, methodProposal); nameBuffer.append(')'); nameBuffer.append(RETURN_TYPE_SEPARATOR); // return type // TODO remove SignatureUtil.fix83600 call when bugs are fixed char[] returnType= createTypeDisplayName(SignatureUtil.getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature())))); nameBuffer.append(returnType); item.setLabel(nameBuffer.toString()); item.setFilterText(name); // declaring type StringBuilder typeBuffer = new StringBuilder(); String declaringType= extractDeclaringTypeFQN(methodProposal); declaringType= Signature.getSimpleName(declaringType); typeBuffer.append(String.format("Override method in '%s'", declaringType)); item.setDetail(typeBuffer.toString()); setSignature(item, String.valueOf(methodProposal.getSignature())); setDeclarationSignature(item, String.valueOf(methodProposal.getDeclarationSignature())); setName(item, String.valueOf(methodProposal.getName())); }
String replacement = prepareTemplate(buf.toString(), lineDelimiter, isSnippetSupported); ci.setTextEdit(new TextEdit(range, replacement)); ci.setFilterText(JAVA_DOC_COMMENT); ci.setLabel(JAVA_DOC_COMMENT); ci.setSortText(SortTextHelper.convertRelevance(0));
private static CompletionItem getClassSnippet(ICompilationUnit cu, CompletionContext completionContext, boolean needsPublic, IProgressMonitor monitor) { if (!accept(cu, completionContext, true)) { return null; } if (monitor.isCanceled()) { return null; } final CompletionItem classSnippetItem = new CompletionItem(); classSnippetItem.setLabel(CLASS_SNIPPET_LABEL); classSnippetItem.setFilterText(CLASS_SNIPPET_LABEL); classSnippetItem.setSortText(SortTextHelper.convertRelevance(1)); try { if (needsPublic) { classSnippetItem.setInsertText(getSnippetContent(cu, CodeGenerationTemplate.CLASSSNIPPET_PUBLIC, cu.findRecommendedLineSeparator(), true)); } else { classSnippetItem.setInsertText(getSnippetContent(cu, CodeGenerationTemplate.CLASSSNIPPET_DEFAULT, cu.findRecommendedLineSeparator(), true)); } setFields(classSnippetItem, cu); } catch (CoreException e) { JavaLanguageServerPlugin.log(e.getStatus()); return null; } return classSnippetItem; }
private static CompletionItem getInterfaceSnippet(ICompilationUnit cu, CompletionContext completionContext, boolean needsPublic, IProgressMonitor monitor) { if (!accept(cu, completionContext, false)) { return null; } if (monitor.isCanceled()) { return null; } final CompletionItem interfaceSnippetItem = new CompletionItem(); interfaceSnippetItem.setFilterText(INTERFACE_SNIPPET_LABEL); interfaceSnippetItem.setLabel(INTERFACE_SNIPPET_LABEL); interfaceSnippetItem.setSortText(SortTextHelper.convertRelevance(0)); try { if (needsPublic) { interfaceSnippetItem.setInsertText(getSnippetContent(cu, CodeGenerationTemplate.INTERFACESNIPPET_PUBLIC, cu.findRecommendedLineSeparator(), true)); } else { interfaceSnippetItem.setInsertText(getSnippetContent(cu, CodeGenerationTemplate.INTERFACESNIPPET_DEFAULT, cu.findRecommendedLineSeparator(), true)); } setFields(interfaceSnippetItem, cu); } catch (CoreException e) { JavaLanguageServerPlugin.log(e.getStatus()); return null; } return interfaceSnippetItem; }
private CompletionItem adaptItem(TextDocument doc, ICompletionProposal completion, SortKeys sortkeys) throws Exception { CompletionItem item = new CompletionItem(); item.setLabel(completion.getLabel()); item.setKind(completion.getKind()); item.setSortText(sortkeys.next()); item.setFilterText(completion.getFilterText()); item.setDetail(completion.getDetail()); if (completion.isDeprecated()) { item.setDeprecated(completion.isDeprecated()); } resolveEdits(doc, completion, item); //Warning. Its not allowed by LSP spec to resolveEdits //lazy as we used to do in the past. if (resolver!=null) { item.setData(resolver.resolveLater(completion, doc)); } else { resolveItem(doc, completion, item); } return item; }
@Test public void testRequest() throws Exception { CompletionParams p = new CompletionParams(); p.setPosition(new Position(1,1)); p.setTextDocument(new TextDocumentIdentifier("test/foo.txt")); CompletionList result = new CompletionList(); result.setIsIncomplete(true); result.setItems(new ArrayList<>()); CompletionItem item = new CompletionItem(); item.setDetail("test"); item.setDocumentation("doc"); item.setFilterText("filter"); item.setInsertText("insert"); item.setKind(CompletionItemKind.Field); result.getItems().add(item); server.expectedRequests.put("textDocument/completion", new Pair<>(p, result)); CompletableFuture<Either<List<CompletionItem>, CompletionList>> future = clientLauncher.getRemoteProxy().getTextDocumentService().completion(p); Assert.assertEquals(Either.forRight(result).toString(), future.get(TIMEOUT, TimeUnit.MILLISECONDS).toString()); client.joinOnEmpty(); }