[MonoDevelop] Re: Reformat source file

Jacob Ilsø Christensen jacobilsoe at gmail.com
Fri Jun 10 16:01:48 EDT 2005


Hi.

I have attached a first attempt of the reformat file functionality.
The file contains a visitor that will visit the AST of the file to be
formatted.
The output is a hashtable which contains line numbers as keys and for
each key the value is the level of indention.
>From the SourceEditorView this hashtable is used to traverse the
lines. If a line is represented in the hashtable it is TrimStart()'ed
and prefixed with the number of tabs specified for that line in the
hashtable.

I tried it out on some sample source file and it works pretty well.
The visitor needs to be completed and some stuff on the parser needs
to be done too.

Seems like the way to go?

/Jacob



On 6/10/05, Jacob Ilsø Christensen <jacobilsoe at gmail.com> wrote:
> Hi.
> 
> I am starting out with just coding reformat file. Then I will do the
> other stuff.
> I have run into an issue though.
> 
> Suppose you have the following:
> 
> 1: namespace NS
> 2:    {
> 3:
> 4:                    }
> 
> This should be (depending on how you have configured MD) formatted to:
> 
> 1: namespace NS
> 2: {
> 3:
> 4: }
> 
> The problem is that the AST only contains information about where a
> namespace declaration begins and ends (lines 1 and 4) not where the
> contents of it begins and ends (line 2 and 4).
> 
> I would like to extend the NamespaceDeclaration class with this
> information. But this class resides in the ICSharpCode.SharpRefactory
> namespace. Is it ok to change stuff there or is there still some
> collaboration going on with SharpDevelop?
> 
> /Jacob
> 
> 
> 
> On 6/9/05, John Luke <john.luke at gmail.com> wrote:
> >
> > Jacob Ilsø Christensen wrote:
> >
> > >Hi.
> > >
> > >Ok, here is what I plan to do:
> > >
> > >1) Parse the file currently viewing.
> > >2) Traverse the built AST in parallel with traversing the file.
> > >3) Indent a specific line according to what level and what item is
> > >currently looked at in the AST.
> > >
> > >Does this sound like a way to do it?
> > >
> > It sounds like _a_ way, but there are many.  You might want to take a
> > look at one of the editors that does
> > this already vim, emacs, eclipse, etc.  Have you looked at the existing
> > FormattingStrategy stuff in the various language bindings?
> > Also, consider multiline pasting and probably more little corner cases I
> > can't think of right now.
> >
> > >Do we want such a feature in MD?
> > >
> > >
> > I think we do.  Perhaps starting with "format a file on ctl+shift+f" and
> > make sure it works right (without changing/losing information) would be
> > a smaller first step.  Then format as you go can come later after you
> > know all the issues.
> >
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ReformatVisitor.cs
Type: text/x-csharp
Size: 4129 bytes
Desc: not available
Url : http://galactus.ximian.com/pipermail/monodevelop-list/attachments/20050610/fb076060/ReformatVisitor.bin


More information about the Monodevelop-list mailing list