Esempio n. 1
0
        public void Update(ITextSnapshot textSnapshot, bool forceRefresh = false)
        {
            if (!ParserEnabled)
            {
                return; // parser was disabled
            }
            if (ParserContext != null && ParserContext.TextSnapshot == textSnapshot && !forceRefresh)
            {
                return; // we're already parsing the current snapshot and it's not a forced refresh
            }
            if (!forceRefresh)
            {
                // new snapshot?
                if (UpdateCandidate == null)
                {
                    UpdateCandidate = textSnapshot; // make it a candidate
                    UpdateStopWatch.Restart();
                    return;                         // first time parsing. will return and wait for 1s
                }
                else if (UpdateCandidate != textSnapshot)
                {
                    UpdateCandidate = textSnapshot; // update our candidate
                    UpdateStopWatch.Restart();
                    return;                         // new candidate. will return and wait for 1s
                }
                else
                {
                    // same snapshot. is it time yet to reparse?
                    UpdateStopWatch.Stop();
                    if (UpdateStopWatch.Elapsed.TotalSeconds < 1)
                    {
                        UpdateStopWatch.Start();
                        return; // not yet.
                    }
                }
            }

            // time to reparse
            if (ParserContext != null)
            {
                ParserContext.Parser.Cancel();
                ParserContext.Dispose();
            }

            ParserContext = new JavaParserContext(textSnapshot, new JavaParser(this, textSnapshot));
            Task fireAndForgetTask = ParserContext.Parser.ParseAsync();
        }
Esempio n. 2
0
        public void Update(ITextSnapshot textSnapshot, bool forceRefresh = false)
        {
            if (!ParserEnabled)
                return; // parser was disabled

            if (ParserContext != null && ParserContext.TextSnapshot == textSnapshot && !forceRefresh)
                return; // we're already parsing the current snapshot and it's not a forced refresh

            if (!forceRefresh)
            {
                // new snapshot? 
                if (UpdateCandidate == null)
                {
                    UpdateCandidate = textSnapshot; // make it a candidate
                    UpdateStopWatch.Restart();
                    return; // first time parsing. will return and wait for 1s
                }
                else if (UpdateCandidate != textSnapshot)
                {
                    UpdateCandidate = textSnapshot; // update our candidate
                    UpdateStopWatch.Restart();
                    return; // new candidate. will return and wait for 1s
                }
                else
                {
                    // same snapshot. is it time yet to reparse?
                    UpdateStopWatch.Stop();
                    if (UpdateStopWatch.Elapsed.TotalSeconds < 1)
                    {
                        UpdateStopWatch.Start();
                        return; // not yet.
                    }
                }
            }

            // time to reparse
            if (ParserContext != null)
            {
                ParserContext.Parser.Cancel();
                ParserContext.Dispose();
            }

            ParserContext = new JavaParserContext(textSnapshot, new JavaParser(this, textSnapshot));
            Task fireAndForgetTask = ParserContext.Parser.ParseAsync();
        }