/** To demonstrate code actions associated with Diagnostics problems, this file provides a mock diagnostics entries. */ import * as vscode from 'vscode' ; /** Code that is used to associate diagnostic entries with code actions. */ export const EMOJI_MENTION = 'emoji_mention' ; /** String to detect in the text document. */ const EMOJI = 'emoji' ; param doc param emojiDiagnostics export function refreshDiagnostics ( doc , emojiDiagnostics ) { const diagnostics = [ ] ; for ( let lineIndex = 0 ; lineIndex < doc . lineCount ; lineIndex ++ ) { const lineOfText = doc . lineAt ( lineIndex ) ; if ( lineOfText . text . includes ( EMOJI ) ) { diagnostics . push ( createDiagnostic ( doc , lineOfText , lineIndex ) ) ; } } emojiDiagnostics . set ( doc . uri , diagnostics ) ; } function createDiagnostic ( doc , lineOfText , lineIndex ) { const index = lineOfText . text . indexOf ( EMOJI ) ; const range = new vscode . Range ( lineIndex , index , lineIndex , index + 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 ; return diagnostic ; } export function subscribeToDocumentChanges ( context , emojiDiagnostics ) { if ( vscode . window . activeTextEditor ) { refreshDiagnostics ( vscode . window . activeTextEditor . document , emojiDiagnostics ) ; } context . subscriptions . push ( vscode . window . onDidChangeActiveTextEditor ( editor => { if ( editor ) { refreshDiagnostics ( editor . document , emojiDiagnostics ) ; } } ) ) ; context . subscriptions . push ( vscode . workspace . onDidChangeTextDocument ( e => refreshDiagnostics ( e . document , emojiDiagnostics ) ) ) ; context . subscriptions . push ( vscode . workspace . onDidCloseTextDocument ( doc => emojiDiagnostics . delete ( doc . uri ) ) ) ; }