public SmartTokenFormatterCommandHandler(
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService) :
     base(undoHistoryRegistry,
          editorOperationsFactoryService)
 {
 }
 public RenameTrackingCodeAction(Document document, string title, IEnumerable<IRefactorNotifyService> refactorNotifyServices, ITextUndoHistoryRegistry undoHistoryRegistry)
 {
     _document = document;
     _title = title;
     _refactorNotifyServices = refactorNotifyServices;
     _undoHistoryRegistry = undoHistoryRegistry;
 }
 public AutomaticLineEnderCommandHandler(
     IWaitIndicator waitIndicator,
     ITextUndoHistoryRegistry undoRegistry,
     IEditorOperationsFactoryService editorOperations)
     : base(waitIndicator, undoRegistry, editorOperations)
 {
 }
Example #4
0
        /// <summary>
        /// Creates a document provider.
        /// </summary>
        /// <param name="projectContainer">Project container for the documents.</param>
        /// <param name="serviceProvider">Service provider</param>
        /// <param name="documentTrackingService">An optional <see cref="VisualStudioDocumentTrackingService"/> to track active and visible documents.</param>
        public DocumentProvider(
            IVisualStudioHostProjectContainer projectContainer,
            IServiceProvider serviceProvider,
            VisualStudioDocumentTrackingService documentTrackingService)
        {
            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            _projectContainer = projectContainer;
            this._documentTrackingServiceOpt = documentTrackingService;
            this._runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            this._editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
            this._contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();
            _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>();
            _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));

            var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
            if (shell == null)
            {
                // This can happen only in tests, bail out.
                return;
            }

            var runningDocumentTableForEvents = (IVsRunningDocumentTable)_runningDocumentTable;
            Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie));
        }
Example #5
0
        public DocumentProvider(
            IVisualStudioHostProjectContainer projectContainer,
            IServiceProvider serviceProvider,
            bool signUpForFileChangeNotification)
        {
            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            _projectContainer = projectContainer;
            this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            this.EditorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
            this.ContentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();
            _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>();
            _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            // In the CodeSense scenario we will receive file change notifications from the native
            // Language Services, so we don't want to sign up for them ourselves.
            if (signUpForFileChangeNotification)
            {
                _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));
            }

            var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
            if (shell == null)
            {
                // This can happen only in tests, bail out.
                return;
            }

            int installed;
            Marshal.ThrowExceptionForHR(shell.IsPackageInstalled(Guids.RoslynPackageId, out installed));
            IsRoslynPackageInstalled = installed != 0;

            var runningDocumentTableForEvents = (IVsRunningDocumentTable)RunningDocumentTable;
            Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie));
        }
 public GlobalUndoServiceFactory(
     ITextUndoHistoryRegistry undoHistoryRegistry,
     SVsServiceProvider serviceProvider,
     Lazy<VisualStudioWorkspace> workspace)
 {
     _singleton = new GlobalUndoService(undoHistoryRegistry, serviceProvider, workspace);
 }
 public CSharpRenameTrackingCodeFixProvider(
     IWaitIndicator waitIndicator,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     [ImportMany] IEnumerable<IRefactorNotifyService> refactorNotifyServices)
     : base(waitIndicator, undoHistoryRegistry, refactorNotifyServices)
 {
 }
Example #8
0
 /// <summary>
 /// create caret preserving edit transaction with automatic code change undo merging policy
 /// </summary>
 public static CaretPreservingEditTransaction CreateEditTransaction(
     this ITextView view, string description, ITextUndoHistoryRegistry registry, IEditorOperationsFactoryService service)
 {
     return new CaretPreservingEditTransaction(description, view, registry, service)
     {
         MergePolicy = AutomaticCodeChangeMergePolicy.Instance
     };
 }
Example #9
0
        public RenameTrackingTestState(
            TestWorkspace workspace,
            string languageName,
            bool onBeforeGlobalSymbolRenamedReturnValue = true,
            bool onAfterGlobalSymbolRenamedReturnValue  = true
            )
        {
            this.Workspace = workspace;

            _hostDocument = Workspace.Documents.First();
            _view         = _hostDocument.GetTextView();
            _view.Caret.MoveTo(
                new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value)
                );
            _editorOperations = Workspace
                                .GetService <IEditorOperationsFactoryService>()
                                .GetEditorOperations(_view);
            _historyRegistry           = Workspace.ExportProvider.GetExport <ITextUndoHistoryRegistry>().Value;
            _mockRefactorNotifyService = new MockRefactorNotifyService
            {
                OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue,
                OnAfterSymbolRenamedReturnValue  = onAfterGlobalSymbolRenamedReturnValue
            };

            // Mock the action taken by the workspace INotificationService
            var notificationService =
                (INotificationServiceCallback)Workspace.Services.GetRequiredService <INotificationService>();
            var callback = new Action <string, string, NotificationSeverity>(
                (message, title, severity) => _notificationMessage = message
                );

            notificationService.NotificationCallback = callback;

            var tracker = new RenameTrackingTaggerProvider(
                Workspace.ExportProvider.GetExportedValue <IThreadingContext>(),
                Workspace.ExportProvider.GetExport <IInlineRenameService>().Value,
                Workspace.ExportProvider.GetExport <IDiagnosticAnalyzerService>().Value,
                Workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>()
                );

            _tagger = tracker.CreateTagger <RenameTrackingTag>(_hostDocument.GetTextBuffer());

            if (languageName == LanguageNames.CSharp || languageName == LanguageNames.VisualBasic)
            {
                _codeRefactoringProvider = new RenameTrackingCodeRefactoringProvider(
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)
                    );
            }
            else
            {
                throw new ArgumentException(
                          "Invalid language name: " + languageName,
                          nameof(languageName)
                          );
            }
        }
 protected AbstractRenameTrackingCodeFixProvider(
     IWaitIndicator waitIndicator,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEnumerable <IRefactorNotifyService> refactorNotifyServices)
 {
     _waitIndicator          = waitIndicator;
     _undoHistoryRegistry    = undoHistoryRegistry;
     _refactorNotifyServices = refactorNotifyServices;
 }
            public StandardTextDocument(
                DocumentProvider documentProvider,
                IVisualStudioHostProject project,
                DocumentKey documentKey,
                IReadOnlyList<string> folderNames,
                SourceCodeKind sourceCodeKind,
                ITextUndoHistoryRegistry textUndoHistoryRegistry,
                IVsFileChangeEx fileChangeService,
                ITextBuffer openTextBuffer,
                DocumentId id,
                EventHandler updatedOnDiskHandler,
                EventHandler<bool> openedHandler,
                EventHandler<bool> closingHandler)
            {
                Contract.ThrowIfNull(documentProvider);

                this.Project = project;
                this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker);
                this.Folders = folderNames;

                _documentProvider = documentProvider;

                this.Key = documentKey;
                this.SourceCodeKind = sourceCodeKind;
                _itemMoniker = documentKey.Moniker;
                _textUndoHistoryRegistry = textUndoHistoryRegistry;
                _fileChangeTracker = new FileChangeTracker(fileChangeService, this.FilePath);
                _fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk;

                _openTextBuffer = openTextBuffer;
                _snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer);

                // The project system does not tell us the CodePage specified in the proj file, so
                // we use null to auto-detect.
                _doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null);

                // If we aren't already open in the editor, then we should create a file change notification
                if (openTextBuffer == null)
                {
                    _fileChangeTracker.StartFileChangeListeningAsync();
                }

                if (updatedOnDiskHandler != null)
                {
                    UpdatedOnDisk += updatedOnDiskHandler;
                }

                if (openedHandler != null)
                {
                    Opened += openedHandler;
                }

                if (closingHandler != null)
                {
                    Closing += closingHandler;
                }
            }
Example #12
0
 public SplitStringLiteralCommandHandler(
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService,
     EditorOptionsService editorOptionsService)
 {
     _undoHistoryRegistry            = undoHistoryRegistry;
     _editorOperationsFactoryService = editorOperationsFactoryService;
     _editorOptionsService           = editorOptionsService;
 }
Example #13
0
 protected AbstractAutomaticLineEnderCommandHandler(
     ITextUndoHistoryRegistry undoRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService,
     EditorOptionsService editorOptionsService)
 {
     _undoRegistry = undoRegistry;
     _editorOperationsFactoryService = editorOperationsFactoryService;
     EditorOptionsService            = editorOptionsService;
 }
 protected AbstractAutomaticLineEnderCommandHandler(
     ITextUndoHistoryRegistry undoRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService,
     IGlobalOptionService globalOptions)
 {
     _undoRegistry = undoRegistry;
     _editorOperationsFactoryService = editorOperationsFactoryService;
     GlobalOptions = globalOptions;
 }
Example #15
0
        /// <summary>
        /// create caret preserving edit transaction with automatic code change undo merging policy
        /// </summary>
        public static CaretPreservingEditTransaction CreateEditTransaction(
            this ITextView view, string description, ITextUndoHistoryRegistry registry, IEditorOperationsFactoryService service)
        {
            var transaction = new CaretPreservingEditTransaction(description, view, registry, service);

            transaction.MergePolicy = AutomaticCodeChangeMergePolicy.Instance;

            return(transaction);
        }
Example #16
0
 public InteractivePasteCommandHandler(
     IEditorOperationsFactoryService editorOperationsFactoryService,
     ITextUndoHistoryRegistry textUndoHistoryRegistry
     )
 {
     _editorOperationsFactoryService = editorOperationsFactoryService;
     _textUndoHistoryRegistry        = textUndoHistoryRegistry;
     RoslynClipboard = new SystemClipboardWrapper();
 }
Example #17
0
 public TextBufferUndoManager(ITextBuffer textBuffer, ITextUndoHistoryRegistry textUndoHistoryRegistry)
 {
     changes    = new List <ChangeInfo>();
     TextBuffer = textBuffer ?? throw new ArgumentNullException(nameof(textBuffer));
     this.textUndoHistoryRegistry = textUndoHistoryRegistry ?? throw new ArgumentNullException(nameof(textUndoHistoryRegistry));
     textBufferUndoHistory        = textUndoHistoryRegistry.RegisterHistory(TextBuffer);
     TextBuffer.Changed          += TextBuffer_Changed;
     TextBuffer.PostChanged      += TextBuffer_PostChanged;
 }
 protected AbstractRenameTrackingCodeFixProvider(
     IWaitIndicator waitIndicator,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEnumerable<IRefactorNotifyService> refactorNotifyServices)
 {
     _waitIndicator = waitIndicator;
     _undoHistoryRegistry = undoHistoryRegistry;
     _refactorNotifyServices = refactorNotifyServices;
 }
		public CommandHandlerDispatcher(IVsTextView textViewAdapter, ITextView textView, ITextUndoHistoryRegistry textUndoHistoryRegistry, params ICommandHandler[] commandHandlers)
		{
			_textViewAdapter = textViewAdapter;
			_textView = textView;
			_textUndoHistoryRegistry = textUndoHistoryRegistry;
			_commandHandlers = commandHandlers.ToDictionary(h => h.CommandId);

			_textViewAdapter.AddCommandFilter(this, out _nextTarget);
		}
Example #20
0
 public FormatCommandHandler(
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService,
     IGlobalOptionService globalOptions)
 {
     _undoHistoryRegistry            = undoHistoryRegistry;
     _editorOperationsFactoryService = editorOperationsFactoryService;
     _globalOptions = globalOptions;
 }
Example #21
0
 public CompleteStatementCommandHandler(
     ITextUndoHistoryRegistry textUndoHistoryRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService,
     IGlobalOptionService globalOptions)
 {
     _textUndoHistoryRegistry        = textUndoHistoryRegistry;
     _editorOperationsFactoryService = editorOperationsFactoryService;
     _globalOptions = globalOptions;
 }
Example #22
0
        public CommandHandlerDispatcher(IVsTextView textViewAdapter, ITextView textView, ITextUndoHistoryRegistry textUndoHistoryRegistry, params ICommandHandler[] commandHandlers)
        {
            _textViewAdapter         = textViewAdapter;
            _textView                = textView;
            _textUndoHistoryRegistry = textUndoHistoryRegistry;
            _commandHandlers         = commandHandlers.ToDictionary(h => h.CommandId);

            _textViewAdapter.AddCommandFilter(this, out _nextTarget);
        }
Example #23
0
 public AbstractAutomaticLineEnderCommandHandler(
     IWaitIndicator waitIndicator,
     ITextUndoHistoryRegistry undoRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService)
 {
     _waitIndicator = waitIndicator;
     _undoRegistry  = undoRegistry;
     _editorOperationsFactoryService = editorOperationsFactoryService;
 }
 public AbstractAutomaticLineEnderCommandHandler(
     ITextUndoHistoryRegistry undoRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService,
     IAsyncCompletionBroker asyncCompletionBroker)
 {
     _undoRegistry = undoRegistry;
     _editorOperationsFactoryService = editorOperationsFactoryService;
     _asyncCompletionBroker          = asyncCompletionBroker;
 }
 public FormatCommandHandler(
     IWaitIndicator waitIndicator,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService)
 {
     _waitIndicator                  = waitIndicator;
     _undoHistoryRegistry            = undoHistoryRegistry;
     _editorOperationsFactoryService = editorOperationsFactoryService;
 }
 public RawStringLiteralCommandHandler(
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IGlobalOptionService globalOptions,
     IEditorOperationsFactoryService editorOperationsFactoryService)
 {
     _undoHistoryRegistry            = undoHistoryRegistry;
     _globalOptions                  = globalOptions;
     _editorOperationsFactoryService = editorOperationsFactoryService;
 }
Example #27
0
            public StandardTextDocument(
                DocumentProvider documentProvider,
                IVisualStudioHostProject project,
                DocumentKey documentKey,
                IReadOnlyList <string> folderNames,
                SourceCodeKind sourceCodeKind,
                ITextUndoHistoryRegistry textUndoHistoryRegistry,
                IVsFileChangeEx fileChangeService,
                ITextBuffer openTextBuffer,
                DocumentId id,
                EventHandler updatedOnDiskHandler,
                EventHandler <bool> openedHandler,
                EventHandler <bool> closingHandler)
            {
                Contract.ThrowIfNull(documentProvider);

                this.Project = project;
                this.Id      = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker);
                this.Folders = folderNames;

                _documentProvider = documentProvider;

                this.Key                          = documentKey;
                this.SourceCodeKind               = sourceCodeKind;
                _itemMoniker                      = documentKey.Moniker;
                _textUndoHistoryRegistry          = textUndoHistoryRegistry;
                _fileChangeTracker                = new FileChangeTracker(fileChangeService, this.FilePath);
                _fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk;

                _openTextBuffer  = openTextBuffer;
                _snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer);

                // The project system does not tell us the CodePage specified in the proj file, so
                // we use null to auto-detect.
                _doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null);

                // If we aren't already open in the editor, then we should create a file change notification
                if (openTextBuffer == null)
                {
                    _fileChangeTracker.StartFileChangeListeningAsync();
                }

                if (updatedOnDiskHandler != null)
                {
                    UpdatedOnDisk += updatedOnDiskHandler;
                }

                if (openedHandler != null)
                {
                    Opened += openedHandler;
                }

                if (closingHandler != null)
                {
                    Closing += closingHandler;
                }
            }
Example #28
0
        public RenameTrackingTestState(
            string markup,
            string languageName,
            bool onBeforeGlobalSymbolRenamedReturnValue = true,
            bool onAfterGlobalSymbolRenamedReturnValue  = true)
        {
            this.Workspace = CreateTestWorkspace(markup, languageName, TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic());

            _hostDocument = Workspace.Documents.First();
            _view         = _hostDocument.GetTextView();
            _view.Caret.MoveTo(new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value));
            _editorOperations          = Workspace.GetService <IEditorOperationsFactoryService>().GetEditorOperations(_view);
            _historyRegistry           = Workspace.ExportProvider.GetExport <ITextUndoHistoryRegistry>().Value;
            _mockRefactorNotifyService = new MockRefactorNotifyService
            {
                OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue,
                OnAfterSymbolRenamedReturnValue  = onAfterGlobalSymbolRenamedReturnValue
            };

            var optionService = this.Workspace.Services.GetService <IOptionService>();

            // Mock the action taken by the workspace INotificationService
            var notificationService = Workspace.Services.GetService <INotificationService>() as INotificationServiceCallback;
            var callback            = new Action <string, string, NotificationSeverity>((message, title, severity) => _notificationMessage = message);

            notificationService.NotificationCallback = callback;

            var tracker = new RenameTrackingTaggerProvider(
                _historyRegistry,
                Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value,
                Workspace.ExportProvider.GetExport <IInlineRenameService>().Value,
                Workspace.ExportProvider.GetExport <IDiagnosticAnalyzerService>().Value,
                SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService),
                Workspace.ExportProvider.GetExports <IAsynchronousOperationListener, FeatureMetadata>());

            _tagger = tracker.CreateTagger <RenameTrackingTag>(_hostDocument.GetTextBuffer());

            if (languageName == LanguageNames.CSharp)
            {
                _codeFixProvider = new CSharpRenameTrackingCodeFixProvider(
                    Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value,
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService));
            }
            else if (languageName == LanguageNames.VisualBasic)
            {
                _codeFixProvider = new VisualBasicRenameTrackingCodeFixProvider(
                    Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value,
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService));
            }
            else
            {
                throw new ArgumentException("Invalid langauge name: " + languageName, "languageName");
            }
        }
        internal DefaultKeyProcessor(IWpfTextView textView, IEditorOperations editorOperations, ITextUndoHistoryRegistry undoHistoryRegistry)
        {
            Check.ArgumentNull(nameof(textView), textView);
            Check.ArgumentNull(nameof(editorOperations), editorOperations);
            Check.ArgumentNull(nameof(undoHistoryRegistry), undoHistoryRegistry);

            _textView            = textView;
            _editorOperations    = editorOperations;
            _undoHistoryRegistry = undoHistoryRegistry;
        }
Example #30
0
        public BlockCommentEditingCommandHandler(
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            Contract.ThrowIfNull(undoHistoryRegistry);
            Contract.ThrowIfNull(editorOperationsFactoryService);

            _undoHistoryRegistry            = undoHistoryRegistry;
            _editorOperationsFactoryService = editorOperationsFactoryService;
        }
        internal AbstractCommentSelectionBase(
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            Contract.ThrowIfNull(undoHistoryRegistry);
            Contract.ThrowIfNull(editorOperationsFactoryService);

            _undoHistoryRegistry            = undoHistoryRegistry;
            _editorOperationsFactoryService = editorOperationsFactoryService;
        }
Example #32
0
        internal CommentUncommentSelectionCommandHandler(
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            Contract.ThrowIfNull(undoHistoryRegistry);
            Contract.ThrowIfNull(editorOperationsFactoryService);

            _undoHistoryRegistry            = undoHistoryRegistry;
            _editorOperationsFactoryService = editorOperationsFactoryService;
        }
        public RenameTrackingTestState(
            string markup,
            string languageName,
            bool onBeforeGlobalSymbolRenamedReturnValue = true,
            bool onAfterGlobalSymbolRenamedReturnValue = true)
        {
            this.Workspace = CreateTestWorkspace(markup, languageName, TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic());

            _hostDocument = Workspace.Documents.First();
            _view = _hostDocument.GetTextView();
            _view.Caret.MoveTo(new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value));
            _editorOperations = Workspace.GetService<IEditorOperationsFactoryService>().GetEditorOperations(_view);
            _historyRegistry = Workspace.ExportProvider.GetExport<ITextUndoHistoryRegistry>().Value;
            _mockRefactorNotifyService = new MockRefactorNotifyService
            {
                OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue,
                OnAfterSymbolRenamedReturnValue = onAfterGlobalSymbolRenamedReturnValue
            };

            var optionService = this.Workspace.Services.GetService<IOptionService>();

            // Mock the action taken by the workspace INotificationService
            var notificationService = Workspace.Services.GetService<INotificationService>() as INotificationServiceCallback;
            var callback = new Action<string, string, NotificationSeverity>((message, title, severity) => _notificationMessage = message);
            notificationService.NotificationCallback = callback;

            var tracker = new RenameTrackingTaggerProvider(
                _historyRegistry,
                Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value,
                Workspace.ExportProvider.GetExport<IInlineRenameService>().Value,
                Workspace.ExportProvider.GetExport<IDiagnosticAnalyzerService>().Value,
                SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService),
                Workspace.ExportProvider.GetExports<IAsynchronousOperationListener, FeatureMetadata>());

            _tagger = tracker.CreateTagger<RenameTrackingTag>(_hostDocument.GetTextBuffer());

            if (languageName == LanguageNames.CSharp)
            {
                _codeFixProvider = new CSharpRenameTrackingCodeFixProvider(
                    Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value,
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService));
            }
            else if (languageName == LanguageNames.VisualBasic)
            {
                _codeFixProvider = new VisualBasicRenameTrackingCodeFixProvider(
                    Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value,
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService));
            }
            else
            {
                throw new ArgumentException("Invalid langauge name: " + languageName, "languageName");
            }
        }
Example #34
0
 public FormatCommandHandler(
     IThreadingContext threadingContext,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService,
     IWaitIndicator waitIndicator)
     : base(threadingContext)
 {
     _undoHistoryRegistry            = undoHistoryRegistry;
     _editorOperationsFactoryService = editorOperationsFactoryService;
     _waitIndicator = waitIndicator;
 }
 public AsyncCompletionService(
     IEditorOperationsFactoryService editorOperationsFactoryService,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     [ImportMany] IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > asyncListeners,
     [ImportMany] IEnumerable <Lazy <IIntelliSensePresenter <ICompletionPresenterSession, ICompletionSession>, OrderableMetadata> > completionPresenters,
     [ImportMany] IEnumerable <Lazy <IBraceCompletionSessionProvider, BraceCompletionMetadata> > autoBraceCompletionChars)
     : this(editorOperationsFactoryService, undoHistoryRegistry,
            ExtensionOrderer.Order(completionPresenters).Select(lazy => lazy.Value).FirstOrDefault(),
            asyncListeners, autoBraceCompletionChars)
 {
 }
 internal DefaultKeyProcessor(
     IWpfTextView textView,
     IEditorOperations editorOperations,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEditorCommandHandlerService editorCommandHandlerService)
 {
     this._textView                    = textView;
     this._editorOperations            = editorOperations;
     this._undoHistoryRegistry         = undoHistoryRegistry;
     this._editorCommandHandlerService = editorCommandHandlerService;
 }
Example #37
0
 public AutoCommentService(
     [Import] IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
     [Import] IEditorOperationsFactoryService editorOperationsFactoryService,
     [Import] ITextUndoHistoryRegistry textUndoHistoryRegistry,
     [ImportMany] IEnumerable<Lazy<ICommenterProvider, IContentTypeMetadata>> commenterProviders)
 {
     _editorAdaptersFactoryService = editorAdaptersFactoryService;
     _editorOperationsFactoryService = editorOperationsFactoryService;
     _textUndoHistoryRegistry = textUndoHistoryRegistry;
     _commenterProviders = commenterProviders.ToList();
 }
 public AutoCommentService(
     [Import] IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
     [Import] IEditorOperationsFactoryService editorOperationsFactoryService,
     [Import] ITextUndoHistoryRegistry textUndoHistoryRegistry,
     [ImportMany] IEnumerable <Lazy <ICommenterProvider, IContentTypeMetadata> > commenterProviders)
 {
     _editorAdaptersFactoryService   = editorAdaptersFactoryService;
     _editorOperationsFactoryService = editorOperationsFactoryService;
     _textUndoHistoryRegistry        = textUndoHistoryRegistry;
     _commenterProviders             = commenterProviders.ToList();
 }
        public static CaretPreservingEditTransaction TryCreate(string description,
                                                               ITextView textView,
                                                               ITextUndoHistoryRegistry undoHistoryRegistry,
                                                               IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            if (undoHistoryRegistry.TryGetHistory(textView.TextBuffer, out var unused))
            {
                return(new CaretPreservingEditTransaction(description, textView, undoHistoryRegistry, editorOperationsFactoryService));
            }

            return(null);
        }
		public TextBufferUndoManager(ITextBuffer textBuffer, ITextUndoHistoryRegistry textUndoHistoryRegistry) {
			if (textBuffer == null)
				throw new ArgumentNullException(nameof(textBuffer));
			if (textUndoHistoryRegistry == null)
				throw new ArgumentNullException(nameof(textUndoHistoryRegistry));
			changes = new List<ChangeInfo>();
			TextBuffer = textBuffer;
			this.textUndoHistoryRegistry = textUndoHistoryRegistry;
			textBufferUndoHistory = textUndoHistoryRegistry.RegisterHistory(TextBuffer);
			TextBuffer.Changed += TextBuffer_Changed;
			TextBuffer.PostChanged += TextBuffer_PostChanged;
		}
Example #41
0
 public RenameTrackingCodeAction(
     Document document,
     string title,
     IEnumerable <IRefactorNotifyService> refactorNotifyServices,
     ITextUndoHistoryRegistry undoHistoryRegistry
     )
 {
     _document = document;
     _title    = title;
     _refactorNotifyServices = refactorNotifyServices;
     _undoHistoryRegistry    = undoHistoryRegistry;
 }
Example #42
0
            internal (CodeAction action, TextSpan renameSpan) TryGetCodeAction(
                Document document,
                SourceText text,
                TextSpan userSpan,
                IEnumerable <IRefactorNotifyService> refactorNotifyServices,
                ITextUndoHistoryRegistry undoHistoryRegistry,
                CancellationToken cancellationToken
                )
            {
                try
                {
                    // This can be called on a background thread. We are being asked whether a
                    // lightbulb should be shown for the given document, but we only know about the
                    // current state of the buffer. Compare the text to see if we should bail early.
                    // Even if the text is the same, the buffer may change on the UI thread during this
                    // method. If it does, we may give an incorrect response, but the diagnostics
                    // engine will know that the document changed and not display the lightbulb anyway.

                    if (
                        Buffer.AsTextContainer().CurrentText == text &&
                        CanInvokeRename(
                            out var trackingSession,
                            waitForResult: true,
                            cancellationToken: cancellationToken
                            )
                        )
                    {
                        var snapshotSpan = trackingSession.TrackingSpan.GetSpan(
                            Buffer.CurrentSnapshot
                            );

                        // user needs to be on the same line as the diagnostic location.
                        if (text.AreOnSameLine(userSpan.Start, snapshotSpan.Start))
                        {
                            var title = string.Format(
                                EditorFeaturesResources.Rename_0_to_1,
                                trackingSession.OriginalName,
                                snapshotSpan.GetText()
                                );

                            return(
                                new RenameTrackingCodeAction(
                                    document,
                                    title,
                                    refactorNotifyServices,
                                    undoHistoryRegistry
                                    ),
                                snapshotSpan.Span.ToTextSpan()
                                );
                        }
                    }

                    return(default);
        public static CaretPreservingEditTransaction TryCreate(string description, 
            ITextView textView,
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            if (undoHistoryRegistry.TryGetHistory(textView.TextBuffer, out var unused))
            {
                return new CaretPreservingEditTransaction(description, textView, undoHistoryRegistry, editorOperationsFactoryService);
            }

            return null;
        }
Example #44
0
        public Commenter(ITextView textView, ITextUndoHistoryRegistry textUndoHistoryRegistry, IEnumerable<CommentFormat> commentFormats)
        {
            Contract.Requires<ArgumentNullException>(textView != null, "textView");
            Contract.Requires<ArgumentNullException>(textUndoHistoryRegistry != null, "textUndoHistoryRegistry");
            Contract.Requires<ArgumentNullException>(commentFormats != null, "commentFormats");

            this._textView = textView;
            this._textUndoHistoryRegistry = textUndoHistoryRegistry;
            this._commentFormats = commentFormats.ToList().AsReadOnly();
            this._blockFormats = _commentFormats.OfType<BlockCommentFormat>().ToList().AsReadOnly();
            this._lineFormats = _commentFormats.OfType<LineCommentFormat>().ToList().AsReadOnly();
            this._useLineComments = this._lineFormats.Count > 0;
        }
Example #45
0
 public AsyncCompletionService(
     IEditorOperationsFactoryService editorOperationsFactoryService,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IInlineRenameService inlineRenameService,
     [ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners,
     [ImportMany] IEnumerable<Lazy<IIntelliSensePresenter<ICompletionPresenterSession, ICompletionSession>, OrderableMetadata>> completionPresenters,
     [ImportMany] IEnumerable<Lazy<ICompletionProvider, OrderableLanguageMetadata>> allCompletionProviders,
     [ImportMany] IEnumerable<Lazy<IBraceCompletionSessionProvider, IBraceCompletionMetadata>> autoBraceCompletionChars)
     : this(editorOperationsFactoryService, undoHistoryRegistry, inlineRenameService,
           ExtensionOrderer.Order(completionPresenters).Select(lazy => lazy.Value).FirstOrDefault(),
           asyncListeners, allCompletionProviders, autoBraceCompletionChars)
 {
 }
Example #46
0
 public CaretPreservingEditTransaction(
     string description,
     ITextView textView,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEditorOperationsFactoryService editorOperationsFactoryService
     )
     : this(
         description,
         undoHistoryRegistry.GetHistory(textView.TextBuffer),
         editorOperationsFactoryService.GetEditorOperations(textView)
         )
 {
 }
Example #47
0
        protected AbstractDocumentationCommentCommandHandler(
            IWaitIndicator waitIndicator,
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            Contract.ThrowIfNull(waitIndicator);
            Contract.ThrowIfNull(undoHistoryRegistry);
            Contract.ThrowIfNull(editorOperationsFactoryService);

            _waitIndicator                  = waitIndicator;
            _undoHistoryRegistry            = undoHistoryRegistry;
            _editorOperationsFactoryService = editorOperationsFactoryService;
        }
 public RenameTrackingCommitter(
     StateMachine stateMachine,
     SnapshotSpan snapshotSpan,
     IEnumerable<IRefactorNotifyService> refactorNotifyServices,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     string displayText)
 {
     _stateMachine = stateMachine;
     _snapshotSpan = snapshotSpan;
     _refactorNotifyServices = refactorNotifyServices;
     _undoHistoryRegistry = undoHistoryRegistry;
     _displayText = displayText;
     _renameSymbolResultGetter = new AsyncLazy<RenameTrackingSolutionSet>(c => RenameSymbolWorkerAsync(c), cacheResult: true);
 }
        internal DefaultKeyProcessor(IWpfTextView textView, IEditorOperations editorOperations, ITextUndoHistoryRegistry undoHistoryRegistry) {
            if (textView == null)
                throw new ArgumentNullException("textView");

            if (editorOperations == null)
                throw new ArgumentNullException("editorOperations");

            if (undoHistoryRegistry == null)
                throw new ArgumentNullException("undoHistoryRegistry");

            _textView = textView;
            _editorOperations = editorOperations;
            _undoHistoryRegistry = undoHistoryRegistry;
        }
 public RenameTrackingCommitter(
     StateMachine stateMachine,
     SnapshotSpan snapshotSpan,
     IEnumerable<IRefactorNotifyService> refactorNotifyServices,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     string displayText,
     bool showPreview)
 {
     _stateMachine = stateMachine;
     _snapshotSpan = snapshotSpan;
     _refactorNotifyServices = refactorNotifyServices;
     _undoHistoryRegistry = undoHistoryRegistry;
     _displayText = displayText;
     _showPreview = showPreview;
 }
Example #51
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommenterFilter"/> class for
        /// the specified text view and commenter.
        /// </summary>
        /// <param name="textViewAdapter"></param>
        /// <param name="textView">The text view.</param>
        /// <param name="commenter">The commenter implementation.</param>
        /// <param name="editorOperations">The <see cref="IEditorOperations"/> instance for the text view.</param>
        /// <param name="textUndoHistoryRegistry">The global <see cref="ITextUndoHistoryRegistry"/> service provided by
        /// Visual Studio.</param>
        /// <exception cref="ArgumentNullException">
        /// <para>If <paramref name="textViewAdapter"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="textView"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="commenter"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="editorOperations"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="textUndoHistoryRegistry"/> is <see langword="null"/>.</para>
        /// </exception>
        public CommenterFilter(IVsTextView textViewAdapter, ITextView textView, ICommenter commenter, IEditorOperations editorOperations, ITextUndoHistoryRegistry textUndoHistoryRegistry)
            : base(textViewAdapter)
        {
            Contract.Requires(textViewAdapter != null);
            Contract.Requires<ArgumentNullException>(textView != null, "textView");
            Contract.Requires<ArgumentNullException>(commenter != null, "commenter");
            Contract.Requires<ArgumentNullException>(editorOperations != null, "editorOperations");
            Contract.Requires<ArgumentNullException>(textUndoHistoryRegistry != null, "textUndoHistoryRegistry");

            this.TextView = textView;
            this.Commenter = commenter;
            this.EditorOperations = editorOperations;
            this.TextUndoHistoryRegistry = textUndoHistoryRegistry;
            textView.Closed += (sender, e) => Dispose();
        }
        public CaretPreservingEditTransaction(
            string description,
            ITextView textView,
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
            _undoHistory = undoHistoryRegistry.GetHistory(textView.TextBuffer);
            _active = true;

            if (_undoHistory != null)
            {
                _transaction = new HACK_TextUndoTransactionThatRollsBackProperly(_undoHistory.CreateTransaction(description));
                _editorOperations.AddBeforeTextBufferChangePrimitive();
            }
        }
            public StandardTextDocument(
                DocumentProvider documentProvider,
                IVisualStudioHostProject project,
                DocumentKey documentKey,
                uint itemId,
                SourceCodeKind sourceCodeKind,
                ITextBufferFactoryService textBufferFactoryService,
                ITextUndoHistoryRegistry textUndoHistoryRegistry,
                IVsFileChangeEx fileChangeService,
                ITextBuffer openTextBuffer,
                DocumentId id)
            {
                Contract.ThrowIfNull(documentProvider);
                Contract.ThrowIfNull(textBufferFactoryService);

                this.Project = project;
                this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker);
                this.Folders = project.GetFolderNames(itemId);

                // TODO: 
                // this one doesn't work for asynchronous project load situation where shared projects is loaded after one uses shared file. 
                // we need to figure out what to do on those case. but this works for project k case.
                // opened an issue to track this issue - https://github.com/dotnet/roslyn/issues/1859
                this.SharedHierarchy = project.Hierarchy == null ? null : LinkedFileUtilities.GetSharedHierarchyForItem(project.Hierarchy, itemId);
                _documentProvider = documentProvider;

                this.Key = documentKey;
                this.SourceCodeKind = sourceCodeKind;
                _itemMoniker = documentKey.Moniker;
                _textBufferFactoryService = textBufferFactoryService;
                _textUndoHistoryRegistry = textUndoHistoryRegistry;
                _fileChangeTracker = new FileChangeTracker(fileChangeService, this.FilePath);
                _fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk;

                _openTextBuffer = openTextBuffer;
                _snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer);

                // The project system does not tell us the CodePage specified in the proj file, so
                // we use null to auto-detect.
                _doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null);

                // If we aren't already open in the editor, then we should create a file change notification
                if (openTextBuffer == null)
                {
                    _fileChangeTracker.StartFileChangeListeningAsync();
                }
            }
            public WorkspaceUndoTransaction(
                ITextUndoHistoryRegistry undoHistoryRegistry,
                IVsLinkedUndoTransactionManager undoManager,
                Workspace workspace,
                string description,
                GlobalUndoService service)
                : base(assertIsForeground: true)
            {
                _undoHistoryRegistry = undoHistoryRegistry;
                _undoManager = undoManager;
                _workspace = workspace;
                _description = description;
                _service = service;

                Marshal.ThrowExceptionForHR(_undoManager.OpenLinkedUndo((uint)LinkedTransactionFlags2.mdtGlobal, _description));
                _transactionAlive = true;
            }
Example #55
0
 public AsyncCompletionService(
     IEditorOperationsFactoryService editorOperationsFactoryService,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IInlineRenameService inlineRenameService,
     IIntelliSensePresenter<ICompletionPresenterSession, ICompletionSession> completionPresenter,
     IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners,
     IEnumerable<Lazy<ICompletionProvider, OrderableLanguageMetadata>> allCompletionProviders,
     IEnumerable<Lazy<IBraceCompletionSessionProvider, IBraceCompletionMetadata>> autoBraceCompletionChars)
 {
     _editorOperationsFactoryService = editorOperationsFactoryService;
     _undoHistoryRegistry = undoHistoryRegistry;
     _inlineRenameService = inlineRenameService;
     _completionPresenter = completionPresenter;
     _asyncListeners = asyncListeners;
     _allCompletionProviders = ExtensionOrderer.Order(allCompletionProviders);
     _autoBraceCompletionChars = autoBraceCompletionChars;
     _autoBraceCompletionCharSet = new Dictionary<IContentType, ImmutableHashSet<char>>();
 }
		public void Execute(ITextView textView, ITextUndoHistoryRegistry textUndoHistoryRegistry)
		{
			var isReversed = textView.Selection.IsReversed;
			var newSelection = new List<Tuple<int, int>>();

			var undoHistory = textUndoHistoryRegistry.RegisterHistory(textView);
			using (var transaction = undoHistory.CreateTransaction("Comment Selection"))
			{
				foreach (var span in textView.Selection.SelectedSpans)
				{
					var startLine = span.Start.GetContainingLine().LineNumber;
					var endLine = span.End.GetContainingLine().LineNumber;

					if (startLine > endLine)
					{
						var tmp = startLine;
						startLine = endLine;
						endLine = tmp;
					}

					var edit = span.Snapshot.TextBuffer.CreateEdit();
					for (int lineNumber = startLine; lineNumber <= endLine; ++lineNumber)
					{
						var line = span.Snapshot.GetLineFromLineNumber(lineNumber);
						Modify(edit, line);
					}

					edit.Apply();

					newSelection.Add(Tuple.Create(startLine, endLine));
				}

				transaction.Complete();
			}

			textView.Selection.Select(new NormalizedSnapshotSpanCollection(
				newSelection.Select(l => new SnapshotSpan(
					textView.TextSnapshot.GetLineFromLineNumber(l.Item1).Start,
					textView.TextSnapshot.GetLineFromLineNumber(l.Item2).End)
				)
			)[0], isReversed);
		}
		public void Execute(ITextView textView, ITextUndoHistoryRegistry textUndoHistoryRegistry)
		{
			var undoHistory = textUndoHistoryRegistry.RegisterHistory(textView);
			using (var transaction = undoHistory.CreateTransaction("Format Document"))
			{
				var text = textView.TextBuffer.CurrentSnapshot.GetText();

				var formatted = new StringWriter();
				var parser = new Parser(new Scanner(new StringReader(text), skipComments: false));
				var emitter = new Emitter(formatted);

				while (parser.MoveNext())
				{
					emitter.Emit(parser.Current);
				}

				var edit = textView.TextBuffer.CreateEdit();
				edit.Replace(0, text.Length, formatted.ToString());
				edit.Apply();

				transaction.Complete();
			}
		}
 internal override ICommandHandler<TypeCharCommandArgs> CreateCommandHandler(ITextUndoHistoryRegistry undoHistory)
 {
     return new XmlTagCompletionCommandHandler(undoHistory, TestWaitIndicator.Default);
 }
 public XmlTagCompletionCommandHandler(ITextUndoHistoryRegistry undoHistory, IWaitIndicator waitIndicator)
     : base(undoHistory, waitIndicator)
 {
 }
Example #60
0
 public Commenter(ITextView textView, ITextUndoHistoryRegistry textUndoHistoryRegistry, params CommentFormat[] commentFormats)
     : this(textView, textUndoHistoryRegistry, commentFormats.AsEnumerable())
 {
     Contract.Requires(textView != null);
     Contract.Requires(textUndoHistoryRegistry != null);
 }