tamasfe / taplo

A TOML toolkit written in Rust
https://taplo.tamasfe.dev
MIT License
1.43k stars 114 forks source link

Relative paths in `"evenBetterToml.schema.associations"` not working in VS Code #479

Open rhenescu opened 1 year ago

rhenescu commented 1 year ago

Thank you for creating this extension!

Using Windows 10 + VS Code 1.82.2 + Even Better TOML 0.19.2, with the following folder structure:

🗃️ P:
 └─ 📂 Projects
     └─ 📁 App  <- Workspace root
         ├─ 📁 .vscode
         │   ├─ 📄 extensions.json
         │   └─ 📄 settings.json
         └─ 📁 src
             ├─ 📁 schema
             │   └─ 📄 app.schema.json
             └─ 📁 template
                 └─ 📄 template.app.toml

.vscode/settings.json contents:

{
    "evenBetterToml.schema.associations": {
        "^.*\\.app\\.toml$": "./src/schema/app.schema.json"
    }
}

Reading the LSP error in VS Code, it appears that the folder used as a base for the relative path is not the workspace root, P:\Projects\App, but one level above, P:\Projects. Because of this, it tries to read the schema from P:\Projects\src\schema\app.schema.json which doesn't exist, instead of P:\Projects\App\src\schema\app.schema.json where it's actually located.

 WARN document_open:publish_diagnostics:collect_schema_errors:validate_root:validate:load_schema: failed to fetch schema error=JsValue(Error: ENOENT: no such file or directory, open 'p:\Projects\src\schema\app.schema.json'
Error: ENOENT: no such file or directory, open 'p:\Projects\src\schema\app.schema.json') document_url=file:///p%3A/Projects/App/src/template/template.app.toml schema_url=file:///p%3A/Projects/src/schema/app.schema.json schema_url=file:///p%3A/Projects/src/schema/app.schema.json schema_url=file:///p%3A/Projects/src/schema/app.schema.json
ERROR document_open:publish_diagnostics:collect_schema_errors: schema validation failed error=failed to load schema file:///p%3A/Projects/src/schema/app.schema.json

Caused by:
    JsValue(Error: ENOENT: no such file or directory, open 'p:\Projects\src\schema\app.schema.json'
    Error: ENOENT: no such file or directory, open 'p:\Projects\src\schema\app.schema.json') document_url=file:///p%3A/Projects/App/src/template/template.app.toml

Also experienced the same issue mentioned in https://github.com/tamasfe/taplo/issues/377#issuecomment-1657494623: I have to delete %APPDATA%\Code\User\globalStorage\tamasfe.even-better-toml and reload the VS Code on every schema-related path change. The JSON: Clear Schema Cache command has no effect.

rhenescu commented 1 year ago

Full project, for reproduction: App.zip

Screenshot: image

thejcannon commented 5 months ago

FWIW file://<relative path> seems to work for me

rhenescu commented 5 months ago

@thejcannon thank you for your reply! Can you please share what your settings look like? I gave it a try with:

{
    "evenBetterToml.schema.associations": {
        "^.*\\.app\\.toml$": "file://./src/schema/app.schema.json"
    }
}

And it appears to be relative to the .vscode folder and can't ../ out of it. This requires the schema to be present at <worskpace root>/.vscode/src/schema/app.schema.json. What I tried to achieve was to specify a path that is relative to the workspace folder.

rhenescu commented 5 months ago

Looks like it works without the dot that indicates the current directory: image The hyperlink in .vscode/settings.json is not working, but I guess I can live with that. Unless this is considered a bug, the issue can be closed from.

Many thanks for your suggestion!

levrik commented 1 month ago

Sadly the workaround suggested by @rhenescu does not work for me. Maybe it only works on Windows by accident. Getting an Error: ENOENT: no such file or directory on macOS. Same when prefixed with ./. Without file:// it is relative to one folder above the workspace root. This really needs to be fixed!