sweetpad-dev / sweetpad

Develop Swift/iOS projects using VSCode
https://marketplace.visualstudio.com/items?itemName=sweetpad.sweetpad
MIT License
619 stars 20 forks source link

Enhancement: Add ProblemMatchers to Support Build Errors and Warnings in Tasks #42

Closed dankinsoid closed 1 month ago

dankinsoid commented 2 months ago

Description

When building iOS projects with the sweetpad extension, the errors and warnings from xcodebuild only appear in the terminal output. This requires developers to manually search through the terminal for issues, which can slow down the development process.

I suggest adding problemMatchers to the tasks provided by sweetpad, which will allow errors and warnings to be parsed and shown in the VSCode "Problems" tab. This would make it easier to identify and navigate to issues in the code.

Proposed Solution

I have tested and created the following problemMatchers to handle both colorized output from xcbeautify and non-colorized output from xcodebuild.

Here is an example of sweetpad build task with working problem matchers:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "SweetPad: Build",
      "type": "sweetpad",
      "action": "build",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "scheme": "Dev",
      "configuration": "Debug",
      "problemMatcher": [
    {
      // Matcher for default problems
      "owner": "xcode",
      "fileLocation": ["relative", "${workspaceFolder}"],
      "pattern": [
        {
          "regexp": "^(.*):(\\d+):(\\d+):\\s+(error|warning):\\s+(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "message": 5
        }
      ]
    },
    {
      // Matcher for xcbeautify errors
      "owner": "xcode",
      "fileLocation": ["absolute"],
      "pattern": {
        "regexp": "^❌\\s*(\\/[^:]+):(\\d+):(\\d+):\\s*(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "message": 4
      },
      "severity": "error"
    },
    {
      // Matcher for xcbeautify warnings
      "owner": "xcode",
      "fileLocation": ["absolute"],
      "pattern": {
        "regexp": "^⚠️\\s*(\\/[^:]+):(\\d+):(\\d+):\\s*(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "message": 4
      },
      "severity": "warning"
    },
    {
      // Matcher for xcbeautify errors with NO_COLOR=1 environment variable
      "owner": "xcode",
      "fileLocation": ["absolute"],
      "pattern": {
        "regexp": "^\\[x\\]\\s*(\\/[^:]+):(\\d+):(\\d+):\\s*(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "message": 4
      },
      "severity": "error"
    },
    {
      // Matcher for xcbeautify warnings with NO_COLOR=1 environment variable
      "owner": "xcode",
      "fileLocation": ["absolute"],
      "pattern": {
        "regexp": "^\\[!\\]\\s*(\\/[^:]+):(\\d+):(\\d+):\\s*(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "message": 4
      },
      "severity": "warning"
    }
  ]
    }
  ]
}
dankinsoid commented 2 months ago

Also Error Lens extension could be added to recommended tools

hyzyla commented 2 months ago

Awesome! I definitely will add problem matchers that you've provided

dankinsoid commented 2 months ago

@hyzyla here is a shortened version:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "SweetPad: Build",
      "type": "sweetpad",
      "action": "build",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "scheme": "Dev",
      "configuration": "Debug",
      "options": {
      "env": {
        "NO_COLOR": "1"
      },
    },
      "problemMatcher": [
    {
      // Matcher for default problems
      "owner": "xcode",
      "fileLocation": ["relative", "${workspaceFolder}"],
      "pattern": [
        {
          "regexp": "^(.*):(\\d+):(\\d+):\\s+(error|warning):\\s+(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "message": 5
        }
      ]
    },
    {
      // Matcher for xcbeautify errors for any NO_COLOR environment variable
      "owner": "xcode",
       "fileLocation": "absolute",
      "pattern": {
        "regexp": "^(?:❌|\\[x\\])\\s*(\\/[^:]+):(\\d+):(\\d+):\\s*(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "message": 4
      },
      "severity": "error"
    },
    {
      // Matcher for xcbeautify warnings for any NO_COLOR environment variable
      "owner": "xcode",
      "fileLocation": "absolute",
      "pattern": {
        "regexp": "^(?:⚠️|\\[!\\])\\s*(\\/[^:]+):(\\d+):(\\d+):\\s*(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "message": 4
      },
      "severity": "warning"
    }
  ]
    }
  ]
}
hyzyla commented 2 months ago

@dankinsoid for contributing! The next 0.1.35 version of the extesnion will include such problem matchers:

export const DEFAULT_BUILD_PROBLEM_MATCHERS = [
  "$sweetpad-watch",
  "$sweetpad-xcodebuild-default",
  "$sweetpad-xcbeautify-errors",
  "$sweetpad-xcbeautify-warnings",
];