VS Code Problem Matcher


#1

Hey,

I’ve been using PureScript for a while along with VS Code.

While porting my app from 0.11 to 0.12 I’ve been going through a lot of compiler errors with easy fixes. To get through this quickly I created a simple problem matcher for jumping to errors.

I haven’t found any other problem matchers around so I thought I would share this here. It’s certainly a WIP and feedback is more than welcome.

{
    "problemMatcher": {
        "fileLocation": [ "relative", "${workspaceFolder}" ],
        "owner": "purescript",
        "pattern": [
            {
                "regexp": "at (.*\\.purs) line (\\d+), column (\\d+) - line (\\d+), column (\\d+).*",
                "file": 1,
                "line": 2,
                "column": 3,
                "endLine": 4,
                "endColumn": 5
            },
            {
                "regexp": "^$"
            },
            {
                "regexp": "^(.*)$",
                "message": 1
            }
        ]
    }
}

#2

I use VSCode, but I’ve never heard of problem matchers. How does this differ from the PureScript IDE plugin?


#3

Well, I don’t think the plugin actually handles parsing the error messages. This could be something we might incorporate into that plugin.

Right now, however, in all of my projects I have a file <project>/.vscode/tasks.json where I keep this.

Here’s what my tasks.json file looks like for my purescript code:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "problemMatcher": {
    "owner": "purescript",
    "fileLocation": ["relative", "${workspaceFolder}"],
    "pattern": [
      {
        "regexp":
          "at (.*\\.purs) line (\\d+), column (\\d+) - line (\\d+), column (\\d+).*",
        "file": 1,
        "line": 2,
        "column": 3,
        "endLine": 4,
        "endColumn": 5
      },
      {
        "regexp": "^$"
      },
      {
        "regexp": "^(.*)$",
        "message": 1
      }
    ]
  },
  "tasks": [
    {
      "label": "configure",
      "type": "shell",
      "command": "npm",
      "args": ["install"]
    },
    {
      "label": "run",
      "type": "shell",
      "command": "npm",
      "args": ["start"]
    },
    {
      "label": "build",
      "type": "shell",
      "command": "npm",
      "args": ["run-script", "build"],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    },
    {
      "label": "test",
      "type": "shell",
      "command": "npm",
      "args": ["test"],
      "group": {
        "kind": "test",
        "isDefault": true
      }
    }
  ]
}

I have a similar tasks.json file for Haskell, since I had to write a custom problem matcher for Haskell too.


#4

There is an open issue to add a problem matcher to vscode plugin https://github.com/nwolverson/vscode-ide-purescript/issues/17

However I’m not sure the use case for this, as with the PureScript compiler’s json output, which is parsed by the vscode plugin either from purs compile output or the purs ide server, there’s no need for a problem matcher, these will appear in “problems” already. You also get quick fixes from compiler suggestions, e.g. fixing import lists.