Skip to content
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

Add problemMatcher for svelte-check #1036

Open
ebeloded opened this issue May 28, 2021 · 4 comments
Open

Add problemMatcher for svelte-check #1036

ebeloded opened this issue May 28, 2021 · 4 comments
Labels
feature request New feature or request

Comments

@ebeloded
Copy link

ebeloded commented May 28, 2021

Is your feature request related to a problem? Please describe.
svelte-check reports errors and hints in a different format than tsc does. Here is a simple example.

  • tsc --watch output:
    image

  • svelte-check --watch output:
    image

This is problematic because it is impossible to integrate svelte-check with VSCode tasks and a built-in $tsc-watch problem matcher.

To clarify: VSCode allows to define tasks for building, testing, checking, linting, etc. For example, to run tsc on my project I can define a task like this:

{
  "label": "tsc --watch",
  "isBackground": true,
  "type": "shell",
  "problemMatcher": "$tsc-watch",
  "command": "tsc --watch"
}

VSCode comes with a number of built-in problem matchers. Problem matchers scan the output and report problems in Problems panel. This allows to quickly see the problem in a well-formatted view, and to jump between problems using commands or keyboard navigation.

Here is what the example I provided looks like:

image

Note that If I open the problematic svelte file, then the problems do appear in the Problems panel. However, at that point, it's no longer useful, because I can see the problem in the open file myself.
image

Describe the solution you'd like
I'd like for svelte-check results to be accessible through $tsc-watch and $tsc problem matchers without any additional configuration. This will allow to run svelte-check in the background and catch errors, even if a file that has issue is not opened in the editor.
This would require changing the reporting format to match the one of TypeScript compiler.

Describe alternatives you've considered
An alternative is to define a custom problem matcher to parse svelte-check output. This custom problem matcher would need to be added to the VSCode extension.

@dummdidumm dummdidumm added the feature request New feature or request label May 29, 2021
@dummdidumm
Copy link
Member

Writing a custom matcher is probably the better alternative. During that I'd also like to revisit the way we print the file location. I'm thinking about using Babel's npm package for that.

@dummdidumm dummdidumm changed the title Allow svelte-check reporting in TSC format Add problemMatcher for svelte-check Jun 1, 2021
@dummdidumm
Copy link
Member

I tried tackling this but I'm stuck on two things:

  1. I can't get VS Code to delete the diagnostics from the output once the file is opened (at this point the VS Code extension should take over). I guess this has to do with the owner property but I don't know what to set it to, or if we need to enhance the extension somehow.
  2. When running in watch mode, resolved errors are not deleted from the output

Matcher for a single run:

{
        "owner": "svelte",
        "applyTo": "closedDocuments",
        "fileLocation": ["absolute"],
        "pattern": [
          {
            "regexp": "^(.*?):(\\d+):(\\d+)$",
            "file": 1,
            "line": 2,
            "column": 3
          },
          {
            "regexp": "^(Error|Warn|Hint):(.*?)$",
            "severity": 1,
            "message": 2
          }
        ]
}

Matcher for multiple runs (needs at least svelte-check 2.1.0)

{
        "owner": "svelte",
        "applyTo": "closedDocuments",
        "fileLocation": ["absolute"],
        "pattern": [
          {
            "regexp": "^(.*?):(\\d+):(\\d+)$",
            "file": 1,
            "line": 2,
            "column": 3
          },
          {
            "regexp": "^(Error|Warn|Hint):(.*?)$",
            "severity": 1,
            "message": 2
          }
        ],
        "background": {
          "activeOnStart": false,
          "beginsPattern": {
            "regexp": "Getting Svelte diagnostics"
          },
          "endsPattern": {
            "regexp": "Watching for file changes"
          }
        }
}

@jasonlyu123
Copy link
Member

It seems like using "Watching for file changes" as endsPattern sometimes doesn't work. Probably because the cursor is on the same line. That may be the reason why the resolved error is not deleted. Using svelte-check found as endsPattern seems to work better.

@denlukia
Copy link

denlukia commented Apr 13, 2024

I just wanted to thank @dummdidumm for a solution and @jasonlyu123 for an improvement.

For me the difference of reading 204 errors (big refactoring, VS Code doesn't update imports very well) from a CLI and from "Problems" (with all it's formatting and filtering) is a difference between "I'll never deal with this pile" and "Hmm, I think this is manageable"

God bless non-console interfaces 🥲

image

vs

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants