-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
base: main
Are you sure you want to change the base?
Conversation
let arr; | ||
while ((arr = regex.exec(lineOfText.text)) !== null) { |
There was a problem hiding this comment.
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.
let arr; | |
while ((arr = regex.exec(lineOfText.text)) !== null) { | |
const matches = lineOfText.text.matchAll(regex); | |
for (const arr of matches) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. I do it
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
fix: support multiple diagnostic in one line