-
-
Notifications
You must be signed in to change notification settings - Fork 39
feat(lsp): add tombi/getSchemas command to fetch the current document schemas
#1444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new LSP command tombi/getSchemas to fetch the resolved schemas for a TOML document. This complements the existing tombi/listSchemas command by returning document-specific schemas that are active for a particular file, including schemas from configuration, catalogs, and document directives.
Changes:
- Added
tombi/getSchemasLSP command with handler implementation - Extended schema configuration to support optional
titleanddescriptionfields - Added
SchemaSourceenum to track schema origins (Catalog, Config, Directive)
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| www.schemastore.org/tombi.json | Added title and description properties to RootSchema and SubSchema definitions |
| docs/src/routes/docs/language-server/command.mdx | Added documentation for the new tombi/getSchemas command |
| docs/src/routes/docs/configuration.mdx | Updated schema configuration documentation to include title and description fields |
| crates/tombi-schema-store/src/store.rs | Updated schema initialization to use title/description from config and set schema source |
| crates/tombi-schema-store/src/schema.rs | Added SchemaSource enum to track schema origin |
| crates/tombi-lsp/src/handler/get_schemas.rs | New handler implementation for tombi/getSchemas command |
| crates/tombi-lsp/src/handler/list_schemas.rs | Made SchemaInfo cloneable and deserializable for reuse |
| crates/tombi-lsp/src/backend.rs | Added get_schemas method to Backend |
| crates/tombi-lsp/src/lib.rs | Registered new custom method and exported types |
| crates/tombi-config/src/schema.rs | Added title and description fields to RootSchema and SubSchema, implemented Default trait |
| crates/tombi-lsp/tests/test_get_schemas.rs | Added test coverage for the new command |
| Multiple test files | Updated to use ..Default::default() for schema construction |
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
98b1c32 to
09d1550
Compare
09d1550 to
a22b2d2
Compare
| toml_version: None, | ||
| path, | ||
| include: vec!["*.toml".to_string()], | ||
| ..Default::default() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to make this clear so that additions to elements can be detected at compile time.
title: None,
description: None| pub enum SchemaSource { | ||
| Catalog, | ||
| Config, | ||
| Directive, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are at least the following three patterns:
- Injection via Third Party VSCode Extension
- Injection via Command
- Injection via Comment Directive
Since these classifications are very difficult, it would be wise not to specify them.
| .custom_method("tombi/getStatus", Backend::get_status) | ||
| .custom_method("tombi/getTomlVersion", Backend::get_toml_version) | ||
| .custom_method("tombi/listSchemas", Backend::list_schemas) | ||
| .custom_method("tombi/getSchemas", Backend::get_schemas) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tombi/getStatus command already exists, so it would be better to add rootSchema and subSchemas there.
interface GetStatusResponse {
tomlVersion: string;
source: "comment" | "schema" | "config" | "default";
configPath?: string;
ignore?: "include-file-pattern-not-matched" | "exclude-file-pattern-matched";
schemaPath?: string;
subSchemas?: {
root: string;
schemaPath: string;
}[]
}| #[derive(Debug, Clone, PartialEq)] | ||
| #[derive(Debug, Default, Clone, PartialEq)] | ||
| pub struct RootSchema { | ||
| /// # Title of the schema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON Schema may include title/description. I prefer not to set information redundantly if it's already in the schema file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a good idea to add title/description to config.
|
I've created a PR to update getStatus. Adding title/description to the schema might require significant changes to existing code. Do you need title/description for your use case? |
|
@ya7010 Sorry, I didn't had an opportunity to get back on it before today. I'll answer all your questions/remarks there:
Yes, at least the title. It's for user facing display (status bar, reporting...). While I can work around for JSON Schema Store schemas by rematching with the URI, I can't for tombi internal schemas, config schemas... And it's duplicating the LSP work.
I haven't yet read your PR, but is it due to embedding this into
The way I see it, the config is just another store. JSON Schema Store catalog entries are Also
I thought it was a good idea to keep the origin of a schema (at least to be able to answer "where does it come from" and "why is it active".
WDYT ? |
I think a lot of this differences in opinions come down to whether we're basing it on Schema Store or JSON Schema. Config and SchemaStore are just ways to fetch schemas. URI/Path is the simplest way to represent them. TOML might get its own schema language down the line, and SchemaStore is a simple system without stuff like version control, so we can't really revolve everything around SchemaStore.
This is mainly due to attempting to support subschemas. The existing mechanism does not consider title/description, requiring a major overhaul.
Your idea is good. The problem is that |
|
In the previous discussion, there was no reason to dynamically switch the configurations specified in Config, so the motivation for For now, I will limit it to obtaining only the available Implementing sub-schemas has been a bit challenging, and I haven't worked on Tombi for a while, so I've forgotten the knowledge. I need some time for the new API. |
|
Don't worry, I am already thrilled you took time to answer and time to implement. If sub-schemas are challenging, maybe they can be left-out in the initial implementation. I think the most important is the root schema:
|
|
Sorry for the delay, but I've updated |
|
Oh thank you very much!! ππΌ |
Hi ππΌ
Following #1423, I now have the LSP schemas listing since the release v0.7.19 (thanks for it) but I was still missing the document schemas. I tried using the hover and/or goToDefinition, but this only works on a valid statements so it's not possible to know which schemas is active on an empty document, on root whitespaces or on invalid nodes.
Given it seems not that complicated as the schemas were already retrieved at multiple place, I gave it try.
So there it is, this PR adds:
tombi/getSchemasLSP method with its documentation, it returns the same format thattombi/listSchemastitleanddescriptionon config schemasSchema declared using the schema directive have a special name "Document Directive Schema"