类org.eclipse.lsp4j.MarkupContent源码实例Demo

下面列出了怎么用org.eclipse.lsp4j.MarkupContent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lemminx   文件: SnippetRegistry.java
private static MarkupContent createDocumentation(Snippet snippet, Map<String, String> model,
		boolean canSupportMarkdown, String lineDelimiter) {
	StringBuilder doc = new StringBuilder();
	if (canSupportMarkdown) {
		doc.append(System.lineSeparator());
		doc.append("```");
		String scope = snippet.getScope();
		if (scope != null) {
			doc.append(scope);
		}
		doc.append(System.lineSeparator());
	}
	String insertText = getInsertText(snippet, model, true, lineDelimiter);
	doc.append(insertText);
	if (canSupportMarkdown) {
		doc.append(System.lineSeparator());
		doc.append("```");
		doc.append(System.lineSeparator());
	}
	return new MarkupContent(canSupportMarkdown ? MarkupKind.MARKDOWN : MarkupKind.PLAINTEXT, doc.toString());
}
 
源代码2 项目: lemminx   文件: MarkupContentFactory.java
/**
 * Create the markup content according the given markup kind and the capability
 * of the client.
 * 
 * @param value         the documentation value
 * @param preferredKind the preferred markup kind
 * @return the markup content according the given markup kind and the capability
 *         of the client.
 */
public static MarkupContent createMarkupContent(String value, String preferredKind,
		ISharedSettingsRequest support) {
	if (value == null) {
		return null;
	}
	MarkupContent content = new MarkupContent();
	if (MarkupKind.MARKDOWN.equals(preferredKind) && support.canSupportMarkupKind(preferredKind)) {
		String markdown = MarkdownConverter.convert(value);
		content.setValue(markdown);
		content.setKind(MarkupKind.MARKDOWN);
	} else {
		content.setValue(value);
		content.setKind(MarkupKind.PLAINTEXT);
	}
	return content;
}
 
源代码3 项目: lemminx   文件: MarkupContentFactory.java
/**
 * Create the hover from the given markup content list and range.
 * 
 * @param values       the list of documentation values
 * @param defaultRange the default range.
 * @return the hover from the given markup content list and range.
 */
public static Hover createHover(List<MarkupContent> values, Range defaultRange) {
	if (values.isEmpty()) {
		return null;
	}
	if (values.size() == 1) {
		return new Hover(values.get(0), defaultRange);
	}
	// Markup kind
	boolean hasMarkdown = values.stream() //
			.anyMatch(contents -> MarkupKind.MARKDOWN.equals(contents.getKind()));
	String markupKind = hasMarkdown ? MarkupKind.MARKDOWN : MarkupKind.PLAINTEXT;
	// Contents
	String content = createContent(values, markupKind);
	// Range
	Range range = defaultRange;
	return new Hover(new MarkupContent(markupKind, content), range);
}
 
源代码4 项目: lemminx   文件: MarkupContentFactory.java
/**
 * Create the content.
 * 
 * @param values     the list of documentation values
 * @param markupKind the markup kind.
 * @return the content.
 */
private static String createContent(List<MarkupContent> values, String markupKind) {
	StringBuilder content = new StringBuilder();
	for (MarkupContent value : values) {
		if (!StringUtils.isEmpty(value.getValue())) {
			if (content.length() > 0) {
				if (markupKind.equals(MarkupKind.MARKDOWN)) {
					content.append(System.lineSeparator());
					content.append(System.lineSeparator());
					content.append(MARKDOWN_SEPARATOR);
				}
				content.append(System.lineSeparator());
				content.append(System.lineSeparator());
			}
			content.append(value.getValue());
		}
	}
	return content.toString();
}
 
源代码5 项目: lemminx   文件: EntitiesHoverParticipant.java
@Override
public Hover onText(IHoverRequest request) throws Exception {
	DOMNode node = request.getNode();
	if (!node.isText()) {
		return null;
	}
	// Hover is done in a text node, check if it's a entity reference
	DOMDocument document = request.getXMLDocument();
	int offset = request.getOffset();
	EntityReferenceRange entityRange = XMLPositionUtility.selectEntityReference(offset, document);
	if (entityRange == null) {
		return null;
	}
	// The hovered text follows the entity reference syntax (ex : &amp;)
	String entityName = entityRange.getName();
	Range range = entityRange.getRange();
	// Try to find the entity
	MarkupContent entityContents = searchInEntities(entityName, range, document, request);
	if (entityContents != null) {
		return new Hover(entityContents, range);
	}
	return null;
}
 
源代码6 项目: lemminx   文件: EntitiesHoverParticipant.java
/**
 * Returns the markup content of the given entity name in the local entities and
 * null otherwise.
 * 
 * @param entityName  the entity name to search.
 * @param entityRange the hovered range.
 * @param document    the DOM document
 * @param request     the hover request.
 * @return the markup content of the given entity name in the local entities and
 *         null otherwise.
 */
private static MarkupContent searchInLocalEntities(String entityName, Range entityRange, DOMDocument document,
		IHoverRequest request) {
	DOMDocumentType docType = document.getDoctype();
	if (docType == null) {
		return null;
	}
	// Loop for entities declared in the DOCTYPE of the document
	NamedNodeMap entities = docType.getEntities();
	for (int i = 0; i < entities.getLength(); i++) {
		DTDEntityDecl entity = (DTDEntityDecl) entities.item(i);
		if (entityName.equals(entity.getName())) {
			boolean markdown = request.canSupportMarkupKind(MarkupKind.MARKDOWN);
			return EntitiesDocumentationUtils.getDocumentation(entity, EntityOriginType.LOCAL, markdown);
		}
	}
	return null;
}
 
源代码7 项目: lemminx   文件: EntitiesHoverParticipant.java
/**
 * Returns the markup content of the given entity name in the external entities
 * and null otherwise.
 * 
 * @param entityName  the entity name to search.
 * @param entityRange the hovered range.
 * @param document    the DOM document
 * @param request     the hover request.
 * @return the markup content of the given entity name in the external entities
 *         and null otherwise.
 */
private static MarkupContent searchInExternalEntities(String entityName, Range entityRange, DOMDocument document,
		IHoverRequest request) {
	ContentModelManager contentModelManager = request.getComponent(ContentModelManager.class);
	Collection<CMDocument> cmDocuments = contentModelManager.findCMDocument(document, null, false);
	for (CMDocument cmDocument : cmDocuments) {
		List<Entity> entities = cmDocument.getEntities();
		for (Entity ent : entities) {
			DTDEntityDecl entity = (DTDEntityDecl) ent;
			if (entityName.equals(entity.getName())) {
				boolean markdown = request.canSupportMarkupKind(MarkupKind.MARKDOWN);
				return EntitiesDocumentationUtils.getDocumentation(entity, EntityOriginType.EXTERNAL, markdown);
			}
		}
	}
	return null;
}
 
源代码8 项目: lemminx   文件: EntitiesCompletionParticipant.java
/**
 * Collect local entities declared in the DOCTYPE.
 * 
 * @param document    the DOM document.
 * @param entityRange the entity range.
 * @param markdown    true if the documentation can be formatted as markdown and
 *                    false otherwise.
 * @param response    the completion response.
 */
private static void collectLocalEntityProposals(DOMDocument document, Range entityRange, boolean markdown,
		ICompletionResponse response) {
	DOMDocumentType docType = document.getDoctype();
	if (docType == null) {
		return;
	}
	NamedNodeMap entities = docType.getEntities();
	for (int i = 0; i < entities.getLength(); i++) {
		Entity entity = (Entity) entities.item(i);
		if (entity.getNodeName() != null) {
			// provide completion for the locally declared entity
			MarkupContent documentation = EntitiesDocumentationUtils.getDocumentation((DTDEntityDecl) entity,
					EntityOriginType.LOCAL, markdown);
			fillCompletion(entity.getNodeName(), documentation, entityRange, response);
		}
	}
}
 
源代码9 项目: lemminx   文件: EntitiesCompletionParticipant.java
/**
 * Collect external entities.
 * 
 * @param document    the DOM document.
 * @param entityRange the entity range.
 * @param markdown    true if the documentation can be formatted as markdown and
 *                    false otherwise.
 * @param request     the completion request.
 * @param response    the completion response.
 */
private static void collectExternalEntityProposals(DOMDocument document, Range entityRange, boolean markdown,
		ICompletionRequest request, ICompletionResponse response) {
	ContentModelManager contentModelManager = request.getComponent(ContentModelManager.class);
	Collection<CMDocument> cmDocuments = contentModelManager.findCMDocument(document, null, false);
	for (CMDocument cmDocument : cmDocuments) {
		List<Entity> entities = cmDocument.getEntities();
		for (Entity entity : entities) {
			if (entity.getNodeName() != null) {
				// provide completion for the external declared entity
				MarkupContent documentation = EntitiesDocumentationUtils.getDocumentation((DTDEntityDecl) entity,
						EntityOriginType.EXTERNAL, markdown);
				fillCompletion(entity.getNodeName(), documentation, entityRange, response);
			}
		}
	}
}
 
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);
}
 
private void fillAttributesWithCMAttributeDeclarations(DOMElement parentElement, Range fullRange,
		CMElementDeclaration cmElement, boolean canSupportSnippet, boolean generateValue,
		ICompletionRequest request, ICompletionResponse response) {

	Collection<CMAttributeDeclaration> attributes = cmElement.getAttributes();
	if (attributes == null) {
		return;
	}
	for (CMAttributeDeclaration cmAttribute : attributes) {
		String attrName = cmAttribute.getName();
		if (!parentElement.hasAttribute(attrName)) {
			CompletionItem item = new AttributeCompletionItem(attrName, canSupportSnippet, fullRange, generateValue,
					cmAttribute.getDefaultValue(), cmAttribute.getEnumerationValues(), request.getSharedSettings());
			MarkupContent documentation = XMLGenerator.createMarkupContent(cmAttribute, cmElement, request);
			item.setDocumentation(documentation);
			response.addCompletionAttribute(item);
		}
	}
}
 
private void fillAttributeValuesWithCMAttributeDeclarations(CMElementDeclaration cmElement,
		ICompletionRequest request, ICompletionResponse response) {
	String attributeName = request.getCurrentAttributeName();
	CMAttributeDeclaration cmAttribute = cmElement.findCMAttribute(attributeName);
	if (cmAttribute != null) {
		Range fullRange = request.getReplaceRange();
		cmAttribute.getEnumerationValues().forEach(value -> {
			CompletionItem item = new CompletionItem();
			item.setLabel(value);
			String insertText = request.getInsertAttrValue(value);
			item.setLabel(value);
			item.setKind(CompletionItemKind.Value);
			item.setFilterText(insertText);
			item.setTextEdit(new TextEdit(fullRange, insertText));
			MarkupContent documentation = XMLGenerator.createMarkupContent(cmAttribute, value, cmElement, request);
			item.setDocumentation(documentation);
			response.addCompletionItem(item);
		});
	}
}
 
源代码13 项目: lemminx   文件: ContentModelHoverParticipant.java
@Override
public Hover onTag(IHoverRequest hoverRequest) throws Exception {
	try {
		ContentModelManager contentModelManager = hoverRequest.getComponent(ContentModelManager.class);
		DOMElement element = (DOMElement) hoverRequest.getNode();
		Collection<CMDocument> cmDocuments = contentModelManager.findCMDocument(element);
		if (cmDocuments.isEmpty()) {
			// no bound grammar -> no documentation
			return null;
		}
		// Compute element declaration documentation from bound grammars
		List<MarkupContent> contentValues = new ArrayList<>();
		for (CMDocument cmDocument : cmDocuments) {
			CMElementDeclaration cmElement = cmDocument.findCMElement(element);
			if (cmElement != null) {
				MarkupContent content = XMLGenerator.createMarkupContent(cmElement, hoverRequest);
				fillHoverContent(content, contentValues);
			}
		}
		return createHover(contentValues);
	} catch (CacheResourceDownloadingException e) {
		return getCacheWarningHover(e, hoverRequest);
	}
}
 
源代码14 项目: eclipse.jdt.ls   文件: SnippetUtils.java
public static Either<String, MarkupContent> beautifyDocument(String raw) {
	// remove the placeholder for the plain cursor like: ${0}, ${1:variable}
	String escapedString = raw.replaceAll("\\$\\{\\d:?(.*?)\\}", "$1");

	// Replace the reserved variable with empty string.
	// See: https://github.com/eclipse/eclipse.jdt.ls/issues/1220
	escapedString = escapedString.replaceAll(TM_SELECTED_TEXT, "");

	if (JavaLanguageServerPlugin.getPreferencesManager() != null && JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences() != null
			&& JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isSupportsCompletionDocumentationMarkdown()) {
		MarkupContent markupContent = new MarkupContent();
		markupContent.setKind(MarkupKind.MARKDOWN);
		markupContent.setValue(String.format("```%s\n%s\n```", MARKDOWN_LANGUAGE, escapedString));
		return Either.forRight(markupContent);
	} else {
		return Either.forLeft(escapedString);
	}
}
 
源代码15 项目: eclipse.jdt.ls   文件: SnippetUtilsTest.java
@Test
public void testMultipleVariablesInput() {
	ClientPreferences mockCapabilies = mock(ClientPreferences.class);
	when(mockCapabilies.isSupportsCompletionDocumentationMarkdown()).thenReturn(Boolean.FALSE);
	when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);

	//@formatter:off
	String raw = "for (${1:int} ${2:i} = ${3:0}; ${2:i} < ${4:args.length}; ${2:i}++) {\n" +
			"\t${0}\n" +
			"}";
	//@formatter:on
	Either<String, MarkupContent> result = SnippetUtils.beautifyDocument(raw);

	//@formatter:off
	String expected = "for (int i = 0; i < args.length; i++) {\n" +
			"\t\n" +
			"}";
	//@formatter:on

	assertEquals(result.getLeft(), expected);
}
 
源代码16 项目: eclipse.jdt.ls   文件: SnippetUtilsTest.java
@Test
public void testSelectedTextPlaceholder() {
	ClientPreferences mockCapabilies = mock(ClientPreferences.class);
	when(mockCapabilies.isSupportsCompletionDocumentationMarkdown()).thenReturn(Boolean.FALSE);
	when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);

	//@formatter:off
	String raw = "for (${1:int} ${2:i} = ${3:0}; ${2:i} < ${4:args.length}; ${2:i}++) {\n" +
			"\t$TM_SELECTED_TEXT${0}\n" +
			"}";
	//@formatter:on
	Either<String, MarkupContent> result = SnippetUtils.beautifyDocument(raw);

	//@formatter:off
	String expected = "for (int i = 0; i < args.length; i++) {\n" +
			"\t\n" +
			"}";
	//@formatter:on

	assertEquals(result.getLeft(), expected);
}
 
源代码17 项目: lsp4j   文件: HoverTypeAdapter.java
protected Either<List<Either<String, MarkedString>>, MarkupContent> readContents(final JsonReader in) throws IOException {
  final JsonToken nextToken = in.peek();
  boolean _equals = Objects.equal(nextToken, JsonToken.STRING);
  if (_equals) {
    final List<Either<String, MarkedString>> value = CollectionLiterals.<Either<String, MarkedString>>newArrayList(Either.<String, MarkedString>forLeft(in.nextString()));
    return Either.<List<Either<String, MarkedString>>, MarkupContent>forLeft(value);
  } else {
    boolean _equals_1 = Objects.equal(nextToken, JsonToken.BEGIN_ARRAY);
    if (_equals_1) {
      final List<Either<String, MarkedString>> value_1 = this.gson.<List<Either<String, MarkedString>>>fromJson(in, HoverTypeAdapter.LIST_STRING_MARKEDSTRING.getType());
      return Either.<List<Either<String, MarkedString>>, MarkupContent>forLeft(value_1);
    } else {
      JsonElement _parse = new JsonParser().parse(in);
      final JsonObject object = ((JsonObject) _parse);
      boolean _has = object.has("language");
      if (_has) {
        final List<Either<String, MarkedString>> value_2 = CollectionLiterals.<Either<String, MarkedString>>newArrayList(Either.<String, MarkedString>forRight(this.gson.<MarkedString>fromJson(object, MarkedString.class)));
        return Either.<List<Either<String, MarkedString>>, MarkupContent>forLeft(value_2);
      } else {
        return Either.<List<Either<String, MarkedString>>, MarkupContent>forRight(this.gson.<MarkupContent>fromJson(object, MarkupContent.class));
      }
    }
  }
}
 
源代码18 项目: intellij-quarkus   文件: LSPTextHover.java
protected static @Nullable String getHoverString(Hover hover) {
    Either<List<Either<String, MarkedString>>, MarkupContent> hoverContent = hover.getContents();
    if (hoverContent.isLeft()) {
        List<Either<String, MarkedString>> contents = hoverContent.getLeft();
        if (contents == null || contents.isEmpty()) {
            return null;
        }
        return contents.stream().map(content -> {
            if (content.isLeft()) {
                return content.getLeft();
            } else if (content.isRight()) {
                MarkedString markedString = content.getRight();
                // TODO this won't work fully until markup parser will support syntax
                // highlighting but will help display
                // strings with language tags, e.g. without it things after <?php tag aren't
                // displayed
                if (markedString.getLanguage() != null && !markedString.getLanguage().isEmpty()) {
                    return String.format("```%s%n%s%n```", markedString.getLanguage(), markedString.getValue()); //$NON-NLS-1$
                } else {
                    return markedString.getValue();
                }
            } else {
                return ""; //$NON-NLS-1$
            }
        }).filter(((Predicate<String>) String::isEmpty).negate()).collect(Collectors.joining("\n\n")); //$NON-NLS-1$ )
    } else {
        return hoverContent.getRight().getValue();
    }
}
 
/**
 * Returns documentation about the provided <code>propertyKey</code>'s value,
 * <code>propertyValue</code>
 * 
 * @param propertyKey   the property key
 * @param propertyValue the property key's value
 * @param documentFormat      documentation format (markdown/text)
 * @param insertSpacing true if spacing should be inserted around the equals
 *                      sign and false otherwise
 * @return
 */
public static MarkupContent getDocumentation(String propertyKey, String propertyValue,
		DocumentFormat documentFormat, boolean insertSpacing) {
	boolean markdown = DocumentFormat.Markdown.equals(documentFormat);
	StringBuilder content = new StringBuilder();

	if (markdown) {
		content.append("`");
	}

	content.append(propertyKey);

	if (propertyValue == null) {
		if (markdown) {
			content.append("`");
		}
		content.append(" is not set.");
	} else {
		if (insertSpacing) {
			content.append(" = ");
		} else {
			content.append("=");
		}
		content.append(propertyValue);
		if (markdown) {
			content.append("`");
		}
	}
	return new MarkupContent(markdown ? MarkupKind.MARKDOWN : MarkupKind.PLAINTEXT, content.toString());
}
 
源代码20 项目: intellij-quarkus   文件: MicroProfileAssert.java
public static void assertHover(String expectedKey, String expectedValue, int expectedLine, int expectedStartOffset,
							   int expectedEndOffset, Hover actualInfo) {
	Assert.assertNotNull(actualInfo);

	Position expectedStart = new Position(expectedLine, expectedStartOffset);
	Position expectedEnd = new Position(expectedLine, expectedEndOffset);
	Range expectedRange = new Range(expectedStart, expectedEnd);

	MarkupContent expectedContent = MicroProfileConfigHoverParticipant.getDocumentation(expectedKey, expectedValue,
			DocumentFormat.Markdown, true);

	Assert.assertEquals(expectedContent, actualInfo.getContents().getRight());
	Assert.assertEquals(expectedRange, actualInfo.getRange());
}
 
源代码21 项目: lemminx   文件: PrologModel.java
private static void createCompletionItem(String attrName, boolean canSupportSnippet, boolean generateValue,
		Range editRange, String defaultValue, Collection<String> enumerationValues, String documentation,
		ICompletionResponse response, SharedSettings sharedSettings) {
	CompletionItem item = new AttributeCompletionItem(attrName, canSupportSnippet, editRange, generateValue,
			defaultValue, enumerationValues, sharedSettings);
	MarkupContent markup = new MarkupContent();
	markup.setKind(MarkupKind.MARKDOWN);

	markup.setValue(StringUtils.getDefaultString(documentation));
	item.setDocumentation(markup);
	response.addCompletionItem(item);
}
 
源代码22 项目: lemminx   文件: EntitiesDocumentationUtils.java
public static MarkupContent getDocumentation(DTDEntityDecl entity, EntityOriginType type, boolean markdown) {
	String systemID = entity.getSystemId();
	String publicID = entity.getPublicId();
	String targetURI = entity.getNameParameter().getTargetURI();
	return getDocumentation(entity.getName(), entity.getNotationName(), systemID, publicID, targetURI, type,
			markdown);
}
 
源代码23 项目: lemminx   文件: EntitiesDocumentationUtils.java
/**
 * Returns the entity documentation.
 * 
 * @param entityName  the entity name.
 * @param entityValue the entity value.
 * @param type        the entity type (local, external or predefined)
 * @param markdown    true if the documentation can be formatted as markdown and
 *                    false otherwise.
 * @return the entity documentation.
 */
public static MarkupContent getDocumentation(String entityName, String entityValue, String systemID,
		String publicID, String targetURI, EntityOriginType type, boolean markdown) {
	StringBuilder documentation = new StringBuilder();

	// Title
	if (markdown) {
		documentation.append("**");
	}
	documentation.append("Entity ");
	documentation.append(entityName);
	if (markdown) {
		documentation.append("**");
	}

	addParameter("Value", entityValue, documentation, markdown);
	addParameter("Type", type.getLabel(), documentation, markdown);
	addParameter("Public ID", publicID, documentation, markdown);
	addParameter("System ID", systemID, documentation, markdown);
	if (targetURI != null) {
		documentation.append(System.lineSeparator());
		if (markdown) {
			documentation.append(" * ");
		}
		documentation.append("Source: ");
		if (markdown) {
			documentation.append("[");
			documentation.append(getFileName(targetURI));
			documentation.append("]");
			documentation.append("(");
		}
		documentation.append(targetURI);
		if (markdown) {
			documentation.append(")");
		}
	}
	return new MarkupContent(markdown ? MarkupKind.MARKDOWN : MarkupKind.PLAINTEXT, documentation.toString());
}
 
源代码24 项目: lemminx   文件: EntitiesHoverParticipant.java
/**
 * Returns the markup content of the given entity name in the predefined, local
 * and external entities and null otherwise.
 * 
 * @param entityName  the entity name to search.
 * @param entityRange the hovered range.
 * @param document    the DOM document
 * @param request     the hover request.
 * @return the markup content of the given entity name in the predefined, local
 *         and external entities and null otherwise.
 */
private static MarkupContent searchInEntities(String entityName, Range entityRange, DOMDocument document,
		IHoverRequest request) {
	MarkupContent entityContents = searchInPredefinedEntities(entityName, entityRange, document, request);
	if (entityContents != null) {
		return entityContents;
	}
	entityContents = searchInLocalEntities(entityName, entityRange, document, request);
	if (entityContents != null) {
		return entityContents;
	}
	return searchInExternalEntities(entityName, entityRange, document, request);
}
 
源代码25 项目: lemminx   文件: EntitiesHoverParticipant.java
/**
 * Returns the markup content of the given entity name in the predefined
 * entities and null otherwise.
 * 
 * @param entityName  the entity name to search.
 * @param entityRange the hovered range.
 * @param document    the DOM document
 * @param request     the hover request.
 * @return the markup content of the given entity name in the predefined
 *         entities and null otherwise.
 */
private static MarkupContent searchInPredefinedEntities(String entityName, Range entityRange, DOMDocument document,
		IHoverRequest request) {
	PredefinedEntity[] entities = PredefinedEntity.values();
	for (PredefinedEntity entity : entities) {
		if (entityName.equals(entity.getName())) {
			boolean markdown = request.canSupportMarkupKind(MarkupKind.MARKDOWN);
			return EntitiesDocumentationUtils.getDocumentation(entity.getName(), entity.getValue(),
					EntityOriginType.PREDEFINED, markdown);
		}
	}
	return null;
}
 
源代码26 项目: lemminx   文件: EntitiesCompletionParticipant.java
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);
}
 
源代码27 项目: lemminx   文件: XSISchemaModel.java
private static void createCompletionItem(String attrName, boolean canSupportSnippet, boolean generateValue,
		Range editRange, String defaultValue, Collection<String> enumerationValues, String documentation,
		ICompletionResponse response, SharedSettings sharedSettings){
	CompletionItem item = new AttributeCompletionItem(attrName, canSupportSnippet, editRange, generateValue,
			defaultValue, enumerationValues, sharedSettings);
	MarkupContent markup = new MarkupContent();
	markup.setKind(MarkupKind.MARKDOWN);
	markup.setValue(StringUtils.getDefaultString(documentation));
	item.setDocumentation(markup);
	response.addCompletionItem(item);
}
 
源代码28 项目: lemminx   文件: XSISchemaModel.java
public static Hover computeHoverResponse(DOMAttr attribute, IHoverRequest request) {

		String name = attribute.getName();
		if(!name.startsWith(request.getXMLDocument().getSchemaInstancePrefix() + ":")) {
			return null;
		}

		DOMDocument document = request.getXMLDocument();
		DOMElement root = document.getDocumentElement();
		String doc = null;
		if(root != null) {
			if(root.equals(document.findNodeAt(attribute.getStart()))) {
				if(name.endsWith(":schemaLocation")) {
					doc = SCHEMA_LOCATION_DOC;
				}
				else if(name.endsWith(":noNamespaceSchemaLocation")) {
					doc = NO_NAMESPACE_SCHEMA_LOCATION_DOC;
				}
			}
		} else {
			return null;
		}
		if(doc == null) {
			if(name.endsWith(":nil")) {
				doc = NIL_DOC;
			}
			else if(name.endsWith(":type")) {
				doc = TYPE_DOC;
			}
			else {
				return null;
			}
		}

		MarkupContent content = new MarkupContent();
		content.setKind(MarkupKind.MARKDOWN);
		content.setValue(doc);
		return new Hover(content);
	}
 
源代码29 项目: lemminx   文件: XMLGenerator.java
/**
 * Returns a markup content for element documentation and null otherwise.
 * 
 * @param cmElement
 * @param support
 * @return a markup content for element documentation and null otherwise.
 */
public static MarkupContent createMarkupContent(CMElementDeclaration cmElement, ISharedSettingsRequest support) {
	String documentation = XMLGenerator.generateDocumentation(cmElement.getDocumentation(support),
			cmElement.getDocumentURI(), support.canSupportMarkupKind(MarkupKind.MARKDOWN));
	if (documentation != null) {
		return MarkupContentFactory.createMarkupContent(documentation, MarkupKind.MARKDOWN, support);
	}
	return null;
}
 
源代码30 项目: lemminx   文件: XMLGenerator.java
/**
 * Returns a markup content for attribute name documentation and null otherwise.
 * 
 * @param cmAttribute  the attribute declaration
 * @param ownerElement the owner element declaration
 * @param request      the request
 * @return a markup content for attribute name documentation and null otherwise.
 */
public static MarkupContent createMarkupContent(CMAttributeDeclaration cmAttribute,
		CMElementDeclaration ownerElement, ISharedSettingsRequest request) {
	String documentation = XMLGenerator.generateDocumentation(cmAttribute.getDocumentation(request),
			ownerElement.getDocumentURI(), request.canSupportMarkupKind(MarkupKind.MARKDOWN));
	if (documentation != null) {
		return MarkupContentFactory.createMarkupContent(documentation, MarkupKind.MARKDOWN, request);
	}
	return null;
}
 
 类所在包
 类方法
 同包方法