public void SelectionAdjustmentAddsToReplacementSelectionOnRecoverSelections() { var selectionServiceMock = TestSelectionServiceMock(); var parseManager = new Mock <IParseManager>().Object; var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManager); var selectionOffset = new Selection(0, 2, 4, 5); var selectionReplacement = new Selection(22, 2, 44, 5); selectionRecoverer.SaveSelections(_testModuleSelections .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(1)); selectionRecoverer.ReplaceSavedSelection(_testModuleSelections[0].QualifiedName, selectionReplacement); selectionRecoverer.AdjustSavedSelection(_testModuleSelections[0].QualifiedName, selectionOffset); selectionRecoverer.RecoverSavedSelections(); var expectedAdjustedSelection = selectionReplacement.Offset(selectionOffset); selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, expectedAdjustedSelection), Times.Once); }
ActivatesSavedActiveCodePaneOnNextParseAfterOnRecoverActiveCodePaneOnNextParse_ActiveSelectionExists() { var selectionServiceMock = TestSelectionServiceMock(); var activeSelection = _testModuleSelections[1]; selectionServiceMock.Setup(m => m.ActiveSelection()).Returns(activeSelection); var parseManagerMock = new Mock <IParseManager>(); var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManagerMock.Object); selectionRecoverer.SaveActiveCodePane(); selectionRecoverer.RecoverActiveCodePaneOnNextParse(); var stateEventArgs = new ParserStateEventArgs(_stateExpectedToTriggerTheRecovery, ParserState.Pending, CancellationToken.None); parseManagerMock.Raise(m => m.StateChanged += null, stateEventArgs); selectionServiceMock.Verify(m => m.TryActivate(activeSelection.QualifiedName), Times.Once); }
public void SetsExactlyLastSavedSelectionsOnRecoverSelectionsAfterMultipleSaves() { var selectionServiceMock = TestSelectionServiceMock(); var parseManager = new Mock <IParseManager>().Object; var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManager); selectionRecoverer.SaveSelections(_testModuleSelections .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2)); selectionRecoverer.SaveSelections(_testModuleSelections .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Skip(1)); selectionRecoverer.RecoverSavedSelections(); foreach (var qualifiedSelection in _testModuleSelections.Skip(1)) { selectionServiceMock.Verify( m => m.TrySetSelection(qualifiedSelection.QualifiedName, qualifiedSelection.Selection), Times.Once); } selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, It.IsAny <Selection>()), Times.Never); }
public void SetsReplacementSelectionOnRecoverSelections_SelectionSavedPreviously() { var selectionServiceMock = TestSelectionServiceMock(); var parseManager = new Mock <IParseManager>().Object; var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManager); var selectionReplacement = new Selection(22, 2, 44, 5); selectionRecoverer.SaveSelections(_testModuleSelections .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2)); selectionRecoverer.ReplaceSavedSelection(_testModuleSelections[0].QualifiedName, selectionReplacement); selectionRecoverer.RecoverSavedSelections(); selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, selectionReplacement), Times.Once); selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[1].QualifiedName, _testModuleSelections[1].Selection), Times.Once); selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[2].QualifiedName, It.IsAny <Selection>()), Times.Never); }
public void SetReplacementSelectionOnNextParseAfterRecoverSelectionsOnNextParse_SelectionNotSavedPreviously_ModuleOpen() { var selectionServiceMock = TestSelectionServiceMock(); var parseManagerMock = new Mock <IParseManager>(); var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManagerMock.Object); var selectionReplacement = new Selection(22, 2, 44, 5); selectionRecoverer.SaveSelections(_testModuleSelections.Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2)); selectionRecoverer.ReplaceSavedSelection(_testModuleSelections[2].QualifiedName, selectionReplacement); selectionRecoverer.RecoverSavedSelectionsOnNextParse(); var stateEventArgs = new ParserStateEventArgs(_stateExpectedToTriggerTheRecovery, ParserState.Pending, CancellationToken.None); parseManagerMock.Raise(m => m.StateChanged += null, stateEventArgs); selectionServiceMock.Verify(m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, _testModuleSelections[0].Selection), Times.Once); selectionServiceMock.Verify(m => m.TrySetSelection(_testModuleSelections[1].QualifiedName, _testModuleSelections[1].Selection), Times.Once); selectionServiceMock.Verify(m => m.TrySetSelection(_testModuleSelections[2].QualifiedName, selectionReplacement), Times.Once); selectionServiceMock.Verify(m => m.TrySetSelection(_testModuleSelections[3].QualifiedName, It.IsAny <Selection>()), Times.Never); }
public void RecoverSelectionsOnNextParseDoesNotSetAnythingImmediately() { var selectionServiceMock = TestSelectionServiceMock(); var parseManager = new Mock <IParseManager>().Object; var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManager); var selectionOffset = new Selection(0, 2, 4, 5); var selectionReplacement = new Selection(22, 2, 44, 5); selectionRecoverer.SaveSelections(_testModuleSelections .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2)); selectionRecoverer.ReplaceSavedSelection(_testModuleSelections[2].QualifiedName, selectionReplacement); selectionRecoverer.AdjustSavedSelection(_testModuleSelections[0].QualifiedName, selectionOffset); selectionRecoverer.RecoverSavedSelectionsOnNextParse(); foreach (var qualifiedSelection in _testModuleSelections) { selectionServiceMock.Verify( m => m.TrySetSelection(qualifiedSelection.QualifiedName, qualifiedSelection.Selection), Times.Never); } }
public void SetsModifiedSelectionAfterOffsetIsAppliedOnRecoverSelections() { var selectionServiceMock = TestSelectionServiceMock(); var parseManager = new Mock <IParseManager>().Object; var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManager); var selectionOffset = new Selection(0, 2, 4, 5); selectionRecoverer.SaveSelections(_testModuleSelections .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2)); selectionRecoverer.AdjustSavedSelection(_testModuleSelections[0].QualifiedName, selectionOffset); selectionRecoverer.RecoverSavedSelections(); var expectedAdjustedSelection = _testModuleSelections[0].Selection.Offset(selectionOffset); selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, expectedAdjustedSelection), Times.Once); selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[1].QualifiedName, _testModuleSelections[1].Selection), Times.Once); selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[2].QualifiedName, It.IsAny <Selection>()), Times.Never); }
public void ReplacementSelectionOverwritesAdjustmentOnParseAfterRecoverSelectionsOnNextParse() { var selectionServiceMock = TestSelectionServiceMock(); var parseManagerMock = new Mock <IParseManager>(); var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManagerMock.Object); var selectionOffset = new Selection(0, 2, 4, 5); var selectionReplacement = new Selection(22, 2, 44, 5); selectionRecoverer.SaveSelections(_testModuleSelections .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(1)); selectionRecoverer.AdjustSavedSelection(_testModuleSelections[0].QualifiedName, selectionOffset); selectionRecoverer.ReplaceSavedSelection(_testModuleSelections[0].QualifiedName, selectionReplacement); selectionRecoverer.RecoverSavedSelectionsOnNextParse(); var stateEventArgs = new ParserStateEventArgs(_stateExpectedToTriggerTheRecovery, ParserState.Pending, CancellationToken.None); parseManagerMock.Raise(m => m.StateChanged += null, stateEventArgs); selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[0].QualifiedName, selectionReplacement), Times.Once); }
public void OnNextParseAfterSetupOpenModulesWithSavedOpenStateBeforeSettingSelection() { var lastCalledMethod = string.Empty; var selectionServiceMock = TestSelectionServiceMock(); selectionServiceMock.Setup(m => m.TryActivate(It.IsAny <QualifiedModuleName>())) .Callback((QualifiedModuleName module) => lastCalledMethod = "TryActivate"); selectionServiceMock.Setup(m => m.TrySetSelection(It.IsAny <QualifiedModuleName>(), It.IsAny <Selection>())) .Callback((QualifiedModuleName module, Selection selection) => lastCalledMethod = "TrySetSelection"); var openModules = _testModuleSelections.Take(3) .Select(qualifiedSelection => qualifiedSelection.QualifiedName) .ToHashSet(); selectionServiceMock.Setup(m => m.OpenModules()).Returns(openModules); var parseManagerMock = new Mock <IParseManager>(); var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManagerMock.Object); var modulesForWhichToSaveOpenState = _testModuleSelections.Skip(1) .Select(qualifiedSelection => qualifiedSelection.QualifiedName) .ToHashSet(); var selectionRecoveryModules = _testModuleSelections .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2); selectionRecoverer.SaveSelections(selectionRecoveryModules); selectionRecoverer.RecoverSavedSelectionsOnNextParse(); selectionRecoverer.SaveOpenState(modulesForWhichToSaveOpenState); selectionRecoverer.RecoverOpenStateOnNextParse(); var stateEventArgs = new ParserStateEventArgs(_stateExpectedToTriggerTheRecovery, ParserState.Pending, CancellationToken.None); parseManagerMock.Raise(m => m.StateChanged += null, stateEventArgs); Assert.AreEqual("TrySetSelection", lastCalledMethod); }
public void ActivatesOpenModulesWithSavedOpenStateOnRecoverOpenState() { var selectionServiceMock = TestSelectionServiceMock(); var openModules = _testModuleSelections.Take(3) .Select(qualifiedSelection => qualifiedSelection.QualifiedName) .ToHashSet(); selectionServiceMock.Setup(m => m.OpenModules()).Returns(openModules); var parseManagerMock = new Mock <IParseManager>(); var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManagerMock.Object); var modulesForWhichToSaveOpenState = _testModuleSelections.Skip(1) .Select(qualifiedSelection => qualifiedSelection.QualifiedName) .ToHashSet(); selectionRecoverer.SaveOpenState(modulesForWhichToSaveOpenState); selectionRecoverer.RecoverOpenState(); selectionServiceMock.Verify(m => m.TryActivate(_testModuleSelections[1].QualifiedName), Times.Once); selectionServiceMock.Verify(m => m.TryActivate(_testModuleSelections[2].QualifiedName), Times.Once); selectionServiceMock.Verify(m => m.TryActivate(_testModuleSelections[0].QualifiedName), Times.Never); selectionServiceMock.Verify(m => m.TryActivate(_testModuleSelections[3].QualifiedName), Times.Never); }
public void SetsExactlySavedSelectionsOnParseAfterRecoverSelectionsOnNextParse() { var selectionServiceMock = TestSelectionServiceMock(); var parseManagerMock = new Mock <IParseManager>(); var selectionRecoverer = new SelectionRecoverer(selectionServiceMock.Object, parseManagerMock.Object); selectionRecoverer.SaveSelections(_testModuleSelections .Select(qualifiedSelection => qualifiedSelection.QualifiedName).Take(2)); selectionRecoverer.RecoverSavedSelectionsOnNextParse(); var stateEventArgs = new ParserStateEventArgs(_stateExpectedToTriggerTheRecovery, ParserState.Pending, CancellationToken.None); parseManagerMock.Raise(m => m.StateChanged += null, stateEventArgs); foreach (var qualifiedSelection in _testModuleSelections.Take(2)) { selectionServiceMock.Verify( m => m.TrySetSelection(qualifiedSelection.QualifiedName, qualifiedSelection.Selection), Times.Once); } selectionServiceMock.Verify( m => m.TrySetSelection(_testModuleSelections[2].QualifiedName, It.IsAny <Selection>()), Times.Never); }
public static (SynchronousParseCoordinator parser, IRewritingManager rewritingManager) CreateWithRewriteManager(IVBE vbe, RubberduckParserState state, IProjectsRepository projectRepository, string serializedComProjectsPath = null, IDictionary <string, IEnumerable <string> > documentModuleSupertypeNames = null) { var vbeVersion = double.Parse(vbe.Version, CultureInfo.InvariantCulture); var compilationArgumentsProvider = MockCompilationArgumentsProvider(vbeVersion); var compilationsArgumentsCache = new CompilationArgumentsCache(compilationArgumentsProvider); var userComProjectsRepository = MockUserComProjectRepository(); var documentSuperTypesProvider = MockDocumentSuperTypeNamesProvider(documentModuleSupertypeNames); var ignoredProjectsSettingsProvider = MockIgnoredProjectsSettingsProviderMock(); var projectsToBeLoadedFromComSelector = new ProjectsToResolveFromComProjectsSelector(projectRepository, ignoredProjectsSettingsProvider); var path = serializedComProjectsPath ?? Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(MockParser)).Location), "Testfiles", "Resolver"); var preprocessorErrorListenerFactory = new PreprocessingParseErrorListenerFactory(); var preprocessorParser = new VBAPreprocessorParser(preprocessorErrorListenerFactory, preprocessorErrorListenerFactory); var preprocessor = new VBAPreprocessor(preprocessorParser, compilationsArgumentsCache); var mainParseErrorListenerFactory = new MainParseErrorListenerFactory(); var mainTokenStreamParser = new VBATokenStreamParser(mainParseErrorListenerFactory, mainParseErrorListenerFactory); var tokenStreamProvider = new SimpleVBAModuleTokenStreamProvider(); var stringParser = new TokenStreamParserStringParserAdapterWithPreprocessing(tokenStreamProvider, mainTokenStreamParser, preprocessor); var vbaParserAnnotationFactory = new VBAParserAnnotationFactory(WellKnownAnnotations()); var projectManager = new RepositoryProjectManager(projectRepository); var moduleToModuleReferenceManager = new ModuleToModuleReferenceManager(); var supertypeClearer = new SynchronousSupertypeClearer(state); var parserStateManager = new SynchronousParserStateManager(state); var referenceRemover = new SynchronousReferenceRemover(state, moduleToModuleReferenceManager); var baseComDeserializer = new XmlComProjectSerializer(new MockFileSystem(), path); var comDeserializer = new StaticCachingComDeserializerDecorator(baseComDeserializer); var declarationsFromComProjectLoader = new DeclarationsFromComProjectLoader(); var referencedDeclarationsCollector = new SerializedReferencedDeclarationsCollector(declarationsFromComProjectLoader, comDeserializer); var userComProjectSynchronizer = new UserComProjectSynchronizer(state, declarationsFromComProjectLoader, userComProjectsRepository, projectsToBeLoadedFromComSelector); var comSynchronizer = new SynchronousCOMReferenceSynchronizer( state, parserStateManager, projectRepository, referencedDeclarationsCollector); var builtInDeclarationLoader = new BuiltInDeclarationLoader( state, new List <ICustomDeclarationLoader> { new DebugDeclarations(state), new SpecialFormDeclarations(state), new FormEventDeclarations(state), new AliasDeclarations(state), }); var codePaneComponentSourceCodeHandler = new CodeModuleComponentSourceCodeHandler(); var codePaneSourceCodeHandler = new ComponentSourceCodeHandlerSourceCodeHandlerAdapter(codePaneComponentSourceCodeHandler, projectRepository); //We use the same handler because to achieve consistency between the return values. var attributesSourceCodeHandler = codePaneSourceCodeHandler; var moduleParser = new ModuleParser( codePaneSourceCodeHandler, attributesSourceCodeHandler, stringParser, vbaParserAnnotationFactory); var parseRunner = new SynchronousParseRunner( state, parserStateManager, moduleParser); var declarationResolveRunner = new SynchronousDeclarationResolveRunner( state, parserStateManager, comSynchronizer); var referenceResolveRunner = new SynchronousReferenceResolveRunner( state, parserStateManager, moduleToModuleReferenceManager, referenceRemover, documentSuperTypesProvider); var parsingStageService = new ParsingStageService( comSynchronizer, builtInDeclarationLoader, parseRunner, declarationResolveRunner, referenceResolveRunner, userComProjectSynchronizer ); var parsingCacheService = new ParsingCacheService( state, moduleToModuleReferenceManager, referenceRemover, supertypeClearer, compilationsArgumentsCache, userComProjectsRepository, projectsToBeLoadedFromComSelector ); var tokenStreamCache = new StateTokenStreamCache(state); var moduleRewriterFactory = new ModuleRewriterFactory( codePaneSourceCodeHandler, attributesSourceCodeHandler); var rewriterProvider = new RewriterProvider(tokenStreamCache, moduleRewriterFactory); var selectionService = new SelectionService(vbe, projectRepository); var selectionRecoverer = new SelectionRecoverer(selectionService, state); var rewriteSessionFactory = new RewriteSessionFactory(state, rewriterProvider, selectionRecoverer); var stubMembersAttributeRecoverer = new Mock <IMemberAttributeRecovererWithSettableRewritingManager>().Object; var rewritingManager = new RewritingManager(rewriteSessionFactory, stubMembersAttributeRecoverer); var parser = new SynchronousParseCoordinator( state, parsingStageService, parsingCacheService, projectManager, parserStateManager, rewritingManager); return(parser, rewritingManager); }