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

fix: support multiple diagnostic in one line #699

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jackluson
Copy link

fix: support multiple diagnostic in one line

@ghost
Copy link

ghost commented Aug 15, 2022

CLA assistant check
All CLA requirements met.

Comment on lines 27 to 28
let arr;
while ((arr = regex.exec(lineOfText.text)) !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you also update minimum VS Code engine from 1.32 to at least 1.40 you can use matchAll, which I think looks cleaner.

Suggested change
let arr;
while ((arr = regex.exec(lineOfText.text)) !== null) {
const matches = lineOfText.text.matchAll(regex);
for (const arr of matches) {

Copy link
Author

Choose a reason for hiding this comment

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

thanks. I do it

Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation looks off for the inner for.

Copy link
Author

Choose a reason for hiding this comment

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

done, it look that because I use spaces for indent

@@ -23,21 +23,27 @@ export function refreshDiagnostics(doc: vscode.TextDocument, emojiDiagnostics: v

for (let lineIndex = 0; lineIndex < doc.lineCount; lineIndex++) {
const lineOfText = doc.lineAt(lineIndex);
if (lineOfText.text.includes(EMOJI)) {
diagnostics.push(createDiagnostic(doc, lineOfText, lineIndex));
const regex = RegExp(EMOJI, 'g');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use new

Also this should escape special regex character in EMOJI in case someone modifies the code: https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex

const regex = RegExp(EMOJI, 'g');
const matches = lineOfText.text.matchAll(regex);
for (const arr of matches) {
arr.index !== undefined && diagnostics.push(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is trying to be too clever. Just use if

Copy link
Contributor

Choose a reason for hiding this comment

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

When would index ever be undefined anyway? I couldn't find any documentation about that being the case for a match.

// create range that represents, where in the document the word is
const range = new vscode.Range(lineIndex, index, lineIndex, index + EMOJI.length);

const range = new vscode.Range(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Splitting into multiple lines is not a worthwhile change IMO

@@ -12,7 +12,7 @@
"url": "https://github.com/Microsoft/vscode-extension-samples/issues"
},
"engines": {
"vscode": "^1.32.0"
"vscode": "^1.40.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also bump the @types/vscode version for this

@mjbvz mjbvz self-assigned this Dec 6, 2022
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

Successfully merging this pull request may close these issues.

3 participants