Java Code Examples for org.eclipse.lsp4j.jsonrpc.CancelChecker#checkCanceled()

The following examples show how to use org.eclipse.lsp4j.jsonrpc.CancelChecker#checkCanceled() . 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: EntitiesDefinitionParticipant.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Search the given entity name in the local entities.
 * 
 * @param document      the DOM document.
 * @param entityName    the entity name.
 * @param entityRange   the entity range.
 * @param locations     the location links
 * @param cancelChecker the cancel checker.
 */
private static void searchInLocalEntities(String entityName, Range entityRange, DOMDocument document,
		List<LocationLink> locations, CancelChecker cancelChecker) {
	DOMDocumentType docType = document.getDoctype();
	if (docType == null) {
		return;
	}
	cancelChecker.checkCanceled();
	// Loop for entities declared in the DOCTYPE of the document
	NamedNodeMap entities = docType.getEntities();
	for (int i = 0; i < entities.getLength(); i++) {
		cancelChecker.checkCanceled();
		DTDEntityDecl entity = (DTDEntityDecl) entities.item(i);
		fillEntityLocation(entity, entityName, entityRange, locations);
	}
}
 
Example 2
Source File: XMLTextDocumentService.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private void validate(DOMDocument xmlDocument) throws CancellationException {
	CancelChecker cancelChecker = xmlDocument.getCancelChecker();
	cancelChecker.checkCanceled();
	getXMLLanguageService().publishDiagnostics(xmlDocument,
			params -> xmlLanguageServer.getLanguageClient().publishDiagnostics(params),
			(doc) -> triggerValidationFor(doc), sharedSettings.getValidationSettings(), cancelChecker);
}
 
Example 3
Source File: XSDUtils.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private static void searchXSOriginAttributes(NodeList nodes, List<DOMAttr> targetAttrs,
		String targetNamespacePrefix, BiConsumer<DOMAttr, DOMAttr> collector, CancelChecker cancelChecker) {
	for (int i = 0; i < nodes.getLength(); i++) {
		if (cancelChecker != null) {
			cancelChecker.checkCanceled();
		}
		Node node = nodes.item(i);
		if (node.getNodeType() == Node.ELEMENT_NODE) {
			DOMElement originElement = (DOMElement) node;
			NamedNodeMap originAttributes = originElement.getAttributes();
			if (originAttributes != null) {
				for (int j = 0; j < originAttributes.getLength(); j++) {
					DOMAttr originAttr = (DOMAttr) originAttributes.item(j);
					BindingType originBnding = XSDUtils.getBindingType(originAttr);
					if (originBnding != BindingType.NONE) {
						String originName = getOriginName(originAttr.getValue(), targetNamespacePrefix);
						for (DOMAttr targetAttr : targetAttrs) {
							Element targetElement = targetAttr.getOwnerElement();
							if (isBounded(originAttr.getOwnerElement(), originBnding, targetElement)) {
								// node is a xs:complexType, xs:simpleType element, xsl:element, xs:group which
								// matches the binding type of the originAttr
								if (targetAttr != null && (Objects.equal(originName, targetAttr.getValue()))) {
									collector.accept(originAttr, targetAttr);
								}
							}
						}
					}
				}
			}
		}
		if (node.hasChildNodes()) {
			searchXSOriginAttributes(node.getChildNodes(), targetAttrs, targetNamespacePrefix, collector,
					cancelChecker);
		}
	}

}
 
Example 4
Source File: MultiCancelChecker.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void checkCanceled() {
	for (CancelChecker cancelChecker : checkers) {
		cancelChecker.checkCanceled();
	}
}
 
Example 5
Source File: DTDUtils.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Search origin DTD node (<!ATTRLIST element-name) or (child <!ELEMENT
 * element-name (child)) from the given target DTD node (<!ELEMENT element-name.
 * 
 * @param targetNode the referenced node
 * @param collector  the collector to collect reference between an origin and
 *                   target attribute.
 */
public static void searchDTDOriginElementDecls(DTDDeclNode targetNode,
		BiConsumer<DTDDeclParameter, DTDDeclParameter> collector, CancelChecker cancelChecker) {
	// Collect all potential target DTD nodes (all <!ELEMENT)
	List<DTDDeclNode> targetNodes = getTargetNodes(targetNode);
	if (targetNodes.isEmpty()) {
		// None referenced nodes, stop the search of references
		return;
	}

	// Loop for each <!ELEMENT and check for each target DTD nodes if it reference
	// it.
	DOMDocumentType docType = targetNode.getOwnerDocType();
	if (docType.hasChildNodes()) {
		// Loop for <!ELEMENT.
		NodeList children = docType.getChildNodes();
		for (int i = 0; i < children.getLength(); i++) {
			if (cancelChecker != null) {
				cancelChecker.checkCanceled();
			}
			Node origin = children.item(i);
			for (DTDDeclNode target : targetNodes) {
				if (target.isDTDElementDecl()) {
					// target node is <!ELEMENT, check if it is references by the current origin
					// node
					DTDElementDecl targetElement = (DTDElementDecl) target;
					switch (origin.getNodeType()) {
					case DOMNode.DTD_ELEMENT_DECL_NODE:
						// check if the current <!ELEMENT origin defines a child which references the
						// target node <!ELEMENT
						// <!ELEMENT from > --> here target node is 'from'
						// <!ELEMENT note(from)> --> here origin node is 'note'
						// --> here 'note' has a 'from' as child and it should be collected
						DTDElementDecl originElement = (DTDElementDecl) origin;
						originElement.collectParameters(targetElement.getNameParameter(), collector);
						break;
					case DOMNode.DTD_ATT_LIST_NODE:
						String name = targetElement.getName();
						// check if the current <!ATTLIST element-name reference the current <!ELEMENT
						// element-name
						// <!ELEMENT note --> here target node is 'note'
						// <!ATTLIST note ... -> here origin node is 'note'
						// --> here <!ATTLIST defines 'note' as element name, and it should be collected
						DTDAttlistDecl originAttribute = (DTDAttlistDecl) origin;
						if (name.equals(originAttribute.getElementName())) {
							// <!ATTLIST origin has the same name than <!ELEMENT target
							collector.accept(originAttribute.getNameParameter(), targetElement.getNameParameter());
						}
						break;
					}
				}
			}
		}
	}
}
 
Example 6
Source File: WorkspaceSymbolProvider.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
public List<? extends SymbolInformation> workspaceSymbol(WorkspaceSymbolParams params, CancelChecker cancelToken)
{
	cancelToken.checkCanceled();
	Set<String> qualifiedNames = new HashSet<>();
	List<SymbolInformation> result = new ArrayList<>();
	String query = params.getQuery();
	StringBuilder currentQuery = new StringBuilder();
	List<String> queries = new ArrayList<>();
	for(int i = 0, length = query.length(); i < length; i++)
	{
		String charAtI = query.substring(i, i + 1);
		if(i > 0 && charAtI.toUpperCase().equals(charAtI))
		{
			queries.add(currentQuery.toString().toLowerCase());
			currentQuery = new StringBuilder();
		}
		currentQuery.append(charAtI);
	}
	if(currentQuery.length() > 0)
	{
		queries.add(currentQuery.toString().toLowerCase());
	}
	for (WorkspaceFolder folder : workspaceFolderManager.getWorkspaceFolders())
	{
		WorkspaceFolderData folderData = workspaceFolderManager.getWorkspaceFolderData(folder);
		ILspProject project = folderData.project;
		if (project == null)
		{
			continue;
		}
		for (ICompilationUnit unit : project.getCompilationUnits())
		{
			if (unit == null)
			{
				continue;
			}
			UnitType unitType = unit.getCompilationUnitType();
			if (UnitType.SWC_UNIT.equals(unitType))
			{
				List<IDefinition> definitions = unit.getDefinitionPromises();
				for (IDefinition definition : definitions)
				{
					if (definition instanceof DefinitionPromise)
					{
						//we won't be able to detect what type of definition
						//this is without getting the actual definition from the
						//promise.
						DefinitionPromise promise = (DefinitionPromise) definition;
						definition = promise.getActualDefinition();
					}
					if (definition.isImplicit())
					{
						continue;
					}
					if (!matchesQueries(queries, definition.getQualifiedName()))
					{
						continue;
					}
					String qualifiedName = definition.getQualifiedName();
					if (qualifiedNames.contains(qualifiedName))
					{
						//we've already added this symbol
						//this can happen when there are multiple root
						//folders in the workspace
						continue;
					}
					SymbolInformation symbol = workspaceFolderManager.definitionToSymbolInformation(definition, project);
					if (symbol != null)
					{
						qualifiedNames.add(qualifiedName);
						result.add(symbol);
					}
				}
			}
			else if (UnitType.AS_UNIT.equals(unitType) || UnitType.MXML_UNIT.equals(unitType))
			{
				IASScope[] scopes;
				try
				{
					scopes = unit.getFileScopeRequest().get().getScopes();
				}
				catch (Exception e)
				{
					return Collections.emptyList();
				}
				for (IASScope scope : scopes)
				{
					querySymbolsInScope(queries, scope, qualifiedNames, project, result);
				}
			}
		}
	}
	cancelToken.checkCanceled();
	return result;
}
 
Example 7
Source File: XMLDiagnostics.java    From lemminx with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Do validation with extension (XML Schema, etc)
 * 
 * @param xmlDocument
 * @param diagnostics
 * @param monitor
 */
private void doExtensionsDiagnostics(DOMDocument xmlDocument, List<Diagnostic> diagnostics, CancelChecker monitor) {
	for (IDiagnosticsParticipant diagnosticsParticipant : extensionsRegistry.getDiagnosticsParticipants()) {
		monitor.checkCanceled();
		diagnosticsParticipant.doDiagnostics(xmlDocument, diagnostics, monitor);
	}
}