コード例 #1
0
        void UpdateWordAdornments()
        {
            SnapshotPoint       currentRequest = RequestedPoint;
            List <SnapshotSpan> wordSpans      = new List <SnapshotSpan>();
            //Find all words in the buffer like the one the caret is on
            TextExtent word      = TextStructureNavigator.GetExtentOfWord(currentRequest);
            bool       foundWord = true;

            //If we've selected something not worth highlighting, we might have missed a "word" by a little bit
            if (!WordExtentIsValid(currentRequest, word))
            {
                //Before we retry, make sure it is worthwhile
                if (word.Span.Start != currentRequest ||
                    currentRequest == currentRequest.GetContainingLine().Start ||
                    char.IsWhiteSpace((currentRequest - 1).GetChar()))
                {
                    foundWord = false;
                }
                else
                {
                    // Try again, one character previous.
                    //If the caret is at the end of a word, pick up the word.
                    word = TextStructureNavigator.GetExtentOfWord(currentRequest - 1);

                    //If the word still isn't valid, we're done
                    if (!WordExtentIsValid(currentRequest, word))
                    {
                        foundWord = false;
                    }
                }
            }

            if (!foundWord)
            {
                //If we couldn't find a word, clear out the existing markers
                SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(), null);
                return;
            }

            SnapshotSpan currentWord = word.Span;

            //If this is the current word, and the caret moved within a word, we're done.
            if (CurrentWord.HasValue && currentWord == CurrentWord)
            {
                return;
            }

            //Find the new spans
            FindData findData = new FindData(currentWord.GetText(), currentWord.Snapshot);

            findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;

            wordSpans.AddRange(TextSearchService.FindAll(findData));

            //If another change hasn't happened, do a real update
            if (currentRequest == RequestedPoint)
            {
                SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(wordSpans), currentWord);
            }
        }
コード例 #2
0
        void UpdateWordAdornments()
        {
            List <SnapshotSpan> wordSpans   = new List <SnapshotSpan>();
            SnapshotSpan        currentWord = this.View.Selection.StreamSelectionSpan.SnapshotSpan;

            if (CurrentWord.HasValue && currentWord == CurrentWord)
            {
                return;
            }

            // Find the new spans
            FindData findData = new FindData(currentWord.GetText(), currentWord.Snapshot);

            bool ctrlDown = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);

            if (ctrlDown)
            {
                findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;
            }
            else
            {
                findData.FindOptions = FindOptions.WholeWord;
            }

            wordSpans.AddRange(TextSearchService.FindAll(findData));

            SynchronousUpdate(new NormalizedSnapshotSpanCollection(wordSpans), currentWord);
        }
コード例 #3
0
        public IEnumerable <SnapshotSpan> SearchText(string text)
        {
            FindData findData = new FindData(text, this.View.TextSnapshot);

            findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;
            return(TextSearchService.FindAll(findData));
        }
コード例 #4
0
        protected virtual IEnumerable <SnapshotSpan> FindAllMatches(SnapshotSpan currentWord)
        {
            var findData = new FindData(currentWord.GetText(), currentWord.Snapshot);

            findData.FindOptions = FindOptions.WholeWord; // Not case sensitive as PowerShell isn't.
            return(TextSearchService.FindAll(findData));
        }
コード例 #5
0
        private void UpdateWordAdornments()
        {
            //Find the new spans
            try
            {
                var store           = DocumentScriptCosters.GetInstance().GetCoster();
                var yellowWordSpans = new List <SnapshotSpan>();
                var redWordSpans    = new List <SnapshotSpan>();

                if (null != store)
                {
                    var statements = store.GetCosts();
                    if (statements != null)
                    {
                        foreach (var s in statements)
                        {
                            if (s.Band == CostBand.Medium)
                            {
                                var findData = new FindData(s.Text, RequestedPoint.Snapshot);
                                findData.FindOptions = FindOptions.Multiline | FindOptions.Wrap;
                                yellowWordSpans.AddRange(TextSearchService.FindAll(findData));
                            }

                            if (s.Band == CostBand.High)
                            {
                                var findData = new FindData(s.Text, RequestedPoint.Snapshot);
                                findData.FindOptions = FindOptions.Multiline | FindOptions.Wrap;
                                redWordSpans.AddRange(TextSearchService.FindAll(findData));
                            }
                        }
                    }
                }

                var currentRequest = RequestedPoint;
                var word           = TextStructureNavigator.GetExtentOfWord(currentRequest);
                var currentWord    = word.Span;


                //If another change hasn't happened, do a real update
                if (currentRequest == RequestedPoint)
                {
                    SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(yellowWordSpans),
                                      new NormalizedSnapshotSpanCollection(redWordSpans), currentWord);
                }
            }

            catch (Exception e)
            {
                MessageBox.Show("2 - e : " + e.Message + " \r\n " + e.StackTrace);
            }
        }
コード例 #6
0
        IEnumerable <SnapshotSpan> FindAll(SnapshotSpan currentWord)
        {
            // Search on the *wrong* snapshot, on purpose, and map the results down to the correct snapshot
            var findData = new FindData(currentWord.GetText(), View.TextSnapshot);

            findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;

            var snapshot = currentWord.Snapshot;

            return(TextSearchService.FindAll(findData)
                   .Select(s => View.BufferGraph.MapDownToSnapshot(s, SpanTrackingMode.EdgeExclusive, snapshot))
                   .Where(spans => spans.Any())
                   .Select(spans => new SnapshotSpan(spans[0].Start, spans[spans.Count - 1].End)));
        }
コード例 #7
0
        public void UpdateAtPosition(int position, int length)
        {
            if (position < 0 || position + length > this.View.TextSnapshot.Length)
            {
                return;
            }

            var currentWord = new SnapshotSpan(this.View.TextSnapshot, position, length);

            if (CurrentWord.HasValue)
            {
                if (CurrentWord == currentWord)
                {
                    return;
                }
                if (CurrentWord.Value.Snapshot == currentWord.Snapshot && CurrentWord.Value.GetText() == currentWord.GetText())
                {
                    return;
                }
            }

            RequestedPoint = currentWord.Start;
            var currentRequest = RequestedPoint;

            FindData findData = new FindData(currentWord.GetText(), currentWord.Snapshot);

            findData.FindOptions = FindOptions.MatchCase;

            var wordSpans = new List <SnapshotSpan>();

            wordSpans.AddRange(TextSearchService.FindAll(findData));

            //If another change hasn't happened, do a real update
            if (currentRequest == RequestedPoint)
            {
                SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(wordSpans), currentWord);
            }
        }
コード例 #8
0
        private void UpdateSnippetReplacementAdornments(object threadContext)
        {
            try
            {
                var delimiter = !View.Properties.ContainsProperty(ReplacementDelimiter) ? null : View.Properties[ReplacementDelimiter] as string;
                delimiter = string.IsNullOrEmpty(delimiter) ? "$" : delimiter;

                var validReplacementString = SnippetRegexPatterns.BuildValidReplacementString(delimiter);

                var wordSpans   = new List <SnapshotSpan>();
                var findOptions = FindOptions.UseRegularExpressions;
                var findData    = new FindData(validReplacementString, View.TextBuffer.CurrentSnapshot, findOptions, null);
                wordSpans.AddRange(TextSearchService.FindAll(findData));

                SynchronousUpdate(new NormalizedSnapshotSpanCollection(wordSpans));
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
            }
        }
コード例 #9
0
        void UpdateWordAdornments()
        {
            //Find the new spans

            FindData findData = new FindData("select * from t", RequestedPoint.Snapshot);

            findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;
            List <SnapshotSpan> wordSpans = new List <SnapshotSpan>();

            wordSpans.AddRange(TextSearchService.FindAll(findData));
            SnapshotPoint currentRequest = RequestedPoint;
            TextExtent    word           = TextStructureNavigator.GetExtentOfWord(currentRequest);
            SnapshotSpan  currentWord    = word.Span;

            //need to send the text to sql and get back the costs, only when toggled on though
            //or if text changed since last got it i.e. need some sort of cache then fill the spans :)

            //If another change hasn't happened, do a real update
            if (currentRequest == RequestedPoint)
            {
                SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(wordSpans), currentWord);
            }
        }
コード例 #10
0
        void UpdateWordsAdornments()
        {
            SnapshotPoint currentRequest = RequestedPoint;
            List <NormalizedSnapshotSpanCollection> wordSpansList = new List <NormalizedSnapshotSpanCollection>();
            var words = HighlightWordsSettingsManager.GetWords();

            foreach (string word in words)
            {
                //Find the new spans
                FindData findData = new FindData(word, SourceBuffer.CurrentSnapshot)
                {
                    FindOptions = FindOptions.WholeWord | FindOptions.MatchCase
                };

                wordSpansList.Add(new NormalizedSnapshotSpanCollection(TextSearchService.FindAll(findData)));
            }

            //If another change hasn't happened, do a real update
            if (currentRequest == RequestedPoint)
            {
                SynchronousUpdate(currentRequest, wordSpansList);
            }
        }
コード例 #11
0
        private NormalizedSnapshotSpanCollection SearchHighlightedSpans(IEnumerable <HighlightedEntity>
                                                                        entities, ITextSnapshot snapshot)
        {
            var highLightedSpans = new List <SnapshotSpan>();

            foreach (var entity in entities)
            {
                //var findData = new FindData(".*\n", snapshot);
                //findData.FindOptions = FindOptions.UseRegularExpressions;
                //var allLines = TextSearchService.FindAll(findData);

                //highLightedSpans.AddRange(allLines.Where(l => entity.IsLineInEntity(l.Start.
                //    GetContainingLine().LineNumber + 1)));

                string[] keywords = entity.Keywords;
                foreach (string keyword in keywords)
                {
                    FindData findData = new FindData(keyword, snapshot);
                    findData.FindOptions = FindOptions.None;
                    highLightedSpans.AddRange(TextSearchService.FindAll(findData));
                }
            }
            return(new NormalizedSnapshotSpanCollection(highLightedSpans));
        }
コード例 #12
0
        private void UpdateWordAdornments(object threadContext)
        {
            try
            {
                var currentRequest = RequestedPoint;

                var wordSpans = new List <SnapshotSpan>();

                var clickLineSelection = SourceBuffer.CurrentSnapshot.GetLineFromPosition(RequestedPoint).GetText();
                var lineStartPos       = SourceBuffer.CurrentSnapshot.GetLineFromPosition(RequestedPoint).Start.Position;
                var lineCaretPos       = RequestedPoint.Position - lineStartPos;

                var fileStartPos = -1;
                var fileEndPos   = -1;
                var foundWord    = false;

                if ((fileStartPos = clickLineSelection.IndexOf("file://", StringComparison.Ordinal)) > 0 &&
                    (fileEndPos = clickLineSelection.IndexOf(">", StringComparison.Ordinal)) > 0 &&
                    fileEndPos > fileStartPos && lineCaretPos > fileStartPos && lineCaretPos < fileEndPos &&
                    fileStartPos >= 0 && fileEndPos >= 0)
                {
                    fileStartPos += "file://".Length;

                    var strFilePath = clickLineSelection.Substring(fileStartPos, fileEndPos - fileStartPos);

                    if (File.Exists(strFilePath))
                    {
                        var strExt = Path.GetExtension(strFilePath);

                        foundWord = true;

                        var editorTool = VSDebugProPackage.Context.Settings.GetAssignedTool(strExt);

                        if (editorTool != string.Empty)
                        {
                            Process.Start(editorTool, strFilePath);
                        }
                    }
                }

                if (!foundWord)
                {
                    // If we couldn't find a word, just clear out the existing markers
                    SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(), null);
                    return;
                }

                var currentWord = new SnapshotSpan(
                    new SnapshotPoint(SourceBuffer.CurrentSnapshot, lineStartPos + fileStartPos),
                    new SnapshotPoint(SourceBuffer.CurrentSnapshot, lineStartPos + fileEndPos));

                // If this is the same word we currently have, we're done (e.g. caret moved within a word).
                if (CurrentWord.HasValue && currentWord == CurrentWord)
                {
                    return;
                }

                // Find the new spans
                var findData = new FindData(currentWord.GetText(), currentWord.Snapshot);
                findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;

                wordSpans.AddRange(TextSearchService.FindAll(findData));
                // If we are still up-to-date (another change hasn't happened yet), do a real update
                if (currentRequest == RequestedPoint)
                {
                    SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(wordSpans), currentWord);
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
コード例 #13
0
        private void OnSelectionChanged(object sender, object e)
        {
            try
            {
                String selectedText = this.View.Selection.StreamSelectionSpan.GetText();
                if (!string.IsNullOrEmpty(selectedText) && !string.IsNullOrWhiteSpace(selectedText))
                {
                    // where are we
                    SnapshotPoint       currentRequest = this.View.Selection.Start.Position;
                    List <SnapshotSpan> wordSpans      = new List <SnapshotSpan>();
                    // Search for me please
                    TextExtent word      = TextStructureNavigator.GetExtentOfWord(currentRequest);
                    bool       foundWord = true;
                    //
                    if (!WordExtentIsValid(currentRequest, word))
                    {
                        //Same context ?
                        if (word.Span.Start != currentRequest ||
                            currentRequest == currentRequest.GetContainingLine().Start ||
                            char.IsWhiteSpace((currentRequest - 1).GetChar()))
                        {
                            foundWord = false;
                        }
                        else
                        {
                            // Move back, and start again
                            word = TextStructureNavigator.GetExtentOfWord(currentRequest - 1);

                            //If the word still isn't valid, we're done
                            if (!WordExtentIsValid(currentRequest, word))
                            {
                                foundWord = false;
                            }
                        }
                    }

                    if (!foundWord)
                    {
                        //If we couldn't find a word, clear out the existing markers
                        SynchronousUpdate(new NormalizedSnapshotSpanCollection());
                        return;
                    }
                    SnapshotSpan currentWord = word.Span;
                    selectedWord = this.View.Selection.StreamSelectionSpan.SnapshotSpan;


                    //If this is the current word, and the caret moved within a word, we're done.
                    if (!(selectedWord.HasValue && currentWord == selectedWord))
                    {
                        return;
                    }
                    //Find the new spans
                    FindData findData = new FindData(currentWord.GetText(), currentWord.Snapshot);
                    findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;
                    // Values are zero-based
                    SnapshotPoint point = View.Caret.Position.BufferPosition;
                    // Retrieve the XFile
                    XSharpModel.XFile xFile = this.View.TextBuffer.GetFile();
                    if (xFile != null)
                    {
                        // Now, retrieve the current member
                        XSharpModel.XMemberDefinition member = XSharpTokenTools.FindMemberAtPosition(point.Position, xFile);
                        if (member == null)
                        {
                            return;
                        }
                        // Ok, so we now have the "range" of the Member, and will only select text in THIS member
                        SnapshotSpan memberSpan = new SnapshotSpan(currentWord.Snapshot, member.Interval.Start, member.Interval.Width);
                        // Get all the corresponding Words
                        Collection <SnapshotSpan> allFound    = TextSearchService.FindAll(findData);
                        Collection <SnapshotSpan> memberFound = new Collection <SnapshotSpan>();
                        foreach (SnapshotSpan ssp in allFound)
                        {
                            // Inside the Member ?
                            if (memberSpan.Contains(ssp))
                            {
                                memberFound.Add(ssp);
                            }
                        }
                        //
                        wordSpans.AddRange(memberFound);
                        // Show please
                        SynchronousUpdate(new NormalizedSnapshotSpanCollection(wordSpans));
                    }
                }
            }
            catch (Exception ex)
            {
                XSettings.DisplayOutputMessage("HighlightWordTag Exception: " + ex.Message);
            }
        }
コード例 #14
0
        void UpdateWordAdornments()
        {
            SnapshotPoint       currentRequest = RequestedPoint;
            List <SnapshotSpan> wordSpans      = new List <SnapshotSpan>();
            //Find all words in the buffer like the one the caret is on
            TextExtent word      = TextStructureNavigator.GetExtentOfWord(currentRequest);
            bool       foundWord = true;

            //If we've selected something not worth highlighting, we might have missed a "word" by a little bit
            if (!WordExtentIsValid(currentRequest, word))
            {
                //Before we retry, make sure it is worthwhile
                if (word.Span.Start != currentRequest ||
                    currentRequest == currentRequest.GetContainingLine().Start ||
                    char.IsWhiteSpace((currentRequest - 1).GetChar()))
                {
                    foundWord = false;
                }
                else
                {
                    // Try again, one character previous.
                    //If the caret is at the end of a word, pick up the word.
                    word = TextStructureNavigator.GetExtentOfWord(currentRequest - 1);

                    //If the word still isn't valid, we're done
                    if (!WordExtentIsValid(currentRequest, word))
                    {
                        foundWord = false;
                    }
                }
            }

            IScopedObject found = null;

            if (foundWord) // see if it's an identifier
            {
                if (nodeProvider.LastValidTree != null)
                {
                    string text = word.Span.GetText();
                    // check functions
                    if (nodeProvider.Funcs == null || (found = nodeProvider.Funcs.FirstOrDefault(func => func.Name == text)) == null)
                    {
                        IEnumerable <Field> fields = nodeProvider.GetFields(currentRequest);
                        if (fields == null || (found = fields.FirstOrDefault(f => f.Name == text)) == null ||
                            !found.References.Any(f => f.Location.Position <= word.Span.Start.Position && f.Span.EndPosition >= word.Span.End.Position)
                            )
                        {
                            foundWord = false;
                        }
                    }
                }
            }

            if (!foundWord)
            {
                //If we couldn't find a word, clear out the existing markers
                SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(), null);
                return;
            }

            SnapshotSpan currentWord = word.Span;

            //If this is the current word, and the caret moved within a word, we're done.
            if (CurrentWord.HasValue && currentWord == CurrentWord)
            {
                return;
            }

            //Find the new spans
            FindData findData = new FindData(currentWord.GetText(), currentWord.Snapshot);

            findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;

            IEnumerable <SnapshotSpan> spans = TextSearchService.FindAll(findData);

            if (found != null && found.References != null)
            {
                spans = spans.Where(span => found.References.Any(f => f.Location.Position <= span.Start.Position && f.Span.EndPosition >= span.End.Position));
            }

            wordSpans.AddRange(spans);

            //If another change hasn't happened, do a real update
            if (currentRequest == RequestedPoint)
            {
                SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(wordSpans), currentWord);
            }
        }