apache / daffodil-vscode

Apache Daffodilâ„¢ Extension for Visual Studio Code
https://daffodil.apache.org/
Apache License 2.0
10 stars 20 forks source link

Root element and namespace auto suggestions/finding #984

Open shanedell opened 4 months ago

shanedell commented 4 months ago

As of right now when debugging a schema the user needs to know if a root element name or namespace needs set. It would be nice to have some features where either the extension or the debugger or both can let the user know, what possible root element names or namespaces could be used for the specific schema. For example, with the DFDL envelopePayload schema @mbeckerle created, if the rootName is not set the debugger, extension or both will let the user know that the schema may fail to debug if the rootName is not set to values one of [a, b, ...].

shanedell commented 4 months ago

@stevedlawrence @mbeckerle Does this sound like something may be achievable in a general sense and in the sense of is there anything in Daffodil that may do something similar or help with this?

stevedlawrence commented 4 months ago

Daffodil doesn't really have a way good way to query for all global elements. You could potentially create ProcessorFactory without specifying a root name/namespace (e.g. Compiler.compileFile("path/to/schema.dfdl.xsdf"), and then query members of its SchemaSet to find all possible global element declarations and their namespace, similar to this:

https://github.com/apache/daffodil/blob/main/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaSet.scala#L380-L382

But that's diving pretty deep into the Daffodil internals and probably isn't recommended.

Probably the easiest approach is to just scan the main schema for global element declarations yourself (e.g. find xs:element's that are immediate children of the xs:schema, and suggest those as possible roots. And the suggested namespace is just the targetNmespace property.

Technically the root element could come from any included/imported schema, but that's pretty uncommon--the root almost always comes from the primary schema. And you probably wouldn't want to suggest all those imported global element declarations anyways because there are often a bunch of them them and it would just be confusing to users.