Java Code Examples for org.eclipse.lsp4j.CompletionItem#setFilterText()
The following examples show how to use
org.eclipse.lsp4j.CompletionItem#setFilterText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilePathCompletionParticipant.java From lemminx with Eclipse Public License 2.0 | 6 votes |
private void createFilePathCompletionItem(File f, Range replaceRange, ICompletionResponse response, String slash) { CompletionItem item = new CompletionItem(); String fName = f.getName(); if(isWindows && fName.isEmpty()) { // Edge case for Windows drive letter fName = f.getPath(); fName = fName.substring(0, fName.length() - 1); } String insertText; insertText = slash + fName; item.setLabel(insertText); CompletionItemKind kind = f.isDirectory()? CompletionItemKind.Folder : CompletionItemKind.File; item.setKind(kind); item.setSortText(CompletionSortTextHelper.getSortText(kind)); item.setFilterText(insertText); item.setTextEdit(new TextEdit(replaceRange, insertText)); response.addCompletionItem(item); }
Example 2
Source File: LauncherTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@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(); }
Example 3
Source File: SnippetCompletionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static CompletionItem getInterfaceSnippet(SnippetCompletionContext scc, IProgressMonitor monitor) { ICompilationUnit cu = scc.getCompilationUnit(); if (!accept(cu, scc.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 { CodeGenerationTemplate template = ((scc.needsPublic(monitor))) ? CodeGenerationTemplate.INTERFACESNIPPET_PUBLIC : CodeGenerationTemplate.INTERFACESNIPPET_DEFAULT; interfaceSnippetItem.setInsertText(getSnippetContent(scc, template, true)); setFields(interfaceSnippetItem, cu); } catch (CoreException e) { JavaLanguageServerPlugin.log(e.getStatus()); return null; } return interfaceSnippetItem; }
Example 4
Source File: SnippetCompletionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static CompletionItem getClassSnippet(SnippetCompletionContext scc, IProgressMonitor monitor) { ICompilationUnit cu = scc.getCompilationUnit(); if (!accept(cu, scc.getCompletionContext(), 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 { CodeGenerationTemplate template = (scc.needsPublic(monitor)) ? CodeGenerationTemplate.CLASSSNIPPET_PUBLIC : CodeGenerationTemplate.CLASSSNIPPET_DEFAULT; classSnippetItem.setInsertText(getSnippetContent(scc, template, true)); setFields(classSnippetItem, cu); } catch (CoreException e) { JavaLanguageServerPlugin.log(e.getStatus()); return null; } return classSnippetItem; }
Example 5
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
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)); } }
Example 6
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
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()); item.setDetail(new String(fullName)); }
Example 7
Source File: DdlCompletionItemLoader.java From syndesis with Apache License 2.0 | 6 votes |
/** * Clones a {@link CompletionItem} for the given label from the supplied items * * @param targetLabel * @return a completion item */ private static CompletionItem cloneCompletionItem(List<CompletionItem> items, String targetLabel) { for (CompletionItem item : items) { if (item.getLabel().equalsIgnoreCase(targetLabel)) { CompletionItem clone = new CompletionItem(targetLabel); clone.setAdditionalTextEdits(item.getAdditionalTextEdits()); clone.setCommand(item.getCommand()); clone.setData(item.getData()); clone.setDetail(item.getDetail()); clone.setFilterText(item.getFilterText()); clone.setInsertText(item.getInsertText()); clone.setInsertTextFormat(item.getInsertTextFormat()); clone.setDocumentation(item.getDocumentation()); clone.setDeprecated(item.getDeprecated()); clone.setKind(item.getKind()); clone.setSortText(item.getSortText()); clone.setPreselect(item.getPreselect()); clone.setTextEdit(item.getTextEdit()); return clone; } } return null; }
Example 8
Source File: ContentModelCompletionParticipant.java From lemminx with Eclipse Public License 2.0 | 6 votes |
private static void addCompletionItem(CMElementDeclaration elementDeclaration, DOMElement parentElement, String defaultPrefix, boolean forceUseOfPrefix, ICompletionRequest request, ICompletionResponse response, XMLGenerator generator, Set<String> tags) { String prefix = forceUseOfPrefix ? defaultPrefix : (parentElement != null ? parentElement.getPrefix(elementDeclaration.getNamespace()) : null); String label = elementDeclaration.getName(prefix); if (tags != null) { if (tags.contains(label)) { return; } else { tags.add(label); } } CompletionItem item = new CompletionItem(label); item.setFilterText(request.getFilterForStartTagName(label)); item.setKind(CompletionItemKind.Property); MarkupContent documentation = XMLGenerator.createMarkupContent(elementDeclaration, request); item.setDocumentation(documentation); String xml = generator.generate(elementDeclaration, prefix, isGenerateEndTag(request.getNode(), request.getOffset(), label)); item.setTextEdit(new TextEdit(request.getReplaceRange(), xml)); item.setInsertTextFormat(InsertTextFormat.Snippet); response.addCompletionItem(item, true); }
Example 9
Source File: HTMLCompletionExtensionsTest.java From lemminx with Eclipse Public License 2.0 | 5 votes |
@Override public void onAttributeValue(String valuePrefix, ICompletionRequest completionRequest, ICompletionResponse completionResponse) { String tag = completionRequest.getCurrentTag(); String attributeName = completionRequest.getCurrentAttributeName(); HTMLTag htmlTag = HTMLTag.getHTMLTag(tag); if (htmlTag != null) { String[] attributes = htmlTag.getAttributes(); if (attributes != null) { for (String attribute : attributes) { String attrName = attribute; String attrType = null; int index = attribute.indexOf(":"); if (index != -1) { attrName = attribute.substring(0, index); attrType = attribute.substring(index + 1, attribute.length()); } if (attrType != null && attributeName.equals(attrName)) { Range fullRange = completionRequest.getReplaceRange(); String[] values = HTMLTag.getAttributeValues(attrType); for (String value : values) { String insertText = completionRequest.getInsertAttrValue(value); CompletionItem item = new CompletionItem(); item.setLabel(value); item.setFilterText(insertText); item.setKind(CompletionItemKind.Unit); item.setTextEdit(new TextEdit(fullRange, insertText)); item.setInsertTextFormat(InsertTextFormat.PlainText); completionResponse.addCompletionAttribute(item); } break; } } } } }
Example 10
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
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())); }
Example 11
Source File: XMLAssert.java From lemminx with Eclipse Public License 2.0 | 5 votes |
public static CompletionItem c(String label, TextEdit textEdit, String filterText) { CompletionItem item = new CompletionItem(); item.setLabel(label); item.setFilterText(filterText); item.setTextEdit(textEdit); return item; }
Example 12
Source File: XMLAssert.java From lemminx with Eclipse Public License 2.0 | 5 votes |
public static CompletionItem c(String label, TextEdit textEdit, String filterText, String documentation, String kind) { CompletionItem item = new CompletionItem(); item.setLabel(label); item.setFilterText(filterText); item.setTextEdit(textEdit); if (kind == null) { item.setDocumentation(documentation); } else { item.setDocumentation(new MarkupContent(kind, documentation)); } return item; }
Example 13
Source File: EntitiesCompletionParticipant.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private static void fillCompletion(String name, MarkupContent documentation, Range entityRange, ICompletionResponse response) { String entityName = "&" + name + ";"; CompletionItem item = new CompletionItem(); item.setLabel(entityName); item.setKind(CompletionItemKind.Keyword); item.setInsertTextFormat(InsertTextFormat.PlainText); String insertText = entityName; item.setFilterText(insertText); item.setTextEdit(new TextEdit(entityRange, insertText)); item.setDocumentation(documentation); response.addCompletionItem(item); }
Example 14
Source File: SnippetCompletionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static CompletionItem getRecordSnippet(SnippetCompletionContext scc, IProgressMonitor monitor) { ICompilationUnit cu = scc.getCompilationUnit(); IJavaProject javaProject = cu.getJavaProject(); if (javaProject == null) { return null; } String version = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_14)) { //not checking if preview features are enabled, as Java 14+ might support records without preview flag return null; } if (!accept(cu, scc.getCompletionContext(), false /* Or should it be true???*/)) { return null; } if (monitor.isCanceled()) { return null; } final CompletionItem recordSnippet = new CompletionItem(); recordSnippet.setFilterText(RECORD_SNIPPET_LABEL); recordSnippet.setLabel(RECORD_SNIPPET_LABEL); recordSnippet.setSortText(SortTextHelper.convertRelevance(0)); try { CodeGenerationTemplate template = (scc.needsPublic(monitor)) ? CodeGenerationTemplate.RECORDSNIPPET_PUBLIC : CodeGenerationTemplate.RECORDSNIPPET_DEFAULT; recordSnippet.setInsertText(getSnippetContent(scc, template, true)); setFields(recordSnippet, cu); } catch (CoreException e) { JavaLanguageServerPlugin.log(e.getStatus()); return null; } return recordSnippet; }
Example 15
Source File: CompletionProvider.java From vscode-as3mxml with Apache License 2.0 | 5 votes |
private void addMXMLLanguageTagToAutoComplete(String tagName, String prefix, boolean includeOpenTagBracket, boolean includeOpenTagPrefix, CompletionList result) { List<CompletionItem> items = result.getItems(); CompletionItem item = new CompletionItem(); item.setKind(CompletionItemKind.Keyword); item.setLabel("fx:" + tagName); if (completionSupportsSnippets) { item.setInsertTextFormat(InsertTextFormat.Snippet); } item.setFilterText(tagName); item.setSortText(tagName); StringBuilder builder = new StringBuilder(); if (includeOpenTagBracket) { builder.append("<"); } if (includeOpenTagPrefix) { builder.append(prefix); builder.append(IMXMLCoreConstants.colon); } builder.append(tagName); builder.append(">"); builder.append("\n"); builder.append("\t"); if (completionSupportsSnippets) { builder.append("$0"); } builder.append("\n"); builder.append("<"); builder.append(IMXMLCoreConstants.slash); builder.append(prefix); builder.append(IMXMLCoreConstants.colon); builder.append(tagName); builder.append(">"); item.setInsertText(builder.toString()); items.add(item); }
Example 16
Source File: XMLCompletions.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private void collectionRegionProposals(ICompletionRequest request, ICompletionResponse response) { // Completion for #region try { int offset = request.getOffset(); TextDocument document = request.getXMLDocument().getTextDocument(); Position pos = document.positionAt(offset); String lineText = document.lineText(pos.getLine()); String lineUntilPos = lineText.substring(0, pos.getCharacter()); Matcher match = regionCompletionRegExpr.matcher(lineUntilPos); if (match.find()) { InsertTextFormat insertFormat = request.getInsertTextFormat(); Range range = new Range(new Position(pos.getLine(), pos.getCharacter() + match.regionStart()), pos); String text = request.isCompletionSnippetsSupported() ? "<!-- #region $1-->" : "<!-- #region -->"; CompletionItem beginProposal = new CompletionItem("#region"); beginProposal.setTextEdit(new TextEdit(range, text)); beginProposal.setDocumentation("Insert Folding Region Start"); beginProposal.setFilterText(match.group()); beginProposal.setSortText("za"); beginProposal.setKind(CompletionItemKind.Snippet); beginProposal.setInsertTextFormat(insertFormat); response.addCompletionAttribute(beginProposal); CompletionItem endProposal = new CompletionItem("#endregion"); endProposal.setTextEdit(new TextEdit(range, "<!-- #endregion-->")); endProposal.setDocumentation("Insert Folding Region End"); endProposal.setFilterText(match.group()); endProposal.setSortText("zb"); endProposal.setKind(CompletionItemKind.Snippet); endProposal.setInsertTextFormat(InsertTextFormat.PlainText); response.addCompletionAttribute(endProposal); } } catch (BadLocationException e) { LOGGER.log(Level.SEVERE, "While performing collectRegionCompletion", e); } }
Example 17
Source File: JavadocCompletionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public List<CompletionItem> getProposals(ICompilationUnit cu, int offset, CompletionProposalRequestor collector, IProgressMonitor monitor) throws JavaModelException { if (cu == null) { throw new IllegalArgumentException("Compilation unit must not be null"); //$NON-NLS-1$ } List<CompletionItem> result = new ArrayList<>(); IDocument d = JsonRpcHelpers.toDocument(cu.getBuffer()); if (offset < 0 || d.getLength() == 0) { return result; } try { int p = (offset == d.getLength() ? offset - 1 : offset); IRegion line = d.getLineInformationOfOffset(p); String lineStr = d.get(line.getOffset(), line.getLength()).trim(); if (!lineStr.startsWith("/**")) { return result; } if (!hasEndJavadoc(d, offset)) { return result; } String text = collector.getContext().getToken() == null ? "" : new String(collector.getContext().getToken()); StringBuilder buf = new StringBuilder(text); IRegion prefix = findPrefixRange(d, line); String indentation = d.get(prefix.getOffset(), prefix.getLength()); int lengthToAdd = Math.min(offset - prefix.getOffset(), prefix.getLength()); buf.append(indentation.substring(0, lengthToAdd)); String lineDelimiter = TextUtilities.getDefaultLineDelimiter(d); ICompilationUnit unit = cu; try { unit.reconcile(ICompilationUnit.NO_AST, false, null, null); String string = createJavaDocTags(d, offset, indentation, lineDelimiter, unit); if (string != null && !string.trim().equals(ASTERISK)) { buf.append(string); } else { return result; } int nextNonWS = findEndOfWhiteSpace(d, offset, d.getLength()); if (!Character.isWhitespace(d.getChar(nextNonWS))) { buf.append(lineDelimiter); } } catch (CoreException e) { // ignore } final CompletionItem ci = new CompletionItem(); Range range = JDTUtils.toRange(unit, offset, 0); boolean isSnippetSupported = JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isCompletionSnippetsSupported(); 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)); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(isSnippetSupported ? InsertTextFormat.Snippet : InsertTextFormat.PlainText); String documentation = prepareTemplate(buf.toString(), lineDelimiter, false); if (documentation.indexOf(lineDelimiter) == 0) { documentation = documentation.replaceFirst(lineDelimiter, ""); } ci.setDocumentation(documentation); Map<String, String> data = new HashMap<>(3); data.put(CompletionResolveHandler.DATA_FIELD_URI, JDTUtils.toURI(cu)); data.put(CompletionResolveHandler.DATA_FIELD_REQUEST_ID, "0"); data.put(CompletionResolveHandler.DATA_FIELD_PROPOSAL_ID, "0"); ci.setData(data); result.add(ci); } catch (BadLocationException excp) { // stop work } return result; }
Example 18
Source File: CompletionProvider.java From vscode-as3mxml with Apache License 2.0 | 4 votes |
private void addRootMXMLLanguageTagsToAutoComplete(IMXMLTagData offsetTag, String prefix, boolean includeOpenTagPrefix, boolean includeOpenTagBracket, CompletionList result) { List<CompletionItem> items = result.getItems(); CompletionItem item = new CompletionItem(); item.setKind(CompletionItemKind.Keyword); item.setLabel("fx:" + IMXMLLanguageConstants.SCRIPT); if (completionSupportsSnippets) { item.setInsertTextFormat(InsertTextFormat.Snippet); } item.setFilterText(IMXMLLanguageConstants.SCRIPT); item.setSortText(IMXMLLanguageConstants.SCRIPT); StringBuilder builder = new StringBuilder(); if (includeOpenTagBracket) { builder.append("<"); } if (includeOpenTagPrefix) { builder.append(prefix); builder.append(IMXMLCoreConstants.colon); } builder.append(IMXMLLanguageConstants.SCRIPT); builder.append(">"); builder.append("\n"); builder.append("\t"); builder.append(IMXMLCoreConstants.cDataStart); builder.append("\n"); builder.append("\t\t"); if (completionSupportsSnippets) { builder.append("$0"); } builder.append("\n"); builder.append("\t"); builder.append(IMXMLCoreConstants.cDataEnd); builder.append("\n"); builder.append("<"); builder.append(IMXMLCoreConstants.slash); builder.append(prefix); builder.append(IMXMLCoreConstants.colon); builder.append(IMXMLLanguageConstants.SCRIPT); builder.append(">"); item.setInsertText(builder.toString()); items.add(item); addMXMLLanguageTagToAutoComplete(IMXMLLanguageConstants.BINDING, prefix, includeOpenTagBracket, includeOpenTagPrefix, result); addMXMLLanguageTagToAutoComplete(IMXMLLanguageConstants.DECLARATIONS, prefix, includeOpenTagBracket, includeOpenTagPrefix, result); addMXMLLanguageTagToAutoComplete(IMXMLLanguageConstants.METADATA, prefix, includeOpenTagBracket, includeOpenTagPrefix, result); addMXMLLanguageTagToAutoComplete(IMXMLLanguageConstants.STYLE, prefix, includeOpenTagBracket, includeOpenTagPrefix, result); }