Java Code Examples for org.eclipse.lsp4j.CompletionItem#setLabel()
The following examples show how to use
org.eclipse.lsp4j.CompletionItem#setLabel() .
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: 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 2
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 3
Source File: CompletionItemUtils.java From vscode-as3mxml with Apache License 2.0 | 5 votes |
public static CompletionItem createDefinitionItem(IDefinition definition, ICompilerProject project) { CompletionItem item = new CompletionItem(); item.setKind(LanguageServerCompilerUtils.getCompletionItemKindFromDefinition(definition)); item.setDetail(DefinitionTextUtils.definitionToDetail(definition, project)); item.setLabel(definition.getBaseName()); String docs = DefinitionDocumentationUtils.getDocumentationForDefinition(definition, true, project.getWorkspace(), false); if (docs != null) { item.setDocumentation(new MarkupContent(MarkupKind.MARKDOWN, docs)); } return item; }
Example 4
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 5
Source File: DdlCompletionItemLoader.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getCreateViewInnerJoinCompletionItem(int data, String sortValue) { CompletionItem ci = new CompletionItem(); ci.setLabel("CREATE VIEW with INNER JOIN"); ci.setInsertText(QueryExpressionHelper.CREATE_VIEW_INNER_JOIN_INSERT_TEXT); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDetail(" CREATE VIEW with inner join"); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); ci.setSortText(sortValue); return ci; }
Example 6
Source File: DdlCompletionItemLoader.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getCreateViewUnionCompletionItem(int data, String sortValue) { CompletionItem ci = new CompletionItem(); ci.setLabel("CREATE VIEW with UNION"); ci.setInsertText(QueryExpressionHelper.CREATE_VIEW_UNION_INSERT_TEXT); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDetail(" Union of two tables from single source"); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); ci.setSortText(sortValue); return ci; }
Example 7
Source File: CompletionProvider.java From vscode-as3mxml with Apache License 2.0 | 5 votes |
private void autoCompleteKeyword(String keyword, CompletionList result) { CompletionItem item = new CompletionItem(); item.setKind(CompletionItemKind.Keyword); item.setLabel(keyword); result.getItems().add(item); }
Example 8
Source File: TableBodyCompletionProvider.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getAs(int data) { CompletionItem ci = new CompletionItem(); ci.setLabel("AS"); ci.setKind(CompletionItemKind.Keyword); ci.setData(data); ci.setPreselect(true); return ci; }
Example 9
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Updates a display label for the given method proposal to item. The display label * consists of: * <ul> * <li>the method name</li> * <li>the parameter list (see {@link #createParameterList(CompletionProposal)})</li> * <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})</li> * <li>the raw simple name of the declaring type</li> * </ul> * <p> * Examples: * For the <code>get(int)</code> method of a variable of type <code>List<? extends Number></code>, the following * display name is returned: <code>get(int index) Number - List</code>.<br> * For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the following * display name is returned: <code>add(Number o) void - List</code>.<br> * </p> * * @param methodProposal the method proposal to display * @param item to update */ private void createMethodProposalLabel(CompletionProposal methodProposal, CompletionItem item) { StringBuilder description = this.createMethodProposalDescription(methodProposal); item.setLabel(description.toString()); item.setInsertText(String.valueOf(methodProposal.getName())); // declaring type StringBuilder typeInfo = new StringBuilder(); String declaringType= extractDeclaringTypeFQN(methodProposal); if (methodProposal.getRequiredProposals() != null) { String qualifier= Signature.getQualifier(declaringType); if (qualifier.length() > 0) { typeInfo.append(qualifier); typeInfo.append('.'); } } declaringType= Signature.getSimpleName(declaringType); typeInfo.append(declaringType); StringBuilder detail = new StringBuilder(); if (typeInfo.length() > 0) { detail.append(typeInfo); detail.append('.'); } detail.append(description); item.setDetail(detail.toString()); setSignature(item, String.valueOf(methodProposal.getSignature())); setDeclarationSignature(item, String.valueOf(methodProposal.getDeclarationSignature())); setName(item, String.valueOf(methodProposal.getName())); }
Example 10
Source File: TableBodyCompletionProvider.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getColumnCompletionItem(int data) { CompletionItem ci = new CompletionItem(); ci.setLabel("column definition"); ci.setInsertText("${1:column_name} ${2:datatype}"); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); ci.setSortText("1100"); return ci; }
Example 11
Source File: CompletionItemBuilder.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem createFieldItem(String label, String detail, String documentation) { CompletionItem ci = new CompletionItem(); ci.setLabel(label); ci.setKind(CompletionItemKind.Field); if (detail != null) { ci.setDetail(detail); } if (documentation != null) { ci.setDocumentation(documentation); } return ci; }
Example 12
Source File: CompletionItemBuilder.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem createKeywordItemFromItemData(String label) { String[] itemData = getItemData(label); CompletionItem ci = new CompletionItem(); ci.setLabel(label); ci.setKind(CompletionItemKind.Keyword); if (itemData != null) { if (itemData.length > 1) { String detail = itemData[1]; if (detail != null) { ci.setDetail(detail); } } if (itemData.length > 2) { String documentation = itemData[2]; if (documentation != null) { ci.setDocumentation(documentation); } } if (itemData.length > 3) { String insertText = itemData[3]; if (insertText != null) { ci.setInsertText(insertText); ci.setKind(CompletionItemKind.Snippet); } } } return ci; }
Example 13
Source File: CompletionItemBuilder.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem createKeywordItem(String label, String detail, String documentation) { CompletionItem ci = new CompletionItem(); ci.setLabel(label); ci.setKind(CompletionItemKind.Keyword); if (detail != null) { ci.setDetail(detail); } if (documentation != null) { ci.setDocumentation(documentation); } return ci; }
Example 14
Source File: XContentAssistService.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Convert to a completion item. */ protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition, Document document) { CompletionItem result = new CompletionItem(); String label = null; if (entry.getLabel() != null) { label = entry.getLabel(); } else { label = entry.getProposal(); } result.setLabel(label); result.setDetail(entry.getDescription()); result.setDocumentation(entry.getDocumentation()); String prefix = null; if (entry.getPrefix() != null) { prefix = entry.getPrefix(); } else { prefix = ""; } Position prefixPosition = document.getPosition(caretOffset - prefix.length()); result.setTextEdit(new TextEdit(new Range(prefixPosition, caretPosition), entry.getProposal())); if (!entry.getTextReplacements().isEmpty()) { if (result.getAdditionalTextEdits() == null) { result.setAdditionalTextEdits(new ArrayList<>(entry.getTextReplacements().size())); } entry.getTextReplacements().forEach(it -> { result.getAdditionalTextEdits().add(toTextEdit(it, document)); }); } if (entry.getKind().startsWith(ContentAssistEntry.KIND_SNIPPET + ":")) { result.setInsertTextFormat(InsertTextFormat.Snippet); entry.setKind(entry.getKind().substring(ContentAssistEntry.KIND_SNIPPET.length() + 1)); } else if (Objects.equal(entry.getKind(), ContentAssistEntry.KIND_SNIPPET)) { result.setInsertTextFormat(InsertTextFormat.Snippet); } result.setKind(translateKind(entry)); return result; }
Example 15
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 16
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 17
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 18
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 19
Source File: DdlCompletionItemLoader.java From syndesis with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private List<CompletionItem> loadItemsFromFile(String fileName) { List<CompletionItem> items = new ArrayList<CompletionItem>(); try (InputStream stream = this.getClass().getResourceAsStream(fileName)) { JSONParser parser = new JSONParser(stream); // A JSON object. Key value pairs are unordered. JSONObject supports // java.util.Map interface. LinkedHashMap<String, Object> jsonObject = parser.object(); // A JSON array. JSONObject supports java.util.List interface. ArrayList<?> completionItemArray = (ArrayList<?>) jsonObject.get("items"); if (completionItemArray != null) { for (Object item : completionItemArray) { LinkedHashMap<String, Object> itemInfo = (LinkedHashMap<String, Object>) item; CompletionItem newItem = new CompletionItem(); newItem.setLabel((String) itemInfo.get("label")); newItem.setKind(STRING_TO_KIND_MAP.get(((String) itemInfo.get("kind")).toUpperCase(Locale.US))); String detail = (String) itemInfo.get("detail"); if (detail != null) { newItem.setDetail(detail); } String documentation = (String) itemInfo.get("documentation"); if (documentation != null) { newItem.setDocumentation(documentation); } newItem.setDeprecated(Boolean.parseBoolean((String) itemInfo.get("deprecated"))); newItem.setPreselect(Boolean.parseBoolean((String) itemInfo.get("preselect"))); String sortText = (String) itemInfo.get("sortText"); if (sortText != null) { newItem.setSortText(sortText); } String insertText = (String) itemInfo.get("insertText"); if (insertText != null) { insertText = insertText.replaceAll("\\n", "\n"); insertText = insertText.replaceAll("\\t", "\t"); newItem.setInsertText(insertText); } String insertTextFormat = (String) itemInfo.get("insertTextFormat"); if (insertTextFormat != null) { if (newItem.getKind().equals(CompletionItemKind.Snippet)) { newItem.setInsertTextFormat(InsertTextFormat.Snippet); } else { newItem.setInsertTextFormat(InsertTextFormat.PlainText); } } // TODO: Implement quick fixes // newItem.setTextEdit((TextEdit)itemInfo.get("textEdit")); // newItem.setAdditionalTextEdits((List<TextEdit>)itemInfo.get("additionalTextEdits")); // newItem.setCommitCharacters((List<String>)itemInfo.get("commitCharacters")); String category = (String) itemInfo.get("category"); if (category != null && !category.isEmpty()) { addItemByCategory(category, newItem); } else { items.add(newItem); } } } } catch (IOException | ParseException e) { throw new IllegalArgumentException("Unable to parse given file: " + fileName, e); } return items; }
Example 20
Source File: CompletionProvider.java From vscode-as3mxml with Apache License 2.0 | 4 votes |
private void autoCompleteDefinitionsForActionScript(CompletionList result, ILspProject project, IASNode offsetNode, boolean typesOnly, String requiredPackageName, IDefinition definitionToSkip, boolean includeOpenTagBracket, String typeFilter, char nextChar, AddImportData addImportData) { String skipQualifiedName = null; if (definitionToSkip != null) { skipQualifiedName = definitionToSkip.getQualifiedName(); } for (ICompilationUnit unit : project.getCompilationUnits()) { if (unit == null) { continue; } Collection<IDefinition> definitions = null; try { definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions(); } catch (Exception e) { //safe to ignore continue; } for (IDefinition definition : definitions) { boolean isType = definition instanceof ITypeDefinition; if (!typesOnly || isType) { if (requiredPackageName == null || definition.getPackageName().equals(requiredPackageName)) { if (skipQualifiedName != null && skipQualifiedName.equals(definition.getQualifiedName())) { continue; } if (isType) { IMetaTag excludeClassMetaTag = definition.getMetaTagByName(IMetaAttributeConstants.ATTRIBUTE_EXCLUDECLASS); if (excludeClassMetaTag != null) { //skip types with [ExcludeClass] metadata continue; } } addDefinitionAutoCompleteActionScript(definition, offsetNode, nextChar, addImportData, project, result); } } } } if (requiredPackageName == null || requiredPackageName.equals("")) { CompletionItem item = new CompletionItem(); item.setKind(CompletionItemKind.Class); item.setLabel(IASKeywordConstants.VOID); result.getItems().add(item); } }