question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extensions get used even if document doesn't match

See original GitHub issue

As mentioned here, Lemminx-Maven’s “participants” (eg. DiagnosticParticipant) seems to be still used even if the document doesn’t match.

Our implementation of IXMLExtension.match() looks like:

	public static boolean match(DOMDocument document) {
		return document.getDocumentURI().endsWith(pom.xml);
	}

As a workaround, I’m going to try adding the following to each “participant” to prevent processing a non-pom.xml file:

if (!MavenPlugin.match(...)) {
  return;
}

I haven’t looked into how IXMLExtension.match() is being used, but I imagine it’s used to determine whether or not an extension should be started up or not. Perhaps it should also be used when going through the extension registry to determine if an extension’s “participant” function should be called or not.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
angelozerrcommented, Apr 24, 2020

I totally agree that a kind of matcher must be provided because we do that for instance to avoid validating a XML file with the XSD validator which validate syntax of XML Schema (xs:element, etc) and should not be applied for a simple XML file. See https://github.com/eclipse/lemminx/blob/d0a94fd0a9a588450e63f9c2b622c90b0b09b743/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/participants/diagnostics/XSDDiagnosticsParticipant.java#L32

I already thought about and my idea was:

  • provide a new interface IDocumentSelector:
package org.eclipse.lemminx.services.extensions;

import org.eclipse.lemminx.dom.DOMDocument;

public interface IDocumentSelector {

	boolean match(DOMDocument document);
}
  • implement this interface
public class MavenDocumentSelector implements IDocumentSelector  {

	public boolean match(DOMDocument document) {
             return "pom.xml".equals(document.getDocumentURI());
        }
}

  • use it when you register participant on the IXMlExtension#start
registry.registerDiagnosticsParticipant(mavenDocumentSelector, diagnosticsParticipant);
0reactions
AObuchowcommented, Apr 24, 2020

since Match is already defined in the IXMLExtension interface,

No it doesn’t define this match method

You’re right, my mistake. We just happen to have it defined in our class which implements the IXMLExtension interface.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Word cannot open file because file format does not match file ...
The simplest method to resolve this issue is to change the extension for the file manually. To do so, right-click the file and...
Read more >
Regex pattern that does not match certain extensions?
I am trying to figure out how to make it not match ANY .jpg files even if the file's name has 2 or...
Read more >
[Solved] The File Format Does Not Match the File Extension
Solution 1: Change the File Extension Manually. Changing the file extension manually may work when you encounter the “the file format does not ......
Read more >
A file is in a different format than its extension indicates in Excel
When you open a file in Excel, you get an message that the file name extension doesn't match the actual file format. For...
Read more >
Chrome Extensions content scripts
In these cases, the URL will not match the content script's pattern (and, in the case of about: and data: , do not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found