Exemplo n.º 1
0
        private async Task ProcessDocumentChangedEvent(WorkspaceChangeEventArgs workspaceChangeEventArgs)
        {
            var declaredTypeSymbols = await GetDeclaredTypeSymbols(workspaceChangeEventArgs.NewSolution,
                                                                   workspaceChangeEventArgs.ProjectId, workspaceChangeEventArgs.DocumentId);

            foreach (var declaredTypeSymbol in declaredTypeSymbols)
            {
                // Match by name
                var matchingEntityByName = _model.RoslynBasedEntities.FirstOrDefault(i => i.RoslynSymbol.SymbolEquals(declaredTypeSymbol));
                if (matchingEntityByName != null)
                {
                    Debug.WriteLine($"Found entity {declaredTypeSymbol.Name} by name.");
                    _model.UpdateEntity(matchingEntityByName, declaredTypeSymbol);
                    continue;
                }

                // Match by location
                var mathingEntityByLocation = _model.GetEntityByLocation(declaredTypeSymbol.Locations.FirstOrDefault());
                if (mathingEntityByLocation != null)
                {
                    Debug.WriteLine($"Found entity {declaredTypeSymbol.Name} by location.");
                    _model.UpdateEntity(mathingEntityByLocation, declaredTypeSymbol);

                    continue;
                }
            }
        }
Exemplo n.º 2
0
        private void UpdateEntitiesFromSource(CancellationToken cancellationToken, IIncrementalProgress progress)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var workspace    = _roslynModelProvider.GetWorkspace();
            var compilations = workspace.CurrentSolution.Projects.Select(i => i.GetCompilationAsync(cancellationToken))
                               .Select(i => i.Result).ToArray();

            foreach (var roslynBasedModelEntity in _model.Entities.OfType <RoslynBasedModelEntity>().ToArray())
            {
                cancellationToken.ThrowIfCancellationRequested();

                var namedTypeSymbol    = roslynBasedModelEntity.RoslynSymbol;
                var newVersionOfSymbol = FindSymbolInCompilations(namedTypeSymbol, compilations, cancellationToken);

                if (newVersionOfSymbol == null)
                {
                    _model.RemoveEntity(roslynBasedModelEntity);
                }
                else
                {
                    _model.UpdateEntity(roslynBasedModelEntity, newVersionOfSymbol);
                }

                progress?.Report(1);
            }
        }