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.ts — registerSchema() and resolveSchemaForDocument()
Summary
When multiple XML files use the same XSD schema, a new
XsdCompletionProvideris created foreach 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
XsdValidatorServiceworks, which correctly shares one compiledvalidator per unique
xsdKey.Root Cause
In
SchemaProvider.registerSchema(), the completion provider is keyed by document URIinstead of XSD key:
There is no guard to skip re-creation when the same XSD is already parsed. Compare this to the
validator, which has the guard:
Impact
If a workspace has N XML files that all use the same XSD:
XsdValidatorServiceis compiled once ✅XsdCompletionProvideris created N times ❌ — same XSD parsed N times, N identical element Maps held in memoryFor a typical WSO2 project with 20–50 XML files sharing one
synapse_config.xsd, this meansthe XSD is unnecessarily parsed 20–50 times on startup.
Expected Behaviour
XsdCompletionProvidershould be shared per uniquexsdKey(i.e.xsdPath ?? uri), the sameway
XsdValidatorServiceis shared today.Suggested Fix
Key the completion provider by
xsdKeyinstead ofinfo.uri, and add the same guard used forthe validator:
Then update
resolveSchemaForDocument()to look up byxsdKeywhen resolving for a document.Files Affected
src/schema/schemaProvider.ts—registerSchema()andresolveSchemaForDocument()