Class HeadLimitRules

java.lang.Object
org.eclipse.lemminx.extensions.index.HeadLimitRules

public final class HeadLimitRules extends Object
Compiled form of the xml.workspaceIndex.headLimits setting.

Keys in the raw settings map are glob patterns (e.g. "**/*.xsd", "**/vendor/**"). This class compiles them once into an ordered list of HeadLimitRules.Rules and resolves the limit for a given file path efficiently.

Matching rule: rules are sorted by pattern length descending; the longest (most-specific) pattern wins. The first matching rule is returned.

Rule types and fast paths:

  • Match-all ("*", "**", "**/*") - always matches, O(1). "*" is accepted as a user-friendly alias for "any file" even though bare * does not cross path separators in strict glob semantics.
  • Extension-only ("*.ext" or "**/*.ext") - matched via a string comparison on the file extension, O(1), no PathMatcher needed.
  • Path-based (everything else, e.g. "**/vendor/**") - uses PathMatcher.matches(Path) on the absolute path, computed lazily only when the rule is first reached. When the pattern ends with *.ext, an O(1) extension pre-filter skips the PathMatcher call for files whose extension does not match.
See Also:
  • Field Details

    • NONE

      public static final HeadLimitRules NONE
      Sentinel used when no headLimits are configured — no limit for any file.
  • Method Details

    • compile

      public static HeadLimitRules compile(Map<String,String> raw)
      Compiles a raw glob-pattern→size-string map into a HeadLimitRules instance.
      Parameters:
      raw - map from glob pattern to size string; null or empty → NONE.
      Returns:
      compiled rules, ready for repeated getLimit(Path) calls.
    • getLimit

      public int getLimit(Path path)
      Returns the head-read limit (in chars) for path. Returns Integer.MAX_VALUE when no rule matches (no limit — read the whole file).
      Parameters:
      path - the file being indexed; may be relative or absolute.
      Returns:
      character limit, or Integer.MAX_VALUE for no limit.