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

Message displays incorrectly when template does not have a whitespace between empty elements #216

Open
raven42 opened this issue Aug 14, 2024 · 0 comments

Comments

@raven42
Copy link

raven42 commented Aug 14, 2024

If an element in the message template does not exist for a given diagnostic, and if there is no space between that element and another part of the string, the result.replace() logic here is removing other parts of the message.

result = result.replace(/(\s*?)?(\S*?)?(\$code)(\S*?)?(\s*?)?/u, (match, g1: string | undefined, g2, g3, g4, g5: string | undefined) => (g1 ?? '') + (g5 ?? ''));

For example, if the message template is defined like this, then it shows correctly when the diagnostic has a valid $code, but if the $code is not valid, then the $source and other characters (parenthesis with this template) are also removed leaving only the $message piece (in this example, the Pylance $source indicator is not seen.

{
  "errorLens.alignMessage": {
    "start": 45,
    "end": 0,
    "minimumMargin": 5
  },
  "errorLens.messageTemplate": "$source($code): $message",
}

image

However if spaces are added instead of the parenthesis, then the message does show the $source.

{
  "errorLens.alignMessage": {
    "start": 45,
    "end": 0,
    "minimumMargin": 5
  },
  "errorLens.messageTemplate": "$source $code : $message",
}

image

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

No branches or pull requests

1 participant