Example #1
0
        /// <include file='doc\ExpansionProvider.uex' path='docs/doc[@for="ExpansionProvider.FormatSpan"]/*' />
        public virtual int FormatSpan(IVsTextLines buffer, TextSpan[] ts)
        {
            if (this.source.GetTextLines() != buffer)
            {
                throw new System.ArgumentException(SR.GetString(SR.UnknownBuffer), "buffer");
            }
            int rc = NativeMethods.E_NOTIMPL;

            if (ts != null)
            {
                for (int i = 0, n = ts.Length; i < n; i++)
                {
                    if (this.source.LanguageService.Preferences.EnableFormatSelection)
                    {
                        TextSpan span = ts[i];
                        // We should not merge edits in this case because it might clobber the
                        // $varname$ spans which are markers for yellow boxes.
                        using (EditArray edits = new EditArray(this.source, this.view, false, SR.GetString(SR.FormatSpan))) {
                            this.source.ReformatSpan(edits, span);
                            edits.ApplyEdits();
                        }
                        rc = NativeMethods.S_OK;
                    }
                }
            }
            return(rc);
        }
Example #2
0
 /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.ReformatDocument;"]/*' />
 public virtual void ReformatDocument()
 {
     if (this.CanReformat())
     {
         Debug.Assert(this.source != null);
         if (this.source != null)
         {
             TextSpan  span = this.source.GetDocumentSpan();
             EditArray mgr  = new EditArray(this.source, this.TextView, true, SR.GetString(SR.FormatSpan));
             this.source.ReformatSpan(mgr, span);
             mgr.ApplyEdits();
         }
     }
 }
Example #3
0
        private void DoFormatting(EditArray mgr, TextSpan span)
        {
            // Make sure there is one space after every comma unless followed
            // by a tab or comma is at end of line.
            IVsTextLines pBuffer = GetTextLines();
            if (pBuffer != null)
            {
//                List<EditSpan> changeList = new List<EditSpan>();

                // BETA DISABLED
                List<EditSpan> changeList = NShaderFormatHelper.ReformatCode(pBuffer, span, LanguageService.GetLanguagePreferences().TabSize);
                foreach (EditSpan editSpan in changeList)
                {
                    // Add edit operation
                    mgr.Add(editSpan);
                }
                // Apply all edits
                mgr.ApplyEdits();
            }
        }
Example #4
0
 /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.ReformatSelection;"]/*' />
 public virtual void ReformatSelection()
 {
     if (this.CanReformat())
     {
         Debug.Assert(this.source != null);
         if (this.source != null)
         {
             TextSpan ts = GetSelection();
             if (TextSpanHelper.IsEmpty(ts))
             {
                 // format just this current line.
                 ts.iStartIndex = 0;
                 ts.iEndLine    = ts.iStartLine;
                 ts.iEndIndex   = this.source.GetLineLength(ts.iStartLine);
             }
             EditArray mgr = new EditArray(this.source, this.TextView, true, SR.GetString(SR.FormatSpan));
             this.source.ReformatSpan(mgr, ts);
             mgr.ApplyEdits();
         }
     }
 }
Example #5
0
 /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.ReformatSelection;"]/*' />
 public virtual void ReformatSelection() {
     if (this.CanReformat()) {
         Debug.Assert(this.source != null);
         if (this.source != null) {
             TextSpan ts = GetSelection();
             if (TextSpanHelper.IsEmpty(ts)) {
                 // format just this current line.
                 ts.iStartIndex = 0;
                 ts.iEndLine = ts.iStartLine;
                 ts.iEndIndex = this.source.GetLineLength(ts.iStartLine);
             }
             EditArray mgr = new EditArray(this.source, this.TextView, true, SR.GetString(SR.FormatSpan));
             this.source.ReformatSpan(mgr, ts);
             mgr.ApplyEdits();
         }
     }
 }
Example #6
0
 /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.ReformatDocument;"]/*' />
 public virtual void ReformatDocument() {
     if (this.CanReformat()) {
         Debug.Assert(this.source != null);
         if (this.source != null) {
             TextSpan span = this.source.GetDocumentSpan();
             EditArray mgr = new EditArray(this.source, this.TextView, true, SR.GetString(SR.FormatSpan));
             this.source.ReformatSpan(mgr, span);
             mgr.ApplyEdits();
         }
     }
 }
Example #7
0
        private void InsertStabsIntoSource()
        {
            var methodStubInfos = ReadMethodStubInfosFromDataGrideView().ToArray();
            var laggSrv         = _source.LanguageService;
            var pref            = laggSrv.Preferences;
            var sufix           = methodStubInfos.Length > 1 ? "s" : "";
            var editArray       = new EditArray(_source, null, true, "implement interface" + sufix + " stub" + sufix);

            _source.LockWrite();
            try
            {
                MakeChanges(methodStubInfos, pref, editArray);
                editArray.ApplyEdits();
                Close();
            }
            catch (Exception ex) { _source.ProjectInfo.ShowMessage("Error: " + ex.Message, MessageType.Error); }
            finally
            {
                editArray.Dispose();
                _source.UnlockWrite();
            }
        }
Example #8
0
 /// <include file='doc\ExpansionProvider.uex' path='docs/doc[@for="ExpansionProvider.FormatSpan"]/*' />
 public virtual int FormatSpan(IVsTextLines buffer, TextSpan2[] ts) {
     if (this.source.GetTextLines() != buffer) {
         throw new System.ArgumentException(SR.GetString(SR.UnknownBuffer), "buffer");
     }
     int rc = NativeMethods.E_NOTIMPL;
     if (ts != null) {
         for (int i = 0, n = ts.Length; i < n; i++) {
             if (this.source.LanguageService.Preferences.EnableFormatSelection) {
                 TextSpan span = TextSpanHelper.TextSpanFromTextSpan2(ts[i]);
                 // We should not merge edits in this case because it might clobber the
                 // $varname$ spans which are markers for yellow boxes.
                 EditArray edits = new EditArray(this.source, this.view, false, SR.GetString(SR.FormatSpan));
                 this.source.ReformatSpan(edits, span);
                 edits.ApplyEdits();
                 rc = NativeMethods.S_OK;
             }
         }
     }
     return rc;
 }
Example #9
0
 internal void ReformatSpan(EditArray mgr, TextSpan span, IFormatter provider)
 {
     var sourcePart = Data.ToSourcePart(span);
     var reformat = Compiler.Locate(sourcePart).Reformat(sourcePart, provider);
     mgr.Add(new EditSpan(span, reformat));
     mgr.ApplyEdits();
 }
Example #10
0
        public override TextSpan UncommentLines(TextSpan span, string lineComment)
        {
            // Remove line comments
            int clen = lineComment.Length;
            var editMgr = new EditArray(this, null, true, "UncommentLines");

            for (int line = span.iStartLine; line <= span.iEndLine; line++) {
                int i = this.ScanToNonWhitespaceChar(line);
                string text = base.GetLine(line);

                if ((i + clen) <= text.Length && text.Substring(i, clen) == lineComment) {
                    var es = new EditSpan(new TextSpan() {
                        iEndLine = line,
                        iStartLine = line,
                        iStartIndex = i,
                        iEndIndex = i + clen
                    }, "");
                    editMgr.Add(es); // remove line comment.

                    if (line == span.iStartLine && span.iStartIndex != 0)
                        span.iStartIndex = i;
                }
            }

            editMgr.ApplyEdits();

            span.iStartIndex = 0;
            return span;
        }