Skip to content

XsdCompletionProvider is not shared across documents that use the same XSD #68

Description

@harshanacz

Summary

When multiple XML files use the same XSD schema, a new XsdCompletionProvider is created for
each file. This means the XSD is parsed and the element Map is rebuilt from scratch every time a
file opens — even when the XSD content is identical.

This is inconsistent with how XsdValidatorService works, which correctly shares one compiled
validator per unique xsdKey.

Root Cause

In SchemaProvider.registerSchema(), the completion provider is keyed by document URI
instead of XSD key:

// schemaProvider.ts
const provider = new XsdCompletionProvider(completionXsd);
this.completionProviders.set(info.uri, provider); // ← one per file, not one per XSD

There is no guard to skip re-creation when the same XSD is already parsed. Compare this to the
validator, which has the guard:

if (!this.validators.has(xsdKey)) { // ← only compiled once per unique XSD
  this.validators.set(xsdKey, await XsdValidatorService.create(xsd));
}

Impact

If a workspace has N XML files that all use the same XSD:

  • XsdValidatorService is compiled once
  • XsdCompletionProvider is created N times ❌ — same XSD parsed N times, N identical element Maps held in memory

For a typical WSO2 project with 20–50 XML files sharing one synapse_config.xsd, this means
the XSD is unnecessarily parsed 20–50 times on startup.

Expected Behaviour

XsdCompletionProvider should be shared per unique xsdKey (i.e. xsdPath ?? uri), the same
way XsdValidatorService is shared today.

Suggested Fix

Key the completion provider by xsdKey instead of info.uri, and add the same guard used for
the validator:

// in registerSchema()
if (!this.completionProviders.has(xsdKey)) {
  const completionXsd = info.imports
    ? inlineIncludes(info.xsdText, info.imports)
    : info.xsdText;
  const provider = new XsdCompletionProvider(completionXsd);
  this.completionProviders.set(xsdKey, provider);
}

Then update resolveSchemaForDocument() to look up by xsdKey when resolving for a document.

Files Affected

  • src/schema/schemaProvider.tsregisterSchema() and resolveSchemaForDocument()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions