Java Code Examples for org.eclipse.lsp4j.MarkupContent#setKind()

The following examples show how to use org.eclipse.lsp4j.MarkupContent#setKind() . 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: MarkupContentFactory.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: SnippetUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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);
	}
}
 
Example 3
Source File: PrologModel.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: XSISchemaModel.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: XSISchemaModel.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
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);
	}
 
Example 6
Source File: CompletionItemBuilder.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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");

    MarkupContent markupContent = new MarkupContent();
    markupContent.setKind(MarkupKind.MARKDOWN);
    markupContent.setValue(String.format("```%s%n%s%n```", "java", escapedString));
    return Either.forRight(markupContent);
}