pedro-w / vscode-tmlanguage

Syntax highlighting for TextMate/SublimeText language definitions
MIT License
18 stars 4 forks source link

The `uuid` package triggers false positive in JSON files #17

Closed dnicolson closed 10 months ago

dnicolson commented 11 months ago

A JSON file containing the following:

{
  "dependencies": {
    "uuid": "^9.0.0"
  }
}

Results in: Screenshot 2023-08-08 at 21 31 55

pedro-w commented 11 months ago

I'll look into it. What version of the extension are you using?

dnicolson commented 11 months ago

Version v0.13.0.

pedro-w commented 11 months ago

I see what you mean. Looks like the extension is being activated on ordinary json files which it shouldn't be.

pedro-w commented 11 months ago

I've stopped the extension activating on all .json, .yaml and .xml files, now it's just .tmLanguage.json, .JSON-tmLanguage, .tmLanguage.yaml, .YAML-tmLanguage, .tmLanguage.yaml and .tmLanguage. I think this is the right thing to do even if it's a bit unsubtle. See bf6d918 If you can test it yourself, great, otherwise I'll publish a new version in the next few days.

pedro-w commented 10 months ago

@dnicolson new version 0.14.0 has been uploaded to the marketplace, if you've got time please can you tell me if it fixes this issue!

dnicolson commented 10 months ago

Version 0.14.0 resolves the issue.

Initially, I wasn't able to reproduce the original issue because the diagnostics are only run after file changes. Is this intentional? If not, adding this to extension.ts will check files before changes are made (onDidOpenTextDocument is not called when a workspace is reopened):

    const document = vscode.workspace.textDocuments[0];
    if (document) {
      diagnosticProvider.CreateDiagnostics(document);
    }
    vscode.workspace.onDidOpenTextDocument(document => {
      diagnosticProvider.CreateDiagnostics(document)
    })
pedro-w commented 10 months ago

I haven't had time to dig into this, but I think it's not working properly in fact - if you have a folder with a .tmlanguage.json file and a 'plain' .json file, the extension will not activate until you open the former but then it will attach diagnostics to both of them. The fix may be just checking the document's languageId before proceeding.