Add a completion-oriented schema wrapper#2006
Add a completion-oriented schema wrapper#2006rjoussen wants to merge 1 commit into4C-multiphysics:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a completion-oriented JSON Schema wrapper to improve VS Code top-level section auto-completion for .4C.yaml files (closes #2002).
Changes:
- Extend the internal JSON Schema draft-2020-12 model to support
anyOf,allOf,propertyNames,defaultSnippets, and$ref. - Generate an additional “completion schema” JSON file that exposes all top-level keys via
propertyNamesand provides a default snippet for function sections, while delegating validation to the full schema.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
utilities/four_c_python/src/four_c_metadata/json_schema_draft_2020_12.py |
Adds schema keyword/model support needed by the completion wrapper (anyOf/allOf, propertyNames, defaultSnippets, $ref). |
utilities/four_c_python/src/four_c_metadata/json_schema.py |
Implements completion-schema generation and writes the additional completion schema file alongside the existing full/partial schemas. |
| completion_schema = create_completion_schema( | ||
| properties_names=list(properties.schemas.keys()), | ||
| json_schema_path=json_schema_path, | ||
| function_regex=function_regex, | ||
| function_section_name=function_section_name, | ||
| function_id_label=function_id_label, | ||
| ) | ||
|
|
||
| json_completion_schema_path = json_schema_path.with_stem( | ||
| completion_schema_stem(json_schema_path.stem) | ||
| ) | ||
| json_completion_schema_path.write_text( | ||
| json.dumps(completion_schema.to_dict(), indent=2) | ||
| ) |
There was a problem hiding this comment.
This change modifies schema generation under utilities/four_c_python/src/four_c_metadata. Per the project guideline, please ensure the generated completion schema is tested for compatibility with fourcipp (and port the change there if fourcipp maintains a copy/fork of this schema generation logic).
There was a problem hiding this comment.
Since the normal schema remains unchanged, this probably won't be a problem, @davidrudlstorfer?
There was a problem hiding this comment.
Unfortunately, I do not know 100%, maybe you can just briefly test it.
As you've said, as long as the old schema is the same it will (99,999% sure) work.
But probably it would make sense to add some sort of testing on that schema either here in 4C or in FourCIPP?
Furthermore, this schema should also be added to FourCIPP so each version is available like the current schema (<= This is the most important point). This would also necessitate to upload the schema during build like the other schema and metadata file. See
4C/.github/workflows/nightly_tests.yml
Lines 128 to 141 in dd555b4
Exposing all propertyNames and a default snippets for function definitions.
9079f87 to
e2d6d1f
Compare
| completion_schema = create_completion_schema( | ||
| properties_names=list(properties.schemas.keys()), | ||
| json_schema_path=json_schema_path, | ||
| function_regex=function_regex, | ||
| function_section_name=function_section_name, | ||
| function_id_label=function_id_label, | ||
| ) | ||
|
|
||
| json_completion_schema_path = json_schema_path.with_stem( | ||
| completion_schema_stem(json_schema_path.stem) | ||
| ) | ||
| json_completion_schema_path.write_text( | ||
| json.dumps(completion_schema.to_dict(), indent=2) | ||
| ) |
There was a problem hiding this comment.
Unfortunately, I do not know 100%, maybe you can just briefly test it.
As you've said, as long as the old schema is the same it will (99,999% sure) work.
But probably it would make sense to add some sort of testing on that schema either here in 4C or in FourCIPP?
Furthermore, this schema should also be added to FourCIPP so each version is available like the current schema (<= This is the most important point). This would also necessitate to upload the schema during build like the other schema and metadata file. See
4C/.github/workflows/nightly_tests.yml
Lines 128 to 141 in dd555b4
Description and Context
This suggests adding a completion-oriented JSON schema which essentially wraps our normal schema and, for me at least, is a lot better at auto-completion of section names (see #2002).
Basically, a new schema is created (called
4C_completion_schema.jsonfor now) that lists all section names aspropertyNames, adefaultSnippetfor the function section, and references the normal schema for the actual validation part. The completion-oriented schema can (but doesn't have to!) be referenced in VS Code to benefit from better top-level auto-completion.The existing schema remains unchanged.
If we want to add this, I will also change the documentation accordingly.
Related Issues and Pull Requests
Closes #2002