private void SubscribeToTextControlChanges()

in src/dotnet/ReSharperPlugin.DotNetDisassembler/AsmViewerHost.cs [122:159]


    private void SubscribeToTextControlChanges(Lifetime lifetime, ITextControlManager textControlManager, GroupingEvent compilationTrigger)
    {
        var caretSubscriptions = new SequentialLifetimes(lifetime);

        textControlManager.LastFocusedTextControlPerClient.ForEachValue_Host(lifetime, (_, textControl) =>
        {
            if (textControl == null)
            {
                _logger.Verbose("No focused text control");
                _currentTextControl = null;
                caretSubscriptions.TerminateCurrent();
                _model.SendResult(new CompilationResult(null, new ErrorInfo(ErrorCode.SourceFileNotFound, null)));
                return;
            }

            // IL Viewer, ASM Viewer and similar tools open read-only editors with synchronized carets.
            // We skip these and keep tracking the source editor - caret sync ensures our subscription still works.
            var projectFile = _documentManager.TryGetProjectFile(textControl.Document);
            if (projectFile == null || _fileLocationsBlacklist.Contains(projectFile.Location))
            {
                _logger.Verbose("Ignoring text control (virtual document or blacklisted): {0}", textControl.Document.Moniker);
                return;
            }

            if (textControl == _currentTextControl)
            {
                _logger.Verbose("Same source text control, skipping resubscription");
                return;
            }

            _currentTextControl = textControl;

            _logger.Verbose("Text control focused: {0}", textControl.Document.Moniker);
            compilationTrigger.FireIncoming();

            SubscribeToCaretChanges(caretSubscriptions, textControl, compilationTrigger);
        });
    }