Ejemplo n.º 1
0
 public StateAgro(NavMeshAgent _agent, Vector3 _point, Transform _transform, ref StateSet _set)
 {
     set = _set;
     transform = _transform;
     agent = _agent;
     point = _point;
 }
            /// <summary>
            /// Return all local diagnostics (syntax, semantic) that belong to given document for the given StateSet (analyzer) either from cache or by calculating them
            /// </summary>
            public async Task<DocumentAnalysisData> GetDocumentAnalysisDataAsync(
                CompilationWithAnalyzers analyzerDriverOpt, Document document, StateSet stateSet, AnalysisKind kind, CancellationToken cancellationToken)
            {
                try
                {
                    var version = await GetDiagnosticVersionAsync(document.Project, cancellationToken).ConfigureAwait(false);
                    var state = stateSet.GetActiveFileState(document.Id);
                    var existingData = state.GetAnalysisData(kind);

                    if (existingData.Version == version)
                    {
                        return existingData;
                    }

                    // perf optimization. check whether analyzer is suppressed and avoid getting diagnostics if suppressed.
                    // REVIEW: IsAnalyzerSuppressed call seems can be quite expensive in certain condition. is there any other way to do this?
                    if (_owner.Owner.IsAnalyzerSuppressed(stateSet.Analyzer, document.Project))
                    {
                        return new DocumentAnalysisData(version, existingData.Items, ImmutableArray<DiagnosticData>.Empty);
                    }

                    var nullFilterSpan = (TextSpan?)null;
                    var diagnostics = await ComputeDiagnosticsAsync(analyzerDriverOpt, document, stateSet.Analyzer, kind, nullFilterSpan, cancellationToken).ConfigureAwait(false);

                    // we only care about local diagnostics
                    return new DocumentAnalysisData(version, existingData.Items, diagnostics.ToImmutableArrayOrEmpty());
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
            public async Task<AnalysisData> GetDocumentBodyAnalysisDataAsync(
                StateSet stateSet, VersionArgument versions, DiagnosticAnalyzerDriver analyzerDriver,
                SyntaxNode root, SyntaxNode member, int memberId, bool supportsSemanticInSpan, MemberRangeMap.MemberRanges ranges)
            {
                try
                {
                    var document = analyzerDriver.Document;
                    var cancellationToken = analyzerDriver.CancellationToken;

                    var state = stateSet.GetState(StateType.Document);
                    var existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);

                    ImmutableArray<DiagnosticData> diagnosticData;
                    if (supportsSemanticInSpan && CanUseRange(memberId, ranges.Ranges) && CanUseDocumentState(existingData, ranges.TextVersion, versions.DataVersion))
                    {
                        var memberDxData = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);

                        diagnosticData = _owner.UpdateDocumentDiagnostics(existingData, ranges.Ranges, memberDxData.AsImmutableOrEmpty(), root.SyntaxTree, member, memberId);
                        ValidateMemberDiagnostics(stateSet.Analyzer, document, root, diagnosticData);
                    }
                    else
                    {
                        // if we can't re-use existing document state, only option we have is updating whole document state here.
                        var dx = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);
                        diagnosticData = dx.AsImmutableOrEmpty();
                    }
                    return new AnalysisData(versions.TextVersion, versions.DataVersion, GetExistingItems(existingData), diagnosticData);
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
Ejemplo n.º 4
0
        public void StatesEqualityTests()
        {
            var s1 = new StateSet
            {
                new State(1),
                new State(2),
                new State(438783),
                new State(4),
                new State(10010),
            };

            var s2 = new StateSet
            {
                new State(1),
                new State(2),
                new State(438783),
                new State(4),
                new State(10010),
            };

            var s3 = new StateSet
            {
                new State(1),
                new State(2),
                new State(438783),
                new State(5),
                new State(10010),
            };

            Assert.That(s1.GetHashCode(), Is.EqualTo(s2.GetHashCode()));
            Assert.That(s1, Is.EqualTo(s2));
            Assert.That(s1.GetHashCode(), Is.Not.EqualTo(s3.GetHashCode()));
            Assert.That(s1, Is.Not.EqualTo(s3));
        }
                    public DiagnosticAnalyzerMap(HostAnalyzerManager analyzerManager, string language, ImmutableDictionary<DiagnosticAnalyzer, StateSet> analyzerMap)
                    {
                        // hold directly on to compiler analyzer
                        _compilerAnalyzer = analyzerManager.GetCompilerDiagnosticAnalyzer(language);

                        // in test case, we might not have the compiler analyzer.
                        if (_compilerAnalyzer == null)
                        {
                            _map = analyzerMap;
                            return;
                        }

                        _compilerStateSet = analyzerMap[_compilerAnalyzer];

                        // hold rest of analyzers
                        _map = analyzerMap.Remove(_compilerAnalyzer);
                    }
            public async Task<AnalysisData> GetDocumentAnalysisDataAsync(DiagnosticAnalyzerDriver analyzerDriver, StateSet stateSet, VersionArgument versions)
            {
                try
                {
                    var document = analyzerDriver.Document;
                    var cancellationToken = analyzerDriver.CancellationToken;

                    var state = stateSet.GetState(StateType.Document);
                    var existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);

                    if (CheckSemanticVersions(document, existingData, versions))
                    {
                        return existingData;
                    }

                    var diagnosticData = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);
                    return new AnalysisData(versions.TextVersion, versions.DataVersion, GetExistingItems(existingData), diagnosticData.AsImmutableOrEmpty());
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
Ejemplo n.º 7
0
        private bool SkipRunningAnalyzer(
            CompilationOptions compilationOptions,
            DiagnosticAnalyzerDriver userDiagnosticDriver,
            bool openedDocument,
            bool skipClosedFileChecks,
            StateSet stateSet)
        {
            if (Owner.IsAnalyzerSuppressed(stateSet.Analyzer, userDiagnosticDriver.Project))
            {
                return(true);
            }

            if (skipClosedFileChecks)
            {
                return(false);
            }

            if (ShouldRunAnalyzerForClosedFile(compilationOptions, openedDocument, stateSet.Analyzer))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        public void Check(CheckType checkType)
        {
            this.checkType = checkType;
            switch (checkType)
            {
            case CheckType.User:
                if (dialog == null || !dialog.Visible)
                {
                    UpdateCheckForm updateCheckForm = new UpdateCheckForm(null);
                    updateCheckForm.Load          += new EventHandler(OnLoad);
                    updateCheckForm.StateSet      += new UpdateCheckForm.UpdateCheckFormEventHandler(OnStateSet);
                    updateCheckForm.HelpRequested += new HelpEventHandler(OnHelpRequested);
                    dialog = updateCheckForm;
                    DialogCreated?.Invoke(this, updateCheckForm);
                    StateSet?.Invoke(State.Connecting, Properties.Resources.MessageConnecting);     //The Connecting state is set in constructor of the form and event is not fired!
                    updateCheckForm.ShowDialog(parent);
                }
                break;

            default:
                timer.Start();
                break;
            }
        }
        public void reset(StateSet states)
        {
            bits   = states.bits;
            index  = 0;
            offset = 0;
            mask   = 1;
            //current = 0;

            while (index < bits.Length && bits[index] == 0)
            {
                index++;
            }

            if (index >= bits.Length)
            {
                return;
            }

            while (offset <= StateSet.MASK && ((bits[index] & mask) == 0))
            {
                mask <<= 1;
                offset++;
            }
        }
            protected override async Task <ImmutableArray <DiagnosticData>?> GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var activeFileDiagnostics = GetActiveFileDiagnostics(stateSet, documentId, kind);

                if (activeFileDiagnostics.HasValue)
                {
                    return(activeFileDiagnostics.Value);
                }

                var projectDiagnostics = await GetProjectStateDiagnosticsAsync(stateSet, project, documentId, kind, cancellationToken).ConfigureAwait(false);

                if (projectDiagnostics.HasValue)
                {
                    return(projectDiagnostics.Value);
                }

                return(null);
            }
 protected abstract Task <AnalysisData> GetDiagnosticAnalysisDataAsync(Solution solution, DiagnosticAnalyzerDriver analyzerDriver, StateSet stateSet, StateType stateType, VersionArgument versions);
Ejemplo n.º 12
0
            private async Task <ImmutableArray <DiagnosticData> > GetProjectStateDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                if (!stateSet.TryGetProjectState(project.Id, out var state))
                {
                    // never analyzed this project yet.
                    return(ImmutableArray <DiagnosticData> .Empty);
                }

                if (documentId != null)
                {
                    // file doesn't exist in current solution
                    var document = project.Solution.GetDocument(documentId);
                    if (document == null)
                    {
                        return(ImmutableArray <DiagnosticData> .Empty);
                    }

                    var result = await state.GetAnalysisDataAsync(Owner.PersistentStorageService, document, avoidLoadingData : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                    return(result.GetDocumentDiagnostics(documentId, kind));
                }

                Contract.ThrowIfFalse(kind == AnalysisKind.NonLocal);
                var nonLocalResult = await state.GetProjectAnalysisDataAsync(Owner.PersistentStorageService, project, avoidLoadingData : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                return(nonLocalResult.GetOtherDiagnostics());
            }
        private async Task PersistAndReportAsync(
            StateSet stateSet, StateType stateType, Document document, VersionStamp textVersion, VersionStamp semanticVersion, ImmutableArray<DiagnosticData> diagnostics)
        {
            var state = stateSet.GetState(stateType);
            var existingDiagnostics = await state.TryGetExistingDataAsync(document, CancellationToken.None).ConfigureAwait(false);

            var mergedDiagnostics = MergeDiagnostics(diagnostics, GetExistingDiagnostics(existingDiagnostics));
            await state.PersistAsync(document, new AnalysisData(textVersion, semanticVersion, mergedDiagnostics), CancellationToken.None).ConfigureAwait(false);
            RaiseDiagnosticsUpdated(stateType, document.Id, stateSet, new SolutionArgument(document), mergedDiagnostics);
        }
Ejemplo n.º 14
0
 private void UndoService_StateSet(object sender, StateSetEventArgs e)
 {
     StateSet?.Invoke(this, e);
 }
Ejemplo n.º 15
0
 public void SetupStateSet(Vector3 pointDown, Vector3 pointDeploy, Vector3 pointMarch, GameObject enemySF)
 {
     agent = GetComponentInChildren<NavMeshAgent>();
     targetSeeker = GetComponent<TargetSeek>();
     stateSet = new StateSet();
     //Debug.Log(pointDown);
     stateSet.down = new StateDown(agent, pointDown, transform, ref stateSet);
     stateSet.deploy = new StateDeploy(agent, pointDeploy, transform, ref stateSet);
     stateSet.marsh = new StateMarsh(agent, pointMarch, transform, ref stateSet);
     stateSet.assault = new StateAssault(agent, enemySF.transform.position, transform, ref stateSet);
     stateSet.agro = new StateAgro(agent, enemySF.transform.position, transform, ref stateSet);
     stateSet.agro.optimalDistance = optimalDistance;
     stateSet.agro.chaseDistance = chaseDistance;
     stateSet.agro.fearDistance = fearDistance;
     stateSet.currentState = stateSet.down;
 }
        private void RaiseProjectDiagnosticsCreated(Project project, StateSet stateSet, DiagnosticAnalysisResult oldAnalysisResult, DiagnosticAnalysisResult newAnalysisResult, Action<DiagnosticsUpdatedArgs> raiseEvents)
        {
            foreach (var documentId in newAnalysisResult.DocumentIds)
            {
                var document = project.GetDocument(documentId);
                if (document == null)
                {
                    // it can happen with build synchronization since, in build case, 
                    // we don't have actual snapshot (we have no idea what sources out of proc build has picked up)
                    // so we might be out of sync.
                    // example of such cases will be changing anything about solution while building is going on.
                    // it can be user explict actions such as unloading project, deleting a file, but also it can be 
                    // something project system or roslyn workspace does such as populating workspace right after
                    // solution is loaded.
                    continue;
                }

                RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.NonLocal, oldAnalysisResult, newAnalysisResult, raiseEvents);

                // we don't raise events for active file. it will be taken cared by active file analysis
                if (stateSet.IsActiveFile(documentId))
                {
                    continue;
                }

                RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.Syntax, oldAnalysisResult, newAnalysisResult, raiseEvents);
                RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.Semantic, oldAnalysisResult, newAnalysisResult, raiseEvents);
            }

            RaiseDiagnosticsCreated(project, stateSet, newAnalysisResult.Others, raiseEvents);
        }
 public ProjectState(StateSet owner, ProjectId projectId)
 {
     _owner      = owner;
     _lastResult = new DiagnosticAnalysisResult(projectId, VersionStamp.Default, documentIds: null, isEmpty: true, fromBuild: false);
 }
Ejemplo n.º 18
0
 public Enemy(Transform Hand, GameManagerSrc GameManager) : base(Hand, GameManager)
 {
     this.StateSet      = new StateSet(this);
     this.State         = this.StateSet.Normal;
     this.NextCardTypes = new List <Deck.Deck.CardType>();
 }
 private int PriorityComparison(StateSet state1, StateSet state2)
 => GetPriority(state1) - GetPriority(state2);
Ejemplo n.º 20
0
Archivo: NFA.cs Proyecto: surenkov/UCP
 public override void Initial()
 {
     Current = new StateSet();
     Current.UnionWith(_epsClosures[StartState]);
 }
 private static ArgumentKey CreateArgumentKey(StateType type, object key, StateSet stateSet)
 {
     return(stateSet.ErrorSourceName != null
         ? new HostAnalyzerKey(stateSet.Analyzer, type, key, stateSet.ErrorSourceName)
         : new ArgumentKey(stateSet.Analyzer, type, key));
 }
Ejemplo n.º 22
0
 public static void DisableCullFace(this StateSet stateSet)
 {
     stateSet.setMode((uint)OsgModule.GL_CULL_FACE, (uint)StateAttribute.Values.OFF);
 }
Ejemplo n.º 23
0
 public static void DisableLights(this StateSet stateSet)
 {
     stateSet.setMode((uint)OsgModule.GL_LIGHTING, (uint)StateAttribute.Values.OFF);
 }
Ejemplo n.º 24
0
 public static void DisableShaders(this StateSet stateSet)
 {
     stateSet.setAttribute(new Program(), StateAttribute.Values.OVERRIDE);
 }
        private void RaiseDocumentDiagnosticsIfNeeded(
            Document document, StateSet stateSet, AnalysisKind kind,
            DiagnosticAnalysisResult oldResult, DiagnosticAnalysisResult newResult,
            Action<DiagnosticsUpdatedArgs> raiseEvents)
        {
            var oldItems = GetResult(oldResult, kind, document.Id);
            var newItems = GetResult(newResult, kind, document.Id);

            RaiseDocumentDiagnosticsIfNeeded(document, stateSet, kind, oldItems, newItems, raiseEvents);
        }
 private void RaiseDiagnosticsRemoved(
     StateType type, object key, StateSet stateSet, SolutionArgument solution, Action<DiagnosticsUpdatedArgs> raiseEvents)
 {
     // get right arg id for the given analyzer
     var id = CreateArgumentKey(type, key, stateSet);
     raiseEvents(DiagnosticsUpdatedArgs.DiagnosticsRemoved(id, Workspace, solution.Solution, solution.ProjectId, solution.DocumentId));
 }
        private void RaiseProjectDiagnosticsRemoved(StateSet stateSet, ProjectId projectId, IEnumerable<DocumentId> documentIds, bool handleActiveFile, Action<DiagnosticsUpdatedArgs> raiseEvents)
        {
            Solution nullSolution = null;
            foreach (var documentId in documentIds)
            {
                RaiseDiagnosticsRemoved(documentId, nullSolution, stateSet, AnalysisKind.NonLocal, raiseEvents);

                // we don't raise events for active file. it will be taken cared by active file analysis
                if (!handleActiveFile && stateSet.IsActiveFile(documentId))
                {
                    continue;
                }

                RaiseDiagnosticsRemoved(documentId, nullSolution, stateSet, AnalysisKind.Syntax, raiseEvents);
                RaiseDiagnosticsRemoved(documentId, nullSolution, stateSet, AnalysisKind.Semantic, raiseEvents);
            }

            RaiseDiagnosticsRemoved(projectId, nullSolution, stateSet, raiseEvents);
        }
 private static ArgumentKey CreateArgumentKey(StateType type, object key, StateSet stateSet)
 {
     return stateSet.ErrorSourceName != null
         ? new HostAnalyzerKey(stateSet.Analyzer, type, key, stateSet.ErrorSourceName)
         : new ArgumentKey(stateSet.Analyzer, type, key);
 }
Ejemplo n.º 29
0
 /// <inheritdoc/>
 public bool Equals(StateSet <TState> other) => this.SetEquals(other);
Ejemplo n.º 30
0
            private static async Task <ImmutableArray <DiagnosticData> > GetProjectStateDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                if (!stateSet.TryGetProjectState(project.Id, out var state))
                {
                    // never analyzed this project yet.
                    return(ImmutableArray <DiagnosticData> .Empty);
                }

                if (documentId != null)
                {
                    // file doesn't exist in current solution
                    var document = await project.Solution.GetDocumentAsync(
                        documentId,
                        includeSourceGenerated : project.Solution.Workspace.Services.GetService <ISyntaxTreeConfigurationService>() is { EnableOpeningSourceGeneratedFilesInWorkspace : true },
 private async Task ClearExistingDiagnostics(Project project, StateSet stateSet, CancellationToken cancellationToken)
 {
     var state = stateSet.GetState(StateType.Project);
     var existingData = await state.TryGetExistingDataAsync(project, cancellationToken).ConfigureAwait(false);
     if (existingData?.Items.Length > 0)
     {
         ClearProjectState(project, stateSet);
     }
 }
 protected abstract Task <ImmutableArray <DiagnosticData>?> GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId documentId, AnalysisKind kind, CancellationToken cancellationToken);
Ejemplo n.º 33
0
            protected override async Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                // active file diagnostics:
                if (documentId != null && kind != AnalysisKind.NonLocal && stateSet.TryGetActiveFileState(documentId, out var state))
                {
                    return(state.GetAnalysisData(kind).Items);
                }

                // project diagnostics:
                return(await GetProjectStateDiagnosticsAsync(stateSet, project, documentId, kind, cancellationToken).ConfigureAwait(false));
            }
 private void RaiseDocumentDiagnosticsIfNeeded(
     Document document, StateSet stateSet, AnalysisKind kind, ImmutableArray <DiagnosticData> oldItems, ImmutableArray <DiagnosticData> newItems)
 {
     RaiseDocumentDiagnosticsIfNeeded(document, stateSet, kind, oldItems, newItems, Owner.RaiseDiagnosticsUpdated);
 }
Ejemplo n.º 35
0
            protected override async Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var stateSets = SpecializedCollections.SingletonCollection(stateSet);

                // Here, we don't care what kind of analyzer (StateSet) is given.
                var forceAnalyzerRun = true;
                var compilation      = await CreateCompilationWithAnalyzersAsync(project, stateSets, IncludeSuppressedDiagnostics, cancellationToken).ConfigureAwait(false);

                if (documentId != null)
                {
                    var document = project.Solution.GetDocument(documentId);
                    Contract.ThrowIfNull(document);

                    switch (kind)
                    {
                    case AnalysisKind.Syntax:
                    case AnalysisKind.Semantic:
                        return((await Owner.GetDocumentAnalysisDataAsync(compilation, document, stateSet, kind, cancellationToken).ConfigureAwait(false)).Items);

                    case AnalysisKind.NonLocal:
                        var nonLocalDocumentResult = await Owner.GetProjectAnalysisDataAsync(compilation, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false);

                        var analysisResult = nonLocalDocumentResult.GetResult(stateSet.Analyzer);
                        return(analysisResult.GetDocumentDiagnostics(documentId, AnalysisKind.NonLocal));

                    default:
                        throw ExceptionUtilities.UnexpectedValue(kind);
                    }
                }

                Contract.ThrowIfFalse(kind == AnalysisKind.NonLocal);
                var projectResult = await Owner.GetProjectAnalysisDataAsync(compilation, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false);

                return(projectResult.GetResult(stateSet.Analyzer).GetOtherDiagnostics());
            }
            private async Task <bool> TryGetSyntaxAndSemanticCompilerDiagnosticsAsync(StateSet stateSet, List <DiagnosticData> list, CancellationToken cancellationToken)
            {
                // First, get syntax errors and semantic errors
                var fullResult = true;

                fullResult &= await TryGetDocumentDiagnosticsAsync(stateSet, AnalysisKind.Syntax, GetCompilerSyntaxDiagnosticsAsync, list, cancellationToken).ConfigureAwait(false);

                fullResult &= await TryGetDocumentDiagnosticsAsync(stateSet, AnalysisKind.Semantic, GetCompilerSemanticDiagnosticsAsync, list, cancellationToken).ConfigureAwait(false);

                return(fullResult);
            }
 private void RaiseDocumentDiagnosticsIfNeeded(
     Document document, StateSet stateSet, AnalysisKind kind, ImmutableArray <DiagnosticData> oldItems, ImmutableArray <DiagnosticData> newItems)
 {
     RaiseDocumentDiagnosticsIfNeeded(document, stateSet, kind, oldItems, newItems, AnalyzerService.RaiseDiagnosticsUpdated, forceUpdate: false);
 }
 private void RaiseDocumentDiagnosticsIfNeeded(Document document, StateSet stateSet, AnalysisKind kind, ImmutableArray<DiagnosticData> items)
 {
     RaiseDocumentDiagnosticsIfNeeded(document, stateSet, kind, ImmutableArray<DiagnosticData>.Empty, items);
 }
            protected override async Task <ImmutableArray <DiagnosticData>?> GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var stateSets = SpecializedCollections.SingletonCollection(stateSet);

                // Here, we don't care what kind of analyzer (StateSet) is given.
                // We just create and use AnalyzerDriver with the given analyzer (StateSet).
                var forceAnalyzerRun  = true;
                var analyzerDriverOpt = await Owner._compilationManager.CreateAnalyzerDriverAsync(project, stateSets, IncludeSuppressedDiagnostics, cancellationToken).ConfigureAwait(false);

                if (documentId != null)
                {
                    var document = project.Solution.GetDocument(documentId);
                    Contract.ThrowIfNull(document);

                    switch (kind)
                    {
                    case AnalysisKind.Syntax:
                    case AnalysisKind.Semantic:
                    {
                        var result = await Owner._executor.GetDocumentAnalysisDataAsync(analyzerDriverOpt, document, stateSet, kind, cancellationToken).ConfigureAwait(false);

                        return(result.Items);
                    }

                    case AnalysisKind.NonLocal:
                    {
                        var nonLocalDocumentResult = await Owner._executor.GetProjectAnalysisDataAsync(analyzerDriverOpt, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false);

                        var analysisResult = nonLocalDocumentResult.GetResult(stateSet.Analyzer);
                        return(GetResult(analysisResult, AnalysisKind.NonLocal, documentId));
                    }

                    default:
                        return(Contract.FailWithReturn <ImmutableArray <DiagnosticData>?>("shouldn't reach here"));
                    }
                }

                Contract.ThrowIfFalse(kind == AnalysisKind.NonLocal);
                var projectResult = await Owner._executor.GetProjectAnalysisDataAsync(analyzerDriverOpt, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false);

                return(projectResult.GetResult(stateSet.Analyzer).Others);
            }
            private static async Task <ImmutableArray <DiagnosticData> > GetProjectStateDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken)
            {
                if (!stateSet.TryGetProjectState(project.Id, out var state))
                {
                    // never analyzed this project yet.
                    return(ImmutableArray <DiagnosticData> .Empty);
                }

                if (documentId != null)
                {
                    // file doesn't exist in current solution
                    var document = await project.Solution.GetDocumentAsync(
                        documentId,
                        includeSourceGenerated : project.Solution.Workspace.Services.GetService <IWorkspaceConfigurationService>()?.Options.EnableOpeningSourceGeneratedFiles == true,
                        cancellationToken).ConfigureAwait(false);

                    if (document == null)
                    {
                        return(ImmutableArray <DiagnosticData> .Empty);
                    }

                    var result = await state.GetAnalysisDataAsync(document, avoidLoadingData : false, cancellationToken).ConfigureAwait(false);

                    return(result.GetDocumentDiagnostics(documentId, kind));
                }

                Contract.ThrowIfFalse(kind == AnalysisKind.NonLocal);
                var nonLocalResult = await state.GetProjectAnalysisDataAsync(project, avoidLoadingData : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                return(nonLocalResult.GetOtherDiagnostics());
            }
 private void RaiseDocumentDiagnosticsIfNeeded(Document document, StateSet stateSet, AnalysisKind kind, ImmutableArray <DiagnosticData> items)
 {
     RaiseDocumentDiagnosticsIfNeeded(document, stateSet, kind, ImmutableArray <DiagnosticData> .Empty, items);
 }
        private bool SkipRunningAnalyzer(
            CompilationOptions compilationOptions,
            DiagnosticAnalyzerDriver userDiagnosticDriver,
            bool openedDocument,
            bool skipClosedFileChecks,
            StateSet stateSet)
        {
            if (Owner.IsAnalyzerSuppressed(stateSet.Analyzer, userDiagnosticDriver.Project))
            {
                return true;
            }

            if (skipClosedFileChecks)
            {
                return false;
            }

            if (ShouldRunAnalyzerForClosedFile(compilationOptions, openedDocument, stateSet.Analyzer))
            {
                return false;
            }

            return true;
        }
        private void RaiseProjectDiagnosticsRemoved(StateSet stateSet, ProjectId projectId, IEnumerable <DocumentId> documentIds, Action <DiagnosticsUpdatedArgs> raiseEvents)
        {
            var handleActiveFile = false;

            RaiseProjectDiagnosticsRemoved(stateSet, projectId, documentIds, handleActiveFile, raiseEvents);
        }
        private void RaiseDocumentDiagnosticsUpdatedIfNeeded(
            StateType type, Document document, StateSet stateSet, ImmutableArray<DiagnosticData> existingItems, ImmutableArray<DiagnosticData> newItems)
        {
            var noItems = existingItems.Length == 0 && newItems.Length == 0;
            if (noItems)
            {
                return;
            }

            RaiseDiagnosticsUpdated(type, document.Id, stateSet, new SolutionArgument(document), newItems);
        }
Ejemplo n.º 45
0
 private static object CreateId(StateSet stateSet, ProjectId projectId, AnalysisKind kind)
 => new LiveDiagnosticUpdateArgsId(stateSet.Analyzer, projectId, (int)kind, stateSet.ErrorSourceName);
        private void RaiseProjectDiagnosticsUpdatedIfNeeded(
            Project project, StateSet stateSet, ImmutableArray<DiagnosticData> existingItems, ImmutableArray<DiagnosticData> newItems)
        {
            var noItems = existingItems.Length == 0 && newItems.Length == 0;
            if (noItems)
            {
                return;
            }

            RaiseProjectDiagnosticsRemovedIfNeeded(project, stateSet, existingItems, newItems);
            RaiseProjectDiagnosticsUpdated(project, stateSet, newItems);
        }
 private void RaiseDocumentDiagnosticsIfNeeded(
     Document document, StateSet stateSet, AnalysisKind kind, ImmutableArray<DiagnosticData> oldItems, ImmutableArray<DiagnosticData> newItems)
 {
     RaiseDocumentDiagnosticsIfNeeded(document, stateSet, kind, oldItems, newItems, Owner.RaiseDiagnosticsUpdated);
 }
        private void RaiseProjectDiagnosticsRemovedIfNeeded(
            Project project, StateSet stateSet, ImmutableArray<DiagnosticData> existingItems, ImmutableArray<DiagnosticData> newItems)
        {
            if (existingItems.Length == 0)
            {
                return;
            }

            var removedItems = existingItems.GroupBy(d => d.DocumentId).Select(g => g.Key).Except(newItems.GroupBy(d => d.DocumentId).Select(g => g.Key));
            foreach (var documentId in removedItems)
            {
                if (documentId == null)
                {
                    RaiseDiagnosticsUpdated(StateType.Project, project.Id, stateSet, new SolutionArgument(project), ImmutableArray<DiagnosticData>.Empty);
                    continue;
                }

                var document = project.GetDocument(documentId);
                var argument = documentId == null ? new SolutionArgument(null, documentId.ProjectId, documentId) : new SolutionArgument(document);
                RaiseDiagnosticsUpdated(StateType.Project, documentId, stateSet, argument, ImmutableArray<DiagnosticData>.Empty);
            }
        }
        private void RaiseDocumentDiagnosticsIfNeeded(
            Document document, StateSet stateSet, AnalysisKind kind,
            ImmutableArray<DiagnosticData> oldItems, ImmutableArray<DiagnosticData> newItems,
            Action<DiagnosticsUpdatedArgs> raiseEvents)
        {
            if (oldItems.IsEmpty && newItems.IsEmpty)
            {
                // there is nothing to update
                return;
            }

            RaiseDiagnosticsCreated(document, stateSet, kind, newItems, raiseEvents);
        }
        private void RaiseProjectDiagnosticsUpdated(Project project, StateSet stateSet, ImmutableArray<DiagnosticData> diagnostics)
        {
            var group = diagnostics.GroupBy(d => d.DocumentId);
            foreach (var kv in group)
            {
                if (kv.Key == null)
                {
                    RaiseDiagnosticsUpdated(StateType.Project, project.Id, stateSet, new SolutionArgument(project), kv.ToImmutableArrayOrEmpty());
                    continue;
                }

                RaiseDiagnosticsUpdated(StateType.Project, kv.Key, stateSet, new SolutionArgument(project.GetDocument(kv.Key)), kv.ToImmutableArrayOrEmpty());
            }
        }
 private void RaiseProjectDiagnosticsRemoved(StateSet stateSet, ProjectId projectId, IEnumerable<DocumentId> documentIds, Action<DiagnosticsUpdatedArgs> raiseEvents)
 {
     var handleActiveFile = false;
     RaiseProjectDiagnosticsRemoved(stateSet, projectId, documentIds, handleActiveFile, raiseEvents);
 }
        private void RaiseDiagnosticsUpdated(
            StateType type, object key, StateSet stateSet, SolutionArgument solution, ImmutableArray<DiagnosticData> diagnostics)
        {
            if (Owner == null)
            {
                return;
            }

            // get right arg id for the given analyzer
            var id = stateSet.ErrorSourceName != null ?
                (object)new HostAnalyzerKey(stateSet.Analyzer, type, key, stateSet.ErrorSourceName) : (object)new ArgumentKey(stateSet.Analyzer, type, key);

            Owner.RaiseDiagnosticsUpdated(this,
                new DiagnosticsUpdatedArgs(id, Workspace, solution.Solution, solution.ProjectId, solution.DocumentId, diagnostics));
        }
Ejemplo n.º 53
0
 public StateDown(NavMeshAgent _agent, Vector3 _point, Transform _transform, ref StateSet _set)
 {
     set = _set;
     transform = _transform;
     agent = _agent;
     point = _point;
     //Debug.Log(point);
 }
            public async Task <AnalysisData> GetDocumentAnalysisDataAsync(DiagnosticAnalyzerDriver analyzerDriver, StateSet stateSet, VersionArgument versions)
            {
                try
                {
                    var document          = analyzerDriver.Document;
                    var cancellationToken = analyzerDriver.CancellationToken;

                    var state        = stateSet.GetState(StateType.Document);
                    var existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);

                    if (CheckSemanticVersions(document, existingData, versions))
                    {
                        return(existingData);
                    }

                    var diagnosticData = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);

                    return(new AnalysisData(versions.TextVersion, versions.DataVersion, GetExistingItems(existingData), diagnosticData.AsImmutableOrEmpty()));
                }
                catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
        private void ClearDocumentState(Document document, StateSet stateSet, StateType type, bool raiseEvent)
        {
            var state = stateSet.GetState(type);

            // remove saved info
            state.Remove(document.Id);

            if (raiseEvent)
            {
                // raise diagnostic updated event
                var documentId = document.Id;
                var solutionArgs = new SolutionArgument(document);

                RaiseDiagnosticsUpdated(type, document.Id, stateSet, solutionArgs, ImmutableArray<DiagnosticData>.Empty);
            }
        }
 protected abstract Task<AnalysisData> GetDiagnosticAnalysisDataAsync(Solution solution, DiagnosticAnalyzerDriver analyzerDriver, StateSet stateSet, StateType stateType, VersionArgument versions);
 public ProjectState(StateSet owner, ProjectId projectId)
 {
     _owner      = owner;
     _lastResult = DiagnosticAnalysisResult.CreateInitialResult(projectId);
 }
        private void ClearProjectState(Project project, StateSet stateSet)
        {
            var state = stateSet.GetState(StateType.Project);

            // remove saved cache
            state.Remove(project.Id);

            // raise diagnostic updated event
            var solutionArgs = new SolutionArgument(project);
            RaiseDiagnosticsUpdated(StateType.Project, project.Id, stateSet, solutionArgs, ImmutableArray<DiagnosticData>.Empty);
        }
 protected override Task<AnalysisData> GetDiagnosticAnalysisDataAsync(
     Solution solution, DiagnosticAnalyzerDriver analyzerDriver, StateSet stateSet, StateType stateType, VersionArgument versions)
 {
     switch (stateType)
     {
         case StateType.Syntax:
             return this.AnalyzerExecutor.GetSyntaxAnalysisDataAsync(analyzerDriver, stateSet, versions);
         case StateType.Document:
             return this.AnalyzerExecutor.GetDocumentAnalysisDataAsync(analyzerDriver, stateSet, versions);
         case StateType.Project:
             return this.AnalyzerExecutor.GetProjectAnalysisDataAsync(analyzerDriver, stateSet, versions);
         default:
             return Contract.FailWithReturn<Task<AnalysisData>>("Can't reach here");
     }
 }
 private async Task ClearExistingDiagnostics(Document document, StateSet stateSet, StateType type, CancellationToken cancellationToken)
 {
     var state = stateSet.GetState(type);
     var existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);
     if (existingData?.Items.Length > 0)
     {
         ClearDocumentState(document, stateSet, type, raiseEvent: true);
     }
 }