Exemplo n.º 1
0
 /// <summary>
 /// Gets the most recently parsed document.
 /// </summary>
 /// <param name="mostRecentDocument">The most recent fully-parsed document for the buffer.</param>
 /// <returns>The task that was used to generate the document.</returns>
 public Task<UvssTextParserResult> GetMostRecent(out UvssTextParserResult mostRecentDocument)
 {
     lock (syncObject)
     {
         mostRecentDocument = this.mostRecentDocument;
         return taskComplete;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the most recently parsed document.
 /// </summary>
 /// <param name="mostRecentDocument">The most recent fully-parsed document for the buffer.</param>
 /// <returns>The task that was used to generate the document.</returns>
 public Task <UvssTextParserResult> GetMostRecent(out UvssTextParserResult mostRecentDocument)
 {
     lock (syncObject)
     {
         mostRecentDocument = this.mostRecentDocument;
         return(taskComplete);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Visits the specified UVSS document and returns a list of classification spans that
        /// intersect with the specified span.
        /// </summary>
        /// <param name="document">The document to visit.</param>
        /// <param name="span">The span for which to retrieve classification spans.</param>
        /// <returns>The classification spans that intersect with the specified span.</returns>
        public IList<ClassificationSpan> VisitDocument(UvssTextParserResult result, SnapshotSpan span)
        {
            if (result.Document == null)
                return null;

			span = span.TranslateTo(result.Snapshot, SpanTrackingMode.EdgeExclusive);
            
            var results = new List<ClassificationSpan>();
            var visitor = new UvssClassifierVisitor(registry, (start, width, type, kind) =>
            {
                var nodeSpan = new SnapshotSpan(span.Snapshot, start, width);
                if (nodeSpan.IntersectsWith(span))
                    results.Add(new ClassificationSpan(nodeSpan, type));
            });
            visitor.Visit(result.Document);
            
            return results;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets a task which produces a UVSS document for the specified text snapshot.
        /// </summary>
        /// <param name="snapshot">The snapshot for which to return a task.</param>
        /// <param name="mostRecentDocument">The most recent fully-parsed document for the buffer.</param>
        /// <returns>The task that was retrieved for the specified snapshot.</returns>
        public Task<UvssTextParserResult> GetParseTask(ITextSnapshot snapshot, out UvssTextParserResult mostRecentDocument)
        {
            lock (syncObject)
            {
                var requestedVersion = snapshot.Version;

                if (versionComplete != null && versionComplete.VersionNumber >= requestedVersion.VersionNumber)
                {
                    mostRecentDocument = this.mostRecentDocument;
                    return taskComplete;
                }

                if (versionProcessing != null && versionProcessing.VersionNumber >= requestedVersion.VersionNumber)
                {
                    mostRecentDocument = this.mostRecentDocument;
                    return taskProcessing;
                }

                if (taskQueued != null)
                {
                    mostRecentDocument = this.mostRecentDocument;
                    return taskQueued;
                }
            }

            var task = default(Task<UvssTextParserResult>);
            task = new Task<UvssTextParserResult>(() =>
            {
                ITextVersion version;
                lock (syncObject)
                {
                    version = buffer.CurrentSnapshot.Version;
                    versionProcessing = version;
                }

                var currentSnapshot = buffer.CurrentSnapshot;
                var source = currentSnapshot.GetText();
                var document = UvssParser.Parse(source);
                var result = new UvssTextParserResult(currentSnapshot, document);

                lock (syncObject)
                {
                    this.mostRecentDocument = result;

                    versionComplete = version;
                    versionProcessing = null;

                    taskComplete = task;
                    taskProcessing = null;

                    if (taskQueued != null)
                    {
                        taskProcessing = taskQueued;
                        taskQueued = null;
                        taskProcessing.Start();
                    }
                }

                RaiseDocumentParsed(new UvssTextParserEventArgs(result));
                return result;
            });

            lock (syncObject)
            {
                if (taskProcessing == null)
                {
                    taskProcessing = task;
                    taskProcessing.Start();
                }
                else
                {
                    taskQueued = new Task<UvssTextParserResult>(() =>
                    {
                        Task.Delay(QueuedTaskDelay).Wait();
                        task.Start();
                        return task.Result;
                    });
                }
            }

            mostRecentDocument = this.mostRecentDocument;
            return task;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Called when a UVSS document is generated by the parser service.
        /// </summary>
        private void OnDocumentGenerated(UvssTextParserResult result)
        {
            lock (errors)
            {
                errors.Clear();

                if (result.Document != null)
                {
                    var diagnostics = result.Document.GetDiagnostics().Where(x => x.Severity == DiagnosticSeverity.Error).ToList();
                    var diagnosticErrors = diagnostics.Select(x =>
                    {
                        var errorSpan = new SnapshotSpan(result.Snapshot, x.Location.Start, x.Location.Length);
                        return new Error(textDocument.FilePath, errorSpan, x);
                    });

                    errors.AddRange(diagnosticErrors);
                }

                errorsDirty = true;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets a task which produces a UVSS document for the specified text snapshot.
        /// </summary>
        /// <param name="snapshot">The snapshot for which to return a task.</param>
        /// <param name="mostRecentDocument">The most recent fully-parsed document for the buffer.</param>
        /// <returns>The task that was retrieved for the specified snapshot.</returns>
        public Task <UvssTextParserResult> GetParseTask(ITextSnapshot snapshot, out UvssTextParserResult mostRecentDocument)
        {
            lock (syncObject)
            {
                var requestedVersion = snapshot.Version;

                if (versionComplete != null && versionComplete.VersionNumber >= requestedVersion.VersionNumber)
                {
                    mostRecentDocument = this.mostRecentDocument;
                    return(taskComplete);
                }

                if (versionProcessing != null && versionProcessing.VersionNumber >= requestedVersion.VersionNumber)
                {
                    mostRecentDocument = this.mostRecentDocument;
                    return(taskProcessing);
                }

                if (taskQueued != null)
                {
                    mostRecentDocument = this.mostRecentDocument;
                    return(taskQueued);
                }
            }

            var task = default(Task <UvssTextParserResult>);

            task = new Task <UvssTextParserResult>(() =>
            {
                ITextVersion version;
                lock (syncObject)
                {
                    version           = buffer.CurrentSnapshot.Version;
                    versionProcessing = version;
                }

                var currentSnapshot = buffer.CurrentSnapshot;
                var source          = currentSnapshot.GetText();
                var document        = UvssParser.Parse(source);
                var result          = new UvssTextParserResult(currentSnapshot, document);

                lock (syncObject)
                {
                    this.mostRecentDocument = result;

                    versionComplete   = version;
                    versionProcessing = null;

                    taskComplete   = task;
                    taskProcessing = null;

                    if (taskQueued != null)
                    {
                        taskProcessing = taskQueued;
                        taskQueued     = null;
                        taskProcessing.Start();
                    }
                }

                RaiseDocumentParsed(new UvssTextParserEventArgs(result));
                return(result);
            });

            lock (syncObject)
            {
                if (taskProcessing == null)
                {
                    taskProcessing = task;
                    taskProcessing.Start();
                }
                else
                {
                    taskQueued = new Task <UvssTextParserResult>(() =>
                    {
                        Task.Delay(QueuedTaskDelay).Wait();
                        task.Start();
                        return(task.Result);
                    });
                }
            }

            mostRecentDocument = this.mostRecentDocument;
            return(task);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UvssTextParserEventArgs"/> class.
 /// </summary>
 /// <param name="result">The result of the parsing operation.</param>
 public UvssTextParserEventArgs(UvssTextParserResult result)
 {
     this.Result = result;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UvssTextParserEventArgs"/> class.
 /// </summary>
 /// <param name="result">The result of the parsing operation.</param>
 public UvssTextParserEventArgs(UvssTextParserResult result)
 {
     this.Result = result;
 }