Пример #1
0
        DocumentChangedEventArgs ComputeChanges(ISassStylesheet previous, ISassStylesheet current, ITextSnapshot snapshot, SingleTextChange change)
        {
            if (previous == null)
                return new DocumentChangedEventArgs { Stylesheet = current, ChangeStart = 0, ChangeEnd = snapshot.Length };

            int start = 0;
            int end = Math.Min(change.Position + change.InsertedLength, snapshot.Length);

            // we need to scan both trees until we find where they start lining up again
            var offset = change.InsertedLength + (-1 * change.DeletedLength);
            var original = previous.Children.FindItemContainingPosition(change.Position - change.DeletedLength) ?? previous as Stylesheet;
            var updated = current.Children.FindItemContainingPosition(change.Position + change.InsertedLength) ?? current as Stylesheet;

            if (original != null && updated != null)
                start = updated.Start;

            while (true)
            {
                if (original == null || updated == null)
                    break;

                // update our positions
                start = Math.Min(start, updated.Start);
                end = Math.Max(end, updated.End);

                if (original.GetType() == updated.GetType())
                {
                    // there are two types of changes (adding characters or removing characters)
                    // if we added characters then we'll need to adjust end characters
                    // if we deleted characters then we'll need to offset starting characters OR ending characters

                    // checking for length being extended by adding characters
                    if (original.Start == updated.Start && (original.End + change.InsertedLength) == updated.End)
                    {
                        end = updated.End;
                        break;
                    }
                    // checking for length being shortened by deleting characters
                    else if (original.Start == updated.Start && (original.End - change.DeletedLength) == updated.End)
                    {
                        break;
                    }
                    // checking for removal of nodes?
                    else if (original.Start == (updated.Start - change.DeletedLength) && (original.End - change.DeletedLength) == updated.End)
                    {
                        break;
                    }
                }

                original = original.InOrderSuccessor();
                updated = updated.InOrderSuccessor();
            }

            return new DocumentChangedEventArgs
            {
                Stylesheet = current,
                ChangeStart = Math.Min(start, change.Position),
                ChangeEnd = Math.Max(end, change.Position + change.InsertedLength)
            };
        }
Пример #2
0
        private ICompletionContext CreateCompletionContext(ISassStylesheet stylesheet, int position, ITextSnapshot snapshot)
        {
            ParseItem current = stylesheet as Stylesheet;

            if (position >= 0)
            {
                var previousCharacterIndex = FindPreceedingCharacter(position-1, snapshot);
                if (previousCharacterIndex != position)
                    current = stylesheet.Children.FindItemContainingPosition(previousCharacterIndex);

                current = current ?? stylesheet.Children.FindItemContainingPosition(position);
                if (current is TokenItem)
                    current = current.Parent;

                if (current != null && !IsUnclosed(current) && previousCharacterIndex != position)
                {
                    current = stylesheet.Children.FindItemContainingPosition(position);
                    if (current is TokenItem)
                        current = current.Parent;
                }
            }

            current = current ?? stylesheet as Stylesheet;

            return new CompletionContext
            {
                Document = Editor.Document,
                Current = current,
                //Predecessor = predecessor,
                Position = position,
                Cache = Cache,
                DocumentTextProvider = new SnapshotTextProvider(snapshot)
            };
        }
Пример #3
0
        public void Update(ISassStylesheet stylesheet, ITextProvider text)
        {
            var container = new StylesheetContainer(IntellisenseManager);
            foreach (var item in stylesheet.Children)
                container.Add(item, text);

            Container = container;
        }
Пример #4
0
        private void OnStylesheetChanged(ISassStylesheet previous, ISassStylesheet current)
        {
            var handler = StylesheetChanged;

            if (handler != null)
            {
                handler(this, new StylesheetChangedEventArgs(previous, current));
            }
        }
Пример #5
0
        public void Update(ISassStylesheet stylesheet, ITextProvider text)
        {
            var container = new StylesheetContainer(IntellisenseManager);

            foreach (var item in stylesheet.Children)
            {
                container.Add(item, text);
            }

            Container = container;
        }
Пример #6
0
        public ISassStylesheet Update(ISassStylesheet stylesheet)
        {
            lock (locker)
            {
                var previous = Stylesheet;
                Stylesheet = stylesheet;
                if (Stylesheet != null)
                    Stylesheet.Owner = this;

                //DumpTree(stylesheet.Children, 0);
                OnStylesheetChanged(previous, stylesheet);
                if (previous != null)
                    previous.Owner = null;

                return previous;
            }
        }
Пример #7
0
        void ProcessRequests()
        {
            while (!ShutdownToken.IsCancellationRequested)
            {
                try
                {
                    BackgroundParseRequest request;
                    if (Requests.TryTake(out request, -1, ShutdownToken))
                    {
                        try
                        {
                            var source = request.Document.Source;
                            source.Refresh();
                            if (source.Exists)
                            {
                                ISassStylesheet stylesheet  = null;
                                var             textManager = new FileTextManager(source);
                                using (var scope = textManager.Open())
                                {
                                    var parser = ParserFactory.Create();
                                    stylesheet = parser.Parse(new FileParsingRequest(scope.Text, request.Document));
                                }

                                if (stylesheet != null)
                                {
                                    request.Document.Update(stylesheet);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(ex, "Failed to process background document parse request.");
                        }
                    }
                }
                catch (OperationCanceledException)
                {
                    // ignore
                    return;
                }
            }
        }
Пример #8
0
        public ISassStylesheet Update(ISassStylesheet stylesheet)
        {
            lock (locker)
            {
                var previous = Stylesheet;
                Stylesheet = stylesheet;
                if (Stylesheet != null)
                {
                    Stylesheet.Owner = this;
                }

                //DumpTree(stylesheet.Children, 0);
                OnStylesheetChanged(previous, stylesheet);
                if (previous != null)
                {
                    previous.Owner = null;
                }

                return(previous);
            }
        }
Пример #9
0
        private ICompletionContext CreateCompletionContext(ISassStylesheet stylesheet, int position, ITextSnapshot snapshot)
        {
            ParseItem current = stylesheet as Stylesheet;

            if (position >= 0)
            {
                var previousCharacterIndex = FindPreceedingCharacter(position - 1, snapshot);
                if (previousCharacterIndex != position)
                {
                    current = stylesheet.Children.FindItemContainingPosition(previousCharacterIndex);
                }

                current = current ?? stylesheet.Children.FindItemContainingPosition(position);
                if (current is TokenItem)
                {
                    current = current.Parent;
                }

                if (current != null && !IsUnclosed(current) && previousCharacterIndex != position)
                {
                    current = stylesheet.Children.FindItemContainingPosition(position);
                    if (current is TokenItem)
                    {
                        current = current.Parent;
                    }
                }
            }

            current = current ?? stylesheet as Stylesheet;

            return(new CompletionContext
            {
                Document = Editor.Document,
                Current = current,
                //Predecessor = predecessor,
                Position = position,
                Cache = Cache,
                DocumentTextProvider = new SnapshotTextProvider(snapshot)
            });
        }
Пример #10
0
 private void OnStylesheetChanged(ISassStylesheet previous, ISassStylesheet current)
 {
     var handler = StylesheetChanged;
     if (handler != null)
         handler(this, new StylesheetChangedEventArgs(previous, current));
 }
Пример #11
0
 public StylesheetChangedEventArgs(ISassStylesheet previous, ISassStylesheet current)
 {
     Previous = previous;
     Current  = current;
 }
Пример #12
0
        DocumentChangedEventArgs ComputeChanges(ISassStylesheet previous, ISassStylesheet current, ITextSnapshot snapshot, SingleTextChange change)
        {
            if (previous == null)
            {
                return new DocumentChangedEventArgs {
                           Stylesheet = current, ChangeStart = 0, ChangeEnd = snapshot.Length
                }
            }
            ;

            int start = 0;
            int end   = Math.Min(change.Position + change.InsertedLength, snapshot.Length);

            // we need to scan both trees until we find where they start lining up again
            var offset   = change.InsertedLength + (-1 * change.DeletedLength);
            var original = previous.Children.FindItemContainingPosition(change.Position - change.DeletedLength) ?? previous as Stylesheet;
            var updated  = current.Children.FindItemContainingPosition(change.Position + change.InsertedLength) ?? current as Stylesheet;

            if (original != null && updated != null)
            {
                start = updated.Start;
            }

            while (true)
            {
                if (original == null || updated == null)
                {
                    break;
                }

                // update our positions
                start = Math.Min(start, updated.Start);
                end   = Math.Max(end, updated.End);

                if (original.GetType() == updated.GetType())
                {
                    // there are two types of changes (adding characters or removing characters)
                    // if we added characters then we'll need to adjust end characters
                    // if we deleted characters then we'll need to offset starting characters OR ending characters

                    // checking for length being extended by adding characters
                    if (original.Start == updated.Start && (original.End + change.InsertedLength) == updated.End)
                    {
                        end = updated.End;
                        break;
                    }
                    // checking for length being shortened by deleting characters
                    else if (original.Start == updated.Start && (original.End - change.DeletedLength) == updated.End)
                    {
                        break;
                    }
                    // checking for removal of nodes?
                    else if (original.Start == (updated.Start - change.DeletedLength) && (original.End - change.DeletedLength) == updated.End)
                    {
                        break;
                    }
                }

                original = original.InOrderSuccessor();
                updated  = updated.InOrderSuccessor();
            }

            return(new DocumentChangedEventArgs
            {
                Stylesheet = current,
                ChangeStart = Math.Min(start, change.Position),
                ChangeEnd = Math.Max(end, change.Position + change.InsertedLength)
            });
        }