Skip to content

fix named multiline problem pattern parsing #65840

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

Merged
merged 2 commits into from
Jan 8, 2019

Conversation

vemoo
Copy link
Contributor

@vemoo vemoo commented Dec 30, 2018

Before an error was being generated for valid named multiline problem patterns like this:

"problemPatterns": [
    {
        "name": "rustc",
        "patterns": [
            {
                "regexp": "^(warning|warn|error)(?:\\[(.*?)\\])?: (.*)$",
                "severity": 1,
                "code": 2,
                "message": 3
            },
            {
                "regexp": "^[\\s->=]*(.*?):(\\d*):(\\d*)\\s*$",
                "file": 1,
                "line": 2,
                "column": 3
            }
        ]
    }
],

And when an error was generated the pattern was ignored.

This PR fixes that.

@octref octref requested a review from alexr00 December 30, 2018 21:54
bors bot added a commit to rust-lang/rust-analyzer that referenced this pull request Jan 2, 2019
408: vscode problem matcher improvements r=matklad a=vemoo

The problem matcher wasn't working properly and looking at the rustc errors i realized it could be simplified.

I also added a new problem matcher that can be used with https://github.com/passcod/cargo-watch to get the errors in the editor on save. To use it one can create a tasks.json file with:
```json
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "cargo watch",
            "command": "cargo",
            "isBackground": true,
            "args": [
                "watch",
                "-c"
            ],
            "problemMatcher": [
                "$rustc-watch"
            ]
        }
    ]
}
```
I initially implemented it like this: cff9f62 but i think there's a bug in vscode so i worked around it by copying the pattern for both problem matchers. The first commit can be used if microsoft/vscode#65840 is merged.


Co-authored-by: Bernardo <berublan@gmail.com>
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the original if check around the error doesn't take into account named multiline problem matchers. Instead of moving the error into this else, the original if should be modified to also check for named and named multiline checked problem matchers.

@vemoo
Copy link
Contributor Author

vemoo commented Jan 3, 2019

I was going to do that initialy but I think that's part of the reason this bug happened, that the validation is being made twice.
Also I found the if check was hard to read so I tried to simplify it.

My reasoning is the following:

  • If the else branch is reached it doesn't make sense that no error is generated.
  • It doesn't make sense to return a value if an error is generated.
  • Another thing is that Config.NamedMultiLineProblemPattern doesn't exist, only Config.NamedMultiLineCheckedProblemPattern, so we cannot make the same check as for Config.MultiLineProblemPattern.

Another more explicit way to write it while avoiding duplicate checks and being less error prone would be this:

const missingRegExpError = () => {
	this.error(localize('ProblemPatternParser.problemPattern.missingRegExp', 'The problem pattern is missing a regular expression.'));
};
if (Config.NamedMultiLineCheckedProblemPattern.is(value)) {
	return this.createNamedMultiLineProblemPattern(value);
} else if (Config.MultiLineProblemPattern.is(value)) {
	if (Config.MultiLineCheckedProblemPattern.is(value)) {
		return this.createMultiLineProblemPattern(value);
	} else {
		missingRegExpError();
		return null;
	}
} else if (Config.NamedProblemPattern.is(value)) {
	if (Config.NamedCheckedProblemPattern.is(value)) {
		let result = this.createSingleProblemPattern(value) as NamedProblemPattern;
		result.name = value.name;
		return result;
	} else {
		missingRegExpError();
		return null;
	}
} else if (Config.CheckedProblemPattern.is(value)) {
	return this.createSingleProblemPattern(value);
} else {
	missingRegExpError();
	return null;
}

Would that be better?

@alexr00
Copy link
Member

alexr00 commented Jan 4, 2019

I see your point about validation being done twice. To keep things concise, how about

    if (Config.NamedMultiLineCheckedProblemPattern.is(value)) {
        return this.createNamedMultiLineProblemPattern(value);
    } else if (Config.MultiLineProblemPattern.is(value) && Config.MultiLineCheckedProblemPattern.is(value)) {
        return this.createMultiLineProblemPattern(value);
    } else if (Config.NamedProblemPattern.is(value) && Config.NamedCheckedProblemPattern.is(value)) {
	let result = this.createSingleProblemPattern(value) as NamedProblemPattern;
	result.name = value.name;
	return result;
    } else if (Config.CheckedProblemPattern.is(value)) {
	return this.createSingleProblemPattern(value);
    } else {
	// this.error line
	return null;
    }

@vemoo
Copy link
Contributor Author

vemoo commented Jan 4, 2019

I like that, the only things is tha both Config.MultiLineCheckedProblemPattern.is and Config.NamedCheckedProblemPattern.is already check Config.MultiLineProblemPattern.is and Config.NamedProblemPattern.is respectively, so those could be removed.

https://github.com/Microsoft/vscode/blob/ac140c084c6de6a947f116b2ed24a7634a625306/src/vs/workbench/parts/tasks/common/problemMatcher.ts#L618-L639

MultiLineCheckedProblemPattern.is includes the same check that MultiLineProblemPattern.is is doing.
Maybe it should call MultiLineProblemPattern.is?

https://github.com/Microsoft/vscode/blob/ac140c084c6de6a947f116b2ed24a7634a625306/src/vs/workbench/parts/tasks/common/problemMatcher.ts#L594-L614

NamedCheckedProblemPattern.is is already calling NamedProblemPattern.is.

That's why i didn't include the non Checked is calls.

@alexr00
Copy link
Member

alexr00 commented Jan 8, 2019

Thanks for the contribution and for being so thorough!

@alexr00 alexr00 merged commit e531895 into microsoft:master Jan 8, 2019
@alexr00 alexr00 added this to the December/January 2019 milestone Jan 8, 2019
kjeremy added a commit to kjeremy/rust-analyzer that referenced this pull request Feb 18, 2019
Now that microsoft/vscode#65840 is in the latest
release we can use the first commit from rust-lang#408
bors bot added a commit to rust-lang/rust-analyzer that referenced this pull request Feb 19, 2019
858: Use named multiline Problem Matcher r=matklad a=kjeremy

Now that microsoft/vscode#65840 is in the latest release we can use the first commit from #408

Co-authored-by: kjeremy <kjeremy@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants