Пример #1
0
        private void ProjectEntry_OnNewAnalysis(object sender, EventArgs e)
        {
            if (sender is IPythonProjectEntry entry)
            {
                TraceMessage($"Received new analysis for {entry.DocumentUri}");
                var version = 0;
                var parse   = entry.GetCurrentParse();
                if (parse?.Cookie is VersionCookie vc && vc.Versions.Count > 0)
                {
                    foreach (var kv in vc.GetAllParts(entry.DocumentUri))
                    {
                        AnalysisComplete(kv.Key, kv.Value.Version);
                        if (kv.Value.Version > version)
                        {
                            version = kv.Value.Version;
                        }
                    }
                }
                else
                {
                    AnalysisComplete(entry.DocumentUri, 0);
                }

                var diags = _analyzer.GetDiagnostics(entry);
                if (!diags.Any())
                {
                    return;
                }

                if (entry is IDocument doc)
                {
                    var reported = _openFiles.GetDocument(doc.DocumentUri).LastReportedDiagnostics;
                    lock (reported) {
                        if (reported.TryGetValue(0, out var lastVersion))
                        {
                            diags = diags.Concat(lastVersion.Diagnostics).ToArray();
                        }
                    }
                }

                PublishDiagnostics(new PublishDiagnosticsEventArgs {
                    diagnostics = diags,
                    uri         = entry.DocumentUri,
                    _version    = version
                });
            }