public void UpdateParseDiagnostics(VersionCookie vc, Uri documentUri)
        {
            List <PublishDiagnosticsEventArgs> diags = null;

            lock (_lock) {
                var last = _parseBufferDiagnostics;

                foreach (var kv in vc.GetAllParts(documentUri))
                {
                    var part = _server.ProjectFiles.GetPart(kv.Key);
                    if (!last.TryGetValue(part, out var lastVersion) || lastVersion.Version < kv.Value.Version || _ignoreDiagnosticsVersion)
                    {
                        last[part] = kv.Value;
                        diags      = diags ?? new List <PublishDiagnosticsEventArgs>();
                        diags.Add(new PublishDiagnosticsEventArgs {
                            uri         = kv.Key,
                            diagnostics = kv.Value.Diagnostics,
                            _version    = kv.Value.Version
                        });
                    }
                }
                _ignoreDiagnosticsVersion     = false;
                _lastReportedParseDiagnostics = diags ?? _lastReportedParseDiagnostics;

                if (diags != null)
                {
                    PublishDiagnostics(diags);
                }
            }
        }
Beispiel #2
0
        private void OnDocumentChangeProcessingComplete(IDocument doc, VersionCookie vc, bool enqueueForAnalysis, AnalysisPriority priority, IDisposable disposeWhenEnqueued)
        {
            try {
                if (vc != null)
                {
                    foreach (var kv in vc.GetAllParts(doc.DocumentUri))
                    {
                        ParseComplete(kv.Key, kv.Value.Version);
                    }
                }
                else
                {
                    ParseComplete(doc.DocumentUri, 0);
                }

                if (doc is IAnalyzable analyzable && enqueueForAnalysis)
                {
                    TraceMessage($"Enqueing document {doc.DocumentUri} for analysis");
                    _queue.Enqueue(analyzable, priority);
                }

                disposeWhenEnqueued?.Dispose();
                disposeWhenEnqueued = null;
                var openedFile = _openFiles.GetDocument(doc.DocumentUri);
                if (vc != null)
                {
                    var reported = openedFile.LastReportedDiagnostics;
                    lock (reported) {
                        foreach (var kv in vc.GetAllParts(doc.DocumentUri))
                        {
                            var part = _projectFiles.GetPart(kv.Key);
                            if (!reported.TryGetValue(part, out var lastVersion) || lastVersion.Version < kv.Value.Version)
                            {
                                reported[part] = kv.Value;
                                PublishDiagnostics(new PublishDiagnosticsEventArgs {
                                    uri         = kv.Key,
                                    diagnostics = kv.Value.Diagnostics,
                                    _version    = kv.Value.Version
                                });
                            }
                        }
                    }
                }
            } catch (BadSourceException) {
            } catch (OperationCanceledException ex) {
                LogMessage(MessageType.Warning, $"Parsing {doc.DocumentUri} cancelled");
                TraceMessage($"{ex}");
            } catch (Exception ex) {
                LogMessage(MessageType.Error, ex.ToString());
            } finally {
                disposeWhenEnqueued?.Dispose();
            }
        }
Beispiel #3
0
        private IPythonParse ParsePythonEntry(IPythonProjectEntry entry, PythonLanguageVersion languageVersion, VersionCookie lastParseCookie)
        {
            PythonAst tree;
            var       doc     = (IDocument)entry;
            var       buffers = new SortedDictionary <int, BufferVersion>();

            foreach (var part in doc.DocumentParts.Reverse())
            {
                using (var r = doc.ReadDocumentBytes(part, out int version)) {
                    if (r == null)
                    {
                        continue;
                    }

                    if (version >= 0 && lastParseCookie != null && lastParseCookie.Versions.TryGetValue(part, out var lastParse) && lastParse.Version >= version)
                    {
                        buffers[part] = lastParse;
                        continue;
                    }

                    buffers[part] = ParsePython(r, entry, languageVersion, version);
                }
            }

            if (!buffers.Any())
            {
                // If the document is a real file, we should have been able to parse.
                if (entry.DocumentUri.IsFile)
                {
                    throw new FileNotFoundException("failed to parse file {0}".FormatInvariant(entry.DocumentUri.AbsoluteUri), entry.FilePath);
                }
                // Otherwise, it is likely just empty for now, so no need to cause a fuss
                return(null);
            }

            var cookie = new VersionCookie(buffers);

            if (buffers.Count == 1)
            {
                tree = buffers.First().Value.Ast;
            }
            else
            {
                tree = new PythonAst(buffers.Values.Select(v => v.Ast));
            }

            return(new StaticPythonParse(tree, cookie));
        }
Beispiel #4
0
        private void OnDocumentChangeProcessingComplete(IDocument doc, VersionCookie vc, bool enqueueForAnalysis, AnalysisPriority priority, IDisposable disposeWhenEnqueued)
        {
            ThrowIfDisposed();
            try {
                if (vc != null)
                {
                    foreach (var kv in vc.GetAllParts(doc.DocumentUri))
                    {
                        ParseComplete(kv.Key, kv.Value.Version);
                    }
                }
                else
                {
                    ParseComplete(doc.DocumentUri, 0);
                }

                if (doc is IAnalyzable analyzable && enqueueForAnalysis)
                {
                    TraceMessage($"Enqueing document {doc.DocumentUri} for analysis");
                    _queue.Enqueue(analyzable, priority);
                }

                disposeWhenEnqueued?.Dispose();
                disposeWhenEnqueued = null;
                if (vc != null)
                {
                    _editorFiles.GetDocument(doc.DocumentUri).UpdateParseDiagnostics(vc, doc.DocumentUri);
                }
            } catch (BadSourceException) {
            } catch (OperationCanceledException ex) {
                LogMessage(MessageType.Warning, $"Parsing {doc.DocumentUri} cancelled");
                TraceMessage($"{ex}");
            } catch (Exception ex) {
                LogMessage(MessageType.Error, ex.ToString());
            } finally {
                disposeWhenEnqueued?.Dispose();
            }
        }