org.eclipse.lsp4j.MarkupKind Java Examples

The following examples show how to use org.eclipse.lsp4j.MarkupKind. 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: SnippetRegistry.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
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());
}
 
Example #2
Source File: XMLSchemaCompletionExtensionsTest.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void documentationAsPlainText() throws BadLocationException {
	String xml = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\r\n" + //
			"	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
			"	xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\r\n"
			+ //
			"	<|" + //
			"</project>";
	testCompletionFor(xml, c("groupId", te(3, 1, 3, 2, "<groupId></groupId>"), "<groupId",
			"3.0.0+" + //
					System.lineSeparator() + //
					System.lineSeparator() + //
					"A universally unique identifier for a project. It is normal to use " + //
					"a fully-qualified package name to distinguish it from other projects with a similar name " + // 
					"(eg. org.apache.maven)." + //
					System.lineSeparator() + //
					System.lineSeparator() + //
					"Source: maven-4.0.0.xsd",
			MarkupKind.PLAINTEXT));
}
 
Example #3
Source File: XMLSchemaCompletionExtensionsTest.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void documentationAsMarkdown() throws BadLocationException, MalformedURIException {
	String xml = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\r\n" + //
			"	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
			"	xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\r\n"
			+ //
			"	<|" + //
			"</project>";

	String mavenFileURI = getXMLSchemaFileURI("maven-4.0.0.xsd");
	testCompletionMarkdownSupportFor(xml, c("groupId", te(3, 1, 3, 2, "<groupId></groupId>"), "<groupId",
			"3.0.0+" + //
					System.lineSeparator() + //
					System.lineSeparator() + //
					"A universally unique identifier for a project. It is normal to use " + //
					"a fully-qualified package name to distinguish it from other projects with a similar name " + // 
					"(eg. `org.apache.maven`)." + //
					System.lineSeparator() + //
					System.lineSeparator() + //
					"Source: [maven-4.0.0.xsd](" + mavenFileURI + ")",
			MarkupKind.MARKDOWN));
}
 
Example #4
Source File: CMXSDAttributeDeclaration.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getValueDocumentation(String value, ISharedSettingsRequest request) {
	SchemaDocumentationType currStrategy = request.getSharedSettings().getPreferences().getShowSchemaDocumentationType();
	if (this.docStrategy != currStrategy) {
		clearDocumentation();
	}
	String documentation = valuesDocumentation.get(value);
	if (documentation != null) {
		return documentation;
	}
	this.docStrategy = currStrategy;
	// Try get xs:annotation from the element declaration or type
	XSObjectList annotations = getValueAnnotations();
	boolean markdownSupported = request.canSupportMarkupKind(MarkupKind.MARKDOWN);
	documentation = new XSDDocumentation(annotations, value, docStrategy, !markdownSupported)
			.getFormattedDocumentation(markdownSupported);
	valuesDocumentation.put(value, documentation);
	return documentation;
}
 
Example #5
Source File: CMXSDAttributeDeclaration.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getDocumentation(ISharedSettingsRequest request) {
	SchemaDocumentationType currStrategy = request.getSharedSettings().getPreferences().getShowSchemaDocumentationType();
	if (this.docStrategy != currStrategy) {
		clearDocumentation();
	} else if (this.attrDocumentation != null) {
		return this.attrDocumentation;
	}
	this.docStrategy = currStrategy;
	// Try get xs:annotation from the element declaration or type
	XSObjectList annotations = getAnnotations();
	boolean markdownSupported = request.canSupportMarkupKind(MarkupKind.MARKDOWN);
	this.attrDocumentation = new XSDDocumentation(annotations, docStrategy, !markdownSupported)
			.getFormattedDocumentation(markdownSupported);
	return this.attrDocumentation;
}
 
Example #6
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 #7
Source File: EntitiesHoverParticipant.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: EntitiesHoverParticipant.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: MarkupContentFactory.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #10
Source File: MarkupContentFactory.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #11
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 #12
Source File: ClientPreferences.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isSupportsCompletionDocumentationMarkdown() {
	//@formatter:off
	return v3supported && capabilities.getTextDocument().getCompletion() != null
			&& capabilities.getTextDocument().getCompletion().getCompletionItem() != null
			&& capabilities.getTextDocument().getCompletion().getCompletionItem().getDocumentationFormat() != null
			&& capabilities.getTextDocument().getCompletion().getCompletionItem().getDocumentationFormat().contains(MarkupKind.MARKDOWN);
	//@formatter:on
}
 
Example #13
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCompletion_javadocMarkdown() throws Exception {
	IJavaProject javaProject = JavaCore.create(project);
	ClientPreferences mockCapabilies = Mockito.mock(ClientPreferences.class);
	Mockito.when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
	Mockito.when(mockCapabilies.isSupportsCompletionDocumentationMarkdown()).thenReturn(true);
	ICompilationUnit unit = (ICompilationUnit) javaProject.findElement(new Path("org/sample/TestJavadoc.java"));
	unit.becomeWorkingCopy(null);
	String joinOnCompletion = System.getProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION);
	try {
		System.setProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION, "true");
		int[] loc = findCompletionLocation(unit, "inner.");
		CompletionParams position = JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]));
		String source = unit.getSource();
		changeDocument(unit, source, 3);
		Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor());
		changeDocument(unit, source, 4);
		CompletionList list = server.completion(position).join().getRight();
		CompletionItem resolved = server.resolveCompletionItem(list.getItems().get(0)).join();
		MarkupContent markup = resolved.getDocumentation().getRight();
		assertNotNull(markup);
		assertEquals(MarkupKind.MARKDOWN, markup.getKind());
		assertEquals("Test", markup.getValue());
	} finally {
		unit.discardWorkingCopy();
		if (joinOnCompletion == null) {
			System.clearProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION);
		} else {
			System.setProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION, joinOnCompletion);
		}
	}
}
 
Example #14
Source File: MicroProfileConfigHoverParticipant.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #15
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);
}
 
Example #16
Source File: XMLSchemaCompletionExtensionsTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private void testCompletionSnippetSupportFor(String xml, String fileURI, Integer expectedCount,
		CompletionItem... expectedItems) throws BadLocationException {
	CompletionCapabilities completionCapabilities = new CompletionCapabilities();
	CompletionItemCapabilities completionItem = new CompletionItemCapabilities(true);
	completionItem.setDocumentationFormat(Arrays.asList(MarkupKind.MARKDOWN));
	completionCapabilities.setCompletionItem(completionItem);

	SharedSettings sharedSettings = new SharedSettings();
	sharedSettings.getCompletionSettings().setCapabilities(completionCapabilities);
	XMLAssert.testCompletionFor(new XMLLanguageService(), xml, null, null, fileURI, null, sharedSettings,
			expectedItems);
}
 
Example #17
Source File: XMLSchemaCompletionExtensionsTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private void testCompletionMarkdownSupportFor(String xml, CompletionItem... expectedItems)
		throws BadLocationException {
	CompletionCapabilities completionCapabilities = new CompletionCapabilities();
	CompletionItemCapabilities completionItem = new CompletionItemCapabilities(false);
	completionItem.setDocumentationFormat(Arrays.asList(MarkupKind.MARKDOWN));
	completionCapabilities.setCompletionItem(completionItem);

	SharedSettings sharedSettings = new SharedSettings();
	sharedSettings.getCompletionSettings().setCapabilities(completionCapabilities);
	XMLAssert.testCompletionFor(new XMLLanguageService(), xml, "src/test/resources/catalogs/catalog.xml", null,
			null, null, sharedSettings, expectedItems);
}
 
Example #18
Source File: CompletionItemUtils.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
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 #19
Source File: DTDCompletionExtensionsTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCompletionDocumentationWithSource() throws BadLocationException {
	// completion on <|
	String xml = "<?xml version=\"1.0\"?>\r\n" + //
			"  <!DOCTYPE catalog\r\n" + //
			"    PUBLIC \"-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN\"\r\n" + //
			"           \"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd\">\r\n" + //
			"\r\n" + //
			"  <|";
	testCompletionFor(xml,
			c("catalog", te(5, 2, 5, 3, "<catalog>$1</catalog>$0"), "<catalog",
					" $Id: catalog.dtd,v 1.10 2002/10/18 23:54:58 ndw Exp $ " + System.lineSeparator()
							+ System.lineSeparator() + "Source: catalog.dtd",
					MarkupKind.PLAINTEXT));
}
 
Example #20
Source File: XMLSchemaHoverDocumentationTypeTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private SharedSettings createSharedSettings(SchemaDocumentationType docSource, boolean markdownSupported) {
	SharedSettings settings = new SharedSettings();
	if (markdownSupported) {
		HoverCapabilities capabilities = new HoverCapabilities(Arrays.asList(MarkupKind.MARKDOWN), false);
		settings.getHoverSettings().setCapabilities(capabilities);
	}
	settings.getPreferences()
			.setShowSchemaDocumentationType(docSource);
	return settings;
}
 
Example #21
Source File: XSDCompletionExtensionsTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void completionWithSourceDescriptionAndDocumentation() throws BadLocationException {
	String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + //
			"<invoice xmlns=\"http://invoice\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n"
			+ " xsi:schemaLocation=\"http://invoice xsd/invoice.xsd \">\r\n" + //
			"  <|";
	String lineSeparator = System.getProperty("line.separator");
	XMLAssert.testCompletionFor(xml, null, "src/test/resources/invoice.xml", null,
			c("date", te(3, 2, 3, 3, "<date></date>"), "<date",
					"Date Description" + lineSeparator + lineSeparator + "Source: invoice.xsd", MarkupKind.PLAINTEXT));
}
 
Example #22
Source File: XMLAssert.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
public static void assertHover(XMLLanguageService xmlLanguageService, String value, String catalogPath,
		String fileURI, String expectedHoverLabel, Range expectedHoverRange, ContentModelSettings settings)
		throws BadLocationException {
	SharedSettings sharedSettings = new SharedSettings();
	HoverCapabilities capabilities = new HoverCapabilities(Arrays.asList(MarkupKind.MARKDOWN), false);
	sharedSettings.getHoverSettings().setCapabilities(capabilities);
	assertHover(xmlLanguageService, value, catalogPath, fileURI, expectedHoverLabel, expectedHoverRange, settings,
			sharedSettings);
}
 
Example #23
Source File: ContentModelHoverParticipant.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private static Hover getCacheWarningHover(CacheResourceDownloadingException e, ISharedSettingsRequest support) {
	// Here cache is enabled and some XML Schema, DTD, etc are loading
	MarkupContent content = MarkupContentFactory.createMarkupContent(
			"Cannot process " + (e.isDTD() ? "DTD" : "XML Schema") + " hover: " + e.getMessage(),
			MarkupKind.MARKDOWN, support);
	return new Hover(content);
}
 
Example #24
Source File: XMLGenerator.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns a markup content for element text documentation and null otherwise.
 * 
 * @param cmElement   element declaration.
 * @param textContent the text content.
 * @param support     markup kind support.
 * 
 * @return a markup content for element text documentation and null otherwise.
 */
public static MarkupContent createMarkupContent(CMElementDeclaration cmElement, String textContent,
		ISharedSettingsRequest support) {
	String documentation = XMLGenerator.generateDocumentation(cmElement.getValueDocumentation(textContent),
			cmElement.getDocumentURI(), support.canSupportMarkupKind(MarkupKind.MARKDOWN));
	if (documentation != null) {
		return MarkupContentFactory.createMarkupContent(documentation, MarkupKind.MARKDOWN, support);
	}
	return null;
}
 
Example #25
Source File: XMLGenerator.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #26
Source File: XMLGenerator.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #27
Source File: CMXSDElementDeclaration.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getDocumentation(ISharedSettingsRequest request) {
	SchemaDocumentationType currStrategy = request.getSharedSettings().getPreferences().getShowSchemaDocumentationType();
	if (this.documentation != null && this.docStrategy == currStrategy) {
		return this.documentation;
	}

	this.docStrategy = currStrategy;
	XSObjectList annotations = getAnnotations();
	boolean markdownSupported = request.canSupportMarkupKind(MarkupKind.MARKDOWN);
	this.documentation = (new XSDDocumentation(annotations, docStrategy, !markdownSupported))
			.getFormattedDocumentation(markdownSupported);
	return this.documentation;
}
 
Example #28
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 #29
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 #30
Source File: EntitiesCompletionParticipant.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onXMLContent(ICompletionRequest request, ICompletionResponse response) throws Exception {
	EntityReferenceRange entityRange = XMLPositionUtility.selectEntityReference(request.getOffset(),
			request.getXMLDocument(), false);
	if (entityRange == null) {
		return;
	}
	Range range = entityRange.getRange();
	// There is the '&' character before the offset where completion was triggered
	boolean markdown = request.canSupportMarkupKind(MarkupKind.MARKDOWN);
	DOMDocument document = request.getXMLDocument();
	collectLocalEntityProposals(document, range, markdown, response);
	collectExternalEntityProposals(document, range, markdown, request, response);
	collectPredefinedEntityProposals(range, markdown, response);
}