Skip to content

Add a completion-oriented schema wrapper#2006

Open
rjoussen wants to merge 1 commit into4C-multiphysics:mainfrom
rjoussen:enhance-auto-completion
Open

Add a completion-oriented schema wrapper#2006
rjoussen wants to merge 1 commit into4C-multiphysics:mainfrom
rjoussen:enhance-auto-completion

Conversation

@rjoussen
Copy link
Copy Markdown
Contributor

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.json for now) that lists all section names as propertyNames, a defaultSnippet for 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

@rjoussen rjoussen requested a review from gilrrei April 28, 2026 15:55
@rjoussen rjoussen self-assigned this Apr 28, 2026
Copilot AI review requested due to automatic review settings April 28, 2026 15:55
@rjoussen rjoussen added type: enhancement A new feature or enhancement to be implemented team: input labels Apr 28, 2026
@rjoussen rjoussen changed the title Add a completion schema wrapper Add a completion-oriented schema wrapper Apr 28, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 propertyNames and 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.

Comment thread utilities/four_c_python/src/four_c_metadata/json_schema.py
Comment thread utilities/four_c_python/src/four_c_metadata/json_schema.py
Comment on lines +498 to +511
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)
)
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot generated this review using guidance from repository custom instructions.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the normal schema remains unchanged, this probably won't be a problem, @davidrudlstorfer?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

- name: Upload 4C schema
uses: actions/upload-artifact@v7
with:
name: ${{ github.job }}-schema
path: |
${{ github.workspace }}/build/4C_schema.json
retention-days: 30
- name: Upload 4C metadata
uses: actions/upload-artifact@v7
with:
name: ${{ github.job }}-metadata
path: |
${{ github.workspace }}/build/4C_metadata.yaml
retention-days: 30

@rjoussen rjoussen marked this pull request as draft April 29, 2026 07:29
Exposing all propertyNames and a default snippets for function
definitions.
@rjoussen rjoussen force-pushed the enhance-auto-completion branch from 9079f87 to e2d6d1f Compare April 29, 2026 08:06
@rjoussen rjoussen marked this pull request as ready for review April 29, 2026 12:45
Comment on lines +498 to +511
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)
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

- name: Upload 4C schema
uses: actions/upload-artifact@v7
with:
name: ${{ github.job }}-schema
path: |
${{ github.workspace }}/build/4C_schema.json
retention-days: 30
- name: Upload 4C metadata
uses: actions/upload-artifact@v7
with:
name: ${{ github.job }}-metadata
path: |
${{ github.workspace }}/build/4C_metadata.yaml
retention-days: 30

Comment thread utilities/four_c_python/src/four_c_metadata/json_schema.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team: input type: enhancement A new feature or enhancement to be implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vs-code .4C.yaml top-level auto-completion is bad

3 participants