Пример #1
0
        public int GetTokenInfoAt(TokenInfo[] infoArray, int col, ref TokenInfo info)
        {
            for (int i = 0, len = infoArray.Length; i < len; i++)
            {
                int start = infoArray[i].StartIndex;
                int end = infoArray[i].EndIndex;

                if (i == 0 && start > col)
                    return -1;

                if (col >= start && col <= end)
                {
                    info = infoArray[i];
                    return i;
                }
            }

            return -1;
        }
Пример #2
0
 public void MatchBracesAndMethodTip(IVsTextView textView, int line, int index, MethodTipMiscellany misc, TokenInfo info)
 {
     this.BeginBackgroundRequest(
         line, 
         index, 
         info, 
         BackgroundRequestReason.MatchBracesAndMethodTip, 
         textView, 
         RequireFreshResults.No, 
         req =>
             {
                 HandleMatchBracesResponse(req);
                 HandleMethodTipResponse(req);
             }
         );
 }
Пример #3
0
        public BackgroundRequest BeginBackgroundRequest(int line, int idx, TokenInfo info, BackgroundRequestReason reason, IVsTextView view, RequireFreshResults requireFreshResults, BackgroundRequestResultHandler callback, MethodTipMiscellany methodTipMiscellany = 0)
        {
            var wpfTextView = GetWpfTextViewFromVsTextView(view);
            var snapshot = wpfTextView.TextSnapshot;

            if (this.disposed) return null;
            string fname = this.GetFilePath();

            Debug.Assert(snapshot != null);
            Debug.Assert(callback != null);

            // Check if we can shortcut executing the background request and just fill in the latest
            // cached scope for the active view from this.service.RecentFullTypeCheckResults.
            //
            // This must only kick in if ExecuteBackgroundRequest is equivalent to fetching a recent,
            // perhaps out-of-date scope.
            if (!this.NeedsVisualRefresh &&
                this.service.IsRecentScopeSufficientForBackgroundRequest(reason) &&
                (this.service.RecentFullTypeCheckResults != null) &&
                this.service.RecentFullTypeCheckFile.Equals(fname) &&
                requireFreshResults != RequireFreshResults.Yes)
            {
                BackgroundRequest request = this.service.CreateBackgroundRequest(this, line, idx, info, null, snapshot, methodTipMiscellany, fname, reason, view);
                request.ResultScope = this.service.RecentFullTypeCheckResults;
                request.ResultClearsDirtinessOfFile = false;
                request.Timestamp = this.ChangeCount;
                request.IsSynchronous = true;
                callback(request);
                return request;
            }
            else
            {

                string text = this.GetText(); // get all the text
                BackgroundRequest request = this.service.CreateBackgroundRequest(this, line, idx, info, text, snapshot, methodTipMiscellany, fname, reason, view);
                request.Timestamp = this.ChangeCount;
                request.DirtySpan = this.dirtySpan;
                request.RequireFreshResults = requireFreshResults;

                if (!this.LanguageService.Preferences.EnableAsyncCompletion)
                {
                    request.IsSynchronous = true; //unless registry value indicates that sync ops always prefer async 
                }
                if (request.IsSynchronous)
                {
                    this.service.ExecuteBackgroundRequest(request);
                    callback(request);
                }
                else
                {
                    request.result = this.service.BeginBackgroundRequest(request, callback);
                }
                return request;
            }
        }
Пример #4
0
 public void MethodTip(IVsTextView textView, int line, int index, TokenInfo info, MethodTipMiscellany methodTipMiscellany, RequireFreshResults requireFreshResults)
 {
     this.BeginBackgroundRequest(line, index, info, BackgroundRequestReason.MethodTip, textView, requireFreshResults, new BackgroundRequestResultHandler(this.HandleMethodTipResponse), methodTipMiscellany);
 }
Пример #5
0
 public void MatchBraces(IVsTextView textView, int line, int index, TokenInfo info)
 {
     this.BeginBackgroundRequest(line, index, info, BackgroundRequestReason.MatchBraces, textView, RequireFreshResults.No, new BackgroundRequestResultHandler(this.HandleMatchBracesResponse));
 }
Пример #6
0
 static bool MatchToken(WORDEXTFLAGS flags, TokenInfo info)
 {
     TokenType type = info.Type;
     if ((flags & WORDEXTFLAGS.WORDEXT_FINDTOKEN) != 0)
         return !(type == TokenType.Comment || type == TokenType.LineComment);
     else
         return (type == TokenType.Keyword || type == TokenType.Identifier || type == TokenType.String || type == TokenType.Literal);
 }
Пример #7
0
 // Implemented in Source.fs
 public abstract void Completion(IVsTextView textView, TokenInfo info, BackgroundRequestReason reason, RequireFreshResults requireFreshResults);
Пример #8
0
        public bool GetWordExtent(int line, int idx, WORDEXTFLAGS flags, out int startIdx, out int endIdx)
        {
            Debug.Assert(line >= 0 && idx >= 0);
            startIdx = endIdx = idx;

            int length;
            NativeMethods.ThrowOnFailure(this.textLines.GetLengthOfLine(line, out length));
            // pin to length of line just in case we return false and skip pinning at the end of this method.
            startIdx = endIdx = Math.Min(idx, length);
            if (length == 0)
            {
                return false;
            }

            //get the character classes
            TokenInfo[] lineInfo = this.colorizer.GetLineInfo(this.textLines, line, this.colorState);
            if (lineInfo == null || lineInfo.Length == 0) return false;

            int count = lineInfo.Length;
            TokenInfo info = new TokenInfo();
            int index = this.GetTokenInfoAt(lineInfo, idx, ref info);

            if (index < 0) return false;
            // don't do anything in comment or text or literal space, unless we
            // are doing intellisense in which case we want to match the entire value
            // of quoted strings.
            TokenType type = info.Type;
            if ((flags != SourceImpl.WholeToken || type != TokenType.String) && (type == TokenType.Comment || type == TokenType.LineComment || type == TokenType.Text || type == TokenType.String || type == TokenType.Literal))
                return false;
            //search for a token
            switch (flags & WORDEXTFLAGS.WORDEXT_MOVETYPE_MASK)
            {
                case WORDEXTFLAGS.WORDEXT_PREVIOUS:
                    index--;
                    while (index >= 0 && !MatchToken(flags, lineInfo[index])) index--;
                    if (index < 0) return false;
                    break;

                case WORDEXTFLAGS.WORDEXT_NEXT:
                    index++;
                    while (index < count && !MatchToken(flags, lineInfo[index])) index++;
                    if (index >= count) return false;
                    break;

                case WORDEXTFLAGS.WORDEXT_NEAREST:
                    {
                        int prevIdx = index;
                        prevIdx--;
                        while (prevIdx >= 0 && !MatchToken(flags, lineInfo[prevIdx])) prevIdx--;
                        int nextIdx = index;
                        while (nextIdx < count && !MatchToken(flags, lineInfo[nextIdx])) nextIdx++;
                        if (prevIdx < 0 && nextIdx >= count) return false;
                        else if (nextIdx >= count) index = prevIdx;
                        else if (prevIdx < 0) index = nextIdx;
                        else if (index - prevIdx < nextIdx - index) index = prevIdx;
                        else
                            index = nextIdx;
                        break;
                    }

                case WORDEXTFLAGS.WORDEXT_CURRENT:
                default:
                    if (!MatchToken(flags, info))
                        return false;

                    break;
            }
            info = lineInfo[index];

            // We found something, set the span, pinned to the valid coordinates for the
            // current line.
            startIdx = Math.Min(length, info.StartIndex);
            endIdx = Math.Min(length, info.EndIndex);

            // The scanner endIndex is the last char of the symbol, but
            // GetWordExtent wants it to be the next char after that, so 
            // we increment the endIdx (if we can).
            if (endIdx < length) endIdx++;
            return true;
        }
Пример #9
0
        public TokenInfo GetTokenInfo(int line, int col)
        {
            if (col < 0)
            {
                throw new InvalidOperationException("TokenInfo called with negative col");
            }
            //get current line 
            TokenInfo info = new TokenInfo();
            //get line info
            TokenInfo[] lineInfo = this.colorizer.GetLineInfo(this.textLines, line, this.colorState);
            if (lineInfo != null)
            {
                //get character info      
                this.GetTokenInfoAt(lineInfo, col - 1, ref info);
            }

            return info;
        }
Пример #10
0
 // Implemented in servicem.fs
 internal abstract BackgroundRequest CreateBackgroundRequest(int line, int col, TokenInfo info, string sourceText, ITextSnapshot snapshot, MethodTipMiscellany methodTipMiscellany, string fname,
                          BackgroundRequestReason reason, IVsTextView view,
                          AuthoringSink sink, ISource source, int timestamp, bool synchronous);
Пример #11
0
 internal BackgroundRequest CreateBackgroundRequest(SourceImpl s, int line, int idx, TokenInfo info, string sourceText, ITextSnapshot snapshot, MethodTipMiscellany methodTipMiscellany,
                                                    string fname, BackgroundRequestReason reason, IVsTextView view)
 {
     // We set this to "false" because we are effectively abandoning any currently executing background request, e.g. an OnIdle request
     this.isServingBackgroundRequest = false;
     bool sync = false;
     if (!this.Preferences.EnableAsyncCompletion)
     {
         sync = true; //unless registry value indicates that sync ops always prefer async 
     }
     return CreateBackgroundRequest(line, idx, info, sourceText, snapshot, methodTipMiscellany, fname, reason, view, s.CreateAuthoringSink(reason, line, idx), s, s.ChangeCount, sync);
 }
Пример #12
0
        internal BackgroundRequest(int line, int col, TokenInfo info, string src, ITextSnapshot snapshot, MethodTipMiscellany methodTipMiscellany, string fname,
                                 BackgroundRequestReason reason, IVsTextView view,
                                 AuthoringSink sink, ISource source, int timestamp, bool synchronous)
        {
            this.Source = source;
            this.Timestamp = timestamp;
            this.Line = line;
            this.Col = col;
            this.FileName = fname;
            this.Text = src;
            this.Reason = reason;
            this.View = view;
            this.Snapshot = snapshot;
            this.MethodTipMiscellany = methodTipMiscellany;
            this.ResultSink = sink;
            this.TokenInfo = info;
            this.isSynchronous = synchronous;

            this.ResultScope = null;
            this.ResultClearsDirtinessOfFile = false;
        }