Exemplo n.º 1
0
        // used by intellisense mechanisms.
        public virtual TokenInfo[] GetLineInfo(int line, IVsTextColorState colorState)
        {
            int length;

            buffer.GetLengthOfLine(line, out length);
            string text;

            buffer.GetLineText(line, 0, line, length, out text);

            int state;

            colorState.GetColorStateAtStartOfLine(line, out state);

            if (this.cachedLine == line && this.cachedLineText == text &&
                this.cachedLineState == state && this.cachedLineInfo != null)
            {
                return(this.cachedLineInfo);
            }

            // recolorize the line, and cache the results
            this.cachedLineInfo  = null;
            this.cachedLine      = line;
            this.cachedLineText  = text;
            this.cachedLineState = state;

            GetColorInfo(text, length, state);

            //now it should be in the cache
            return(this.cachedLineInfo);
        }
Exemplo n.º 2
0
        /// <include file='doc\Colorizer.uex' path='docs/doc[@for="Colorizer.GetLineInfo"]/*' />
        public virtual TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState)
        {
            int length;

            NativeMethods.ThrowOnFailure(buffer.GetLengthOfLine(line, out length));
            if (length == 0)
            {
                return(null);
            }

            string text;

            NativeMethods.ThrowOnFailure(buffer.GetLineText(line, 0, line, length, out text));

            int state;

            NativeMethods.ThrowOnFailure(colorState.GetColorStateAtStartOfLine(line, out state));

            if (this.cachedLine == line && this.cachedLineText == text &&
                this.cachedLineState == state && this.cachedLineInfo != null)
            {
                return(this.cachedLineInfo);
            }

            // recolorize the line, and cache the results
            this.cachedLineInfo  = null;
            this.cachedLine      = line;
            this.cachedLineText  = text;
            this.cachedLineState = state;

            NativeMethods.ThrowOnFailure(GetColorInfo(text, length, state));

            //now it should be in the cache
            return(this.cachedLineInfo);
        }
Exemplo n.º 3
0
        public BracketFinder(NemerleSource source, int startLine,
                             int startCol, NemerleScanner scanner, IVsTextColorState colorState)
        {
            #region Init fields

            Scanner   = scanner;
            Source    = source;
            StartLine = startLine;
            Lex       = scanner.GetNewLexer();
            Lex.SetFileName(source.GetFilePath());
            ColorState = colorState;
            _lineCount = source.GetLineCount();
            var line = startLine - 1;
            _buffer = new string[1] {
                source.GetText(line, 0, line, source.GetLineLength(line))
            };
            _startBufferLine = line;

            #endregion

            #region 2. Determine that it is a paired token. 3. Determine paired token.

            // Get tokens of line under text carret into dynamic array.
            List <ScanTokenInfo> lineToks = GetLineTokens(startLine, true);
            // Find index of token which located under text carret.
            int index = FindIndex(lineToks, x => x.Token.Location.Contains(startLine, startCol));

            if (index < 0)
            {
                return;
            }

            // If index is corret get corresponding token.
            ScanTokenInfo startBraceInfo = lineToks[index];
            // Remember it, if token have paired token.
            if (IsPairedToken(startBraceInfo.Token))
            {
                StartBraceInfo = startBraceInfo;
            }
            else
            {
                // otherwise try get right-hand token...
                startBraceInfo = RightHand(lineToks, index);
                // Remember it, if token have paired token.
                if (IsPairedToken(startBraceInfo.Token))
                {
                    StartBraceInfo = startBraceInfo;
                }
            }

            #endregion
        }
Exemplo n.º 4
0
        /// <summary>
        /// Match paired tokens. Run in GUI thread synchronously!
        /// </summary>
        /// <param name="isMatchBraces">match or highlight mraces</param>
        /// <param name="line">zero based index of line</param>
        /// <param name="index">zero based index of char</param>
        public TextSpan[] GetMatchingBraces(bool isMatchBraces, int line, int index)
        {
            var nline = line + 1;  // one based number of line
            var ncol  = index + 1; // one based number of column

            // Steps:
            // 1. Find token under text caret.
            // 2. Determine that it is a paired token.
            // 3. Determine paired token.
            // 4. Find paired token in the source file.
            // 5. Set info about paired tokens Sink and return it in AuthoringScope.

            var source = this;
            IVsTextColorState colorState = source.ColorState;
            Colorizer         colorizer  = source.GetColorizer();
            var    scanner  = (NSScanner)colorizer.Scanner;
            string lineText = source.GetLine(nline);

            scanner.SetSource(lineText, 0);

            // Steps: 1-3
            //var bracketFinder = new BracketFinder(source, nline, ncol, scanner, colorState);

            // 4. Find paired token in the source file.
            //var matchBraceInfo = bracketFinder.FindMatchBraceInfo();

            //if (matchBraceInfo != null) {
            // 5. Set info about paired tokens Sink and return it in AuthoringScope.

            // Fix a bug in MPF: Correct location of left token.
            // It need for correct navigation (to left side of token).
            //

            //Token matchToken = matchBraceInfo.Token;

            //Location matchLocation = isMatchBraces && !BracketFinder.IsOpenToken(matchToken)
            //  ? matchToken.Location.FromEnd() : matchToken.Location;

            //Location matchLocation = matchToken.Location;

            // Set tokens position info

            //var startSpan = Utils.SpanFromLocation(bracketFinder.StartBraceInfo.Token.Location);
            //var endSpan = Utils.SpanFromLocation(matchLocation);

            //return new[] { startSpan, endSpan };
            //}

            return(new TextSpan[0]);
        }
Exemplo n.º 5
0
        /// <include file='doc\Colorizer.uex' path='docs/doc[@for="Colorizer.GetLineInfo"]/*' />
        public virtual TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState)
        {
            int length;

            NativeMethods.ThrowOnFailure(buffer.GetLengthOfLine(line, out length));
            if (length == 0)
            {
                return(null);
            }

            string text;

            NativeMethods.ThrowOnFailure(buffer.GetLineText(line, 0, line, length, out text));

            int state;

            NativeMethods.ThrowOnFailure(colorState.GetColorStateAtStartOfLine(line, out state));

            if (this.cachedLine == line && this.cachedLineText == text &&
                this.cachedLineState == state && this.cachedLineInfo != null)
            {
                return(this.cachedLineInfo);
            }

            // recolorize the line, and cache the results
            this.cachedLineInfo  = null;
            this.cachedLine      = line;
            this.cachedLineText  = text;
            this.cachedLineState = state;

            // GetColorInfo will update the cache. Note that here we don't use NativeMethods.ThrowOnFailure
            // because the return code is the current parsing state, not an HRESULT.
            GetColorInfo(text, length, state);

            //now it should be in the cache
            return(this.cachedLineInfo);
        }
Exemplo n.º 6
0
 internal abstract TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState);
Exemplo n.º 7
0
        // Overriden in source.fs, it calls this base implementation
        public virtual void Dispose()
        {
#if LANGTRACE
            Trace.WriteLine("Source::Cleanup");
#endif
            this.disposed = true;
            try
            {
                if (this.textLinesEvents != null)
                {
                    this.textLinesEvents.Dispose();
                    this.textLinesEvents = null;
                }
            }
            finally
            {
                try
                {
                    if (this.userDataEvents != null)
                    {
                        this.userDataEvents.Dispose();
                        this.userDataEvents = null;
                    }
                }
                finally
                {
                    try
                    {
                        if (this.hiddenTextSession != null)
                        {
                            // We can't throw or exit here because we need to call Dispose on the
                            // other members that need to be disposed.
                            this.hiddenTextSession.UnadviseClient();
                            // This is causing a debug assert in vs\env\msenv\textmgr\vrlist.cpp
                            // at line 1997 in CVisibleRegionList::Terminate
                            //this.hiddenTextSession.Terminate();
                            this.hiddenTextSession = null;
                        }
                    }
                    finally
                    {
                        try
                        {
                            if (this.methodData != null)
                            {
                                this.methodData.Dispose();
                                this.methodData = null;
                            }
                        }
                        finally
                        {
                            try
                            {
                                if (this.completionSet != null)
                                {
                                    this.completionSet.Dispose();
                                    this.completionSet = null;
                                }
                            }
                            finally
                            {
                                try
                                {
                                    // clear out any remaining tasks for this doc in the task list
                                    // tp may not be the same as taskProvider

                                    // REVIEW: This should be: if (null != this.taskReporter)
                                    // Right now, MSBuild 4.0 can clear out build loggers responsibly, so this.taskReporter will always
                                    // be null when we get to this point, so we'll need to create a new taskReporter to clear out the
                                    // background tasks
                                    TaskReporter tr = this.GetTaskReporter();  // may be our own TR or one from ProjectSite of this file
                                    if (null != tr)
                                    {
                                        tr.ClearBackgroundTasksForFile(this.GetFilePath());
                                        // Refresh the task list
                                        tr.OutputTaskList();
                                    }
                                    if (null != this.taskReporter)      // dispose the one we own (do not dispose one shared by project site!)
                                    {
                                        this.taskReporter.Dispose();
                                        this.taskReporter = null;
                                        this.taskProvider = null;
                                    }
                                }
                                finally
                                {
                                    try
                                    {
                                        this.service = null;
                                        if (this.colorizer != null)
                                        {
                                            // The colorizer is owned by the core text editor, so we don't close it, the core text editor
                                            // does that for us when it is ready to do so.
                                            //colorizer.CloseColorizer();
                                            this.colorizer = null;
                                        }
                                    }
                                    finally
                                    {
                                        this.colorState = null;
                                        try
                                        {
                                            if (this.expansionProvider != null)
                                            {
                                                this.expansionProvider.Dispose();
                                                this.expansionProvider = null;
                                            }

                                        }
                                        finally
                                        {
                                            // Sometimes OnCloseSource is called when language service is changed, (for example
                                            // when you save the file with a different file extension) in which case we cannot 
                                            // null out the site because that will cause a crash inside msenv.dll.
                                            //            if (this.textLines != null) {
                                            //                ((IObjectWithSite)this.textLines).SetSite(null);
                                            //            }
                                            if (this.textLines != null)
                                            {
                                                this.textLines = null;
                                                Marshal.Release(pUnkTextLines);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        internal SourceImpl(LanguageService service, IVsTextLines textLines, Colorizer colorizer)
        {
#if LANGTRACE
            Tracing.TraceRef(textLines, "Source.textLines");
#endif
            this.service = service;
            this.textLines = textLines;
            // REVIEW: why the next line? RCW in this.textLines holds IUnknown already. (released in Dispose correctly though)
            pUnkTextLines = Marshal.GetIUnknownForObject(this.textLines); //so it can't get disposed on us
            this.colorizer = colorizer;
            this.completionSet = this.CreateCompletionSet();
            this.methodData = new MethodData(this.service.Site);
            this.colorState = (IVsTextColorState)textLines;
            // track source changes
            this.textLinesEvents = new NativeMethods.ConnectionPointCookie(textLines, this, typeof(IVsTextLinesEvents));
            this.userDataEvents = new NativeMethods.ConnectionPointCookie(textLines, this, typeof(IVsUserDataEvents));

            this.doOutlining = this.service.Preferences.AutoOutlining;
            if (this.doOutlining)
            {
                GetHiddenTextSession();
            }
            this.expansionProvider = GetExpansionProvider();

            this.lastOnIdleRequestDuration = 0;

            this.openedTime = System.DateTime.Now;
        }
Exemplo n.º 9
0
    public Source(LanguageService service, IVsTextLines textLines, Colorizer colorizer){
      this.service = service;
      this.textLines = textLines;
      this.colorizer = colorizer;
      this.taskProvider = new TaskProvider(service.site); // task list
      this.completionSet = this.GetCompletionSet();      
      this.methodData = this.GetMethodData();
      this.colorState = (IVsTextColorState)textLines;

      Guid statusBarGuid = typeof(VsShellInterop.IVsStatusbar).GUID;
      this.statusBar = (VsShellInterop.IVsStatusbar)service.site.QueryService(statusBarGuid, typeof(VsShellInterop.IVsStatusbar));
      
      this.commentInfo = new CommentInfo();
      service.GetCommentFormat(this.commentInfo);

      // track source changes
      if (service.Preferences.EnableCodeSenseFastOnLineChange){
        textChangeCommitEventsCookie = VsShell.Connect(textLines, (IVsFinalTextChangeCommitEvents)this, ref VsConstants.IID_IVsFinalTextChangeCommitEvents);
      }
      this.textLinesEventsCookie = VsShell.Connect(textLines, (IVsTextLinesEvents)this, ref VsConstants.IID_IVsTextLinesEvents);
      this.SetDirty();

#if WHIDBEY
      // create a task manager
      if (taskManager == null) {
        ITaskManagerFactory taskManagerFactory = (ITaskManagerFactory)(service.site).GetService(typeof(ITaskManagerFactory));
        if (taskManagerFactory != null) {
          taskManager = taskManagerFactory.QuerySharedTaskManager("SpecSharp", true);
        }
      }
#endif
    }
Exemplo n.º 10
0
    // used by intellisense mechanisms.
    public virtual TokenInfo[] GetLineInfo(int line, IVsTextColorState colorState) {
      
      int length;
      buffer.GetLengthOfLine(line, out length);
      string text;
      buffer.GetLineText(line, 0, line, length, out text);
      
      int state;
      colorState.GetColorStateAtStartOfLine(line, out state);

      if (this.cachedLine == line && this.cachedLineText == text && 
          this.cachedLineState == state && this.cachedLineInfo != null) {
        return this.cachedLineInfo;
      }

      // recolorize the line, and cache the results
      this.cachedLineInfo = null;
      this.cachedLine = line;
      this.cachedLineText = text;
      this.cachedLineState = state;

      GetColorInfo(text, length, state);

      //now it should be in the cache
      return this.cachedLineInfo;
    }
Exemplo n.º 11
0
        /// <include file='doc\Colorizer.uex' path='docs/doc[@for="Colorizer.GetLineInfo"]/*' />
        public virtual TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState)
        {
            int length;

            NativeMethods.ThrowOnFailure(buffer.GetLengthOfLine(line, out length));
            if (length == 0)
                return null;

            string text;

            NativeMethods.ThrowOnFailure(buffer.GetLineText(line, 0, line, length, out text));

            int state;

            NativeMethods.ThrowOnFailure(colorState.GetColorStateAtStartOfLine(line, out state));

            if (this.cachedLine == line && this.cachedLineText == text &&
                this.cachedLineState == state && this.cachedLineInfo != null) {
                return this.cachedLineInfo;
            }

            // recolorize the line, and cache the results
            this.cachedLineInfo = null;
            this.cachedLine = line;
            this.cachedLineText = text;
            this.cachedLineState = state;

            // GetColorInfo will update the cache. Note that here we don't use NativeMethods.ThrowOnFailure
            // because the return code is the current parsing state, not an HRESULT.
            GetColorInfo(text, length, state);

            //now it should be in the cache
            return this.cachedLineInfo;
        }
Exemplo n.º 12
0
        /// <include file='doc\LanguageService.uex' path='docs/doc[@for="Source.Dispose"]/*' />
        public virtual void Dispose()
        {
            #if LANGTRACE
            Trace.WriteLine("Source::Cleanup");
            #endif
            try {
                if (this.textLinesEvents != null) {
                    this.textLinesEvents.Dispose();
                    this.textLinesEvents = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.userDataEvents != null) {
                    this.userDataEvents.Dispose();
                    this.userDataEvents = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.hiddenTextSession != null) {
                    // We can't throw or exit here because we need to call Dispose on the
                    // other members that need to be disposed.
                    this.hiddenTextSession.UnadviseClient();
                    this.hiddenTextSession = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.methodData != null) {
                    this.methodData.Dispose();
                    this.methodData = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.completionSet != null) {
                    this.completionSet.Dispose();
                    this.completionSet = null;
                }
            } catch (COMException) {
            }
            try {

                if (this.taskProvider != null) {
                    this.taskProvider.Dispose();
                    this.taskProvider = null;
                }
            } catch (COMException) {
            }
            try {
                this.service = null;
                if (this.colorizer != null) {
                    // The colorizer is owned by the core text editor, so we don't close it, the core text editor
                    // does that for us when it is ready to do so.
                    //colorizer.CloseColorizer();
                    this.colorizer = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.colorState != null) {
                    this.colorState = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.expansionProvider != null) {
                    this.expansionProvider.Dispose();
                    this.expansionProvider = null;
                }

            } catch (COMException) {
            }
            try {

                // Sometimes OnCloseSource is called when language service is changed, (for example
                // when you save the file with a different file extension) in which case we cannot
                // null out the site because that will cause a crash inside msenv.dll.
                //            if (this.textLines != null) {
                //                ((IObjectWithSite)this.textLines).SetSite(null);
                //            }
                if (this.textLines != null) {
                    this.textLines = null; //rely on GC rather control lifetime through ReleaseCOMObject
                    Marshal.Release(pUnkTextLines);
                }
            } catch (COMException) {
            }
        }
Exemplo n.º 13
0
        /// <include file='doc\Source.uex' path='docs/doc[@for="Source.Source"]/*' />
        public Source(LanguageService service, IVsTextLines textLines, Colorizer colorizer)
        {
            #if LANGTRACE
            Tracing.TraceRef(textLines, "Source.textLines");
            #endif
            this.service = service;
            this.textLines = textLines;
            pUnkTextLines = Marshal.GetIUnknownForObject(this.textLines); //so it can't get disposed on us
            this.colorizer = colorizer;
            this.dirty = true;
            this.completionSet = this.CreateCompletionSet();
            this.methodData = this.CreateMethodData();
            this.colorState = (IVsTextColorState)textLines;

            // Register text buffer (IVsTextLines) event handlers
            // Delegate to virtual/overridable method
            RegisterTextBufferEventHandlers(textLines);

            this.doOutlining = this.service.Preferences.AutoOutlining;
            if (this.doOutlining) {
                GetHiddenTextSession();
            }
            this.expansionProvider = GetExpansionProvider();

            this.lastParseTime = Int32.MaxValue;
        }
Exemplo n.º 14
0
 internal abstract TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState);
Exemplo n.º 15
0
        /// <include file='doc\Colorizer.uex' path='docs/doc[@for="Colorizer.GetLineInfo"]/*' />
        public virtual TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState) {

            int length;

            NativeMethods.ThrowOnFailure(buffer.GetLengthOfLine(line, out length));
            if (length == 0)
                return null;

            string text;

            NativeMethods.ThrowOnFailure(buffer.GetLineText(line, 0, line, length, out text));

            int state;

            NativeMethods.ThrowOnFailure(colorState.GetColorStateAtStartOfLine(line, out state));

            if (this.cachedLine == line && this.cachedLineText == text &&
                this.cachedLineState == state && this.cachedLineInfo != null) {
                return this.cachedLineInfo;
            }

            // recolorize the line, and cache the results
            this.cachedLineInfo = null;
            this.cachedLine = line;
            this.cachedLineText = text;
            this.cachedLineState = state;

            NativeMethods.ThrowOnFailure(GetColorInfo(text, length, state));

            //now it should be in the cache
            return this.cachedLineInfo;
        }
Exemplo n.º 16
0
    public Source(LanguageService service, IVsTextLines textLines, Colorizer colorizer) {
      this.service = service;
      this.textLines = textLines;
      this.colorizer = colorizer;
      this.taskProvider = new TaskProvider(service.site); // task list
      this.completionSet = this.GetCompletionSet();      
      this.methodData = this.GetMethodData();
      this.colorState = (IVsTextColorState)textLines;

      Guid statusBarGuid = typeof(VsShellInterop.IVsStatusbar).GUID;
      this.statusBar = (VsShellInterop.IVsStatusbar)service.site.QueryService(statusBarGuid, typeof(VsShellInterop.IVsStatusbar));

      service.GetCommentFormat(ref commentInfo);

      // track source changes
      if (service.Preferences.EnableCodeSenseFastOnLineChange) {
        textChangeCommitEventsCookie = VsShell.Connect( textLines, (IVsFinalTextChangeCommitEvents)this, ref VsConstants.IID_IVsFinalTextChangeCommitEvents);
      }
      this.textLinesEventsCookie = VsShell.Connect( textLines, (IVsTextLinesEvents)this, ref VsConstants.IID_IVsTextLinesEvents);

    }
Exemplo n.º 17
0
 public override TokenInfo[] GetLineInfo
     (IVsTextLines buffer, int line, IVsTextColorState colorState)
 {
     Tracer.TraceBreak();
     return null;
 }