-
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,21 +23,25 @@ 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'); | ||||||||||
let arr; | ||||||||||
while ((arr = regex.exec(lineOfText.text)) !== null) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Indentation looks off for the inner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, it look that because I use spaces for indent |
||||||||||
diagnostics.push(createDiagnostic(doc, lineOfText, lineIndex, arr.index)); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
emojiDiagnostics.set(doc.uri, diagnostics); | ||||||||||
} | ||||||||||
|
||||||||||
function createDiagnostic(doc: vscode.TextDocument, lineOfText: vscode.TextLine, lineIndex: number): vscode.Diagnostic { | ||||||||||
function createDiagnostic(doc: vscode.TextDocument, lineOfText: vscode.TextLine, lineIndex: number, startTextIndex: number): vscode.Diagnostic { | ||||||||||
// find where in the line of that the 'emoji' is mentioned | ||||||||||
const index = lineOfText.text.indexOf(EMOJI); | ||||||||||
|
||||||||||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Splitting into multiple lines is not a worthwhile change IMO |
||||||||||
lineIndex, | ||||||||||
startTextIndex, | ||||||||||
lineIndex, | ||||||||||
startTextIndex + EMOJI.length | ||||||||||
); | ||||||||||
const diagnostic = new vscode.Diagnostic(range, "When you say 'emoji', do you want to find out more?", | ||||||||||
vscode.DiagnosticSeverity.Information); | ||||||||||
diagnostic.code = EMOJI_MENTION; | ||||||||||
|
@@ -64,4 +68,4 @@ export function subscribeToDocumentChanges(context: vscode.ExtensionContext, emo | |||||||||
vscode.workspace.onDidCloseTextDocument(doc => emojiDiagnostics.delete(doc.uri)) | ||||||||||
); | ||||||||||
|
||||||||||
} | ||||||||||
} |
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