//copied from MoonlightEditorExtension #region Document outline protected override void RefillOutlineStore (ParsedDocument doc, Gtk.TreeStore store) { XDocument xdoc = ((XmlParsedDocument)doc).XDocument; if (xdoc == null) return; // Gtk.TreeIter iter = outlineTreeStore.AppendValues (System.IO.Path.GetFileName (CU.Document.FilePath), p); BuildTreeChildren (store, Gtk.TreeIter.Zero, xdoc); }
public override void Initialize () { base.Initialize (); Parser parser = new Parser (CreateRootState (), false); tracker = new DocumentStateTracker<Parser> (parser, Editor); MonoDevelop.Projects.Dom.Parser.ProjectDomService.ParsedDocumentUpdated += OnParseInformationChanged; if (Document.ParsedDocument != null) { lastCU = Document.ParsedDocument; OnParsedDocumentUpdated (); } }
ParsedDocument Parse (ICSharpCode.NRefactory.IParser parser, string fileName) { parser.Parse(); DomConverter visitor = new DomConverter (fileName); ParsedDocument result = new ParsedDocument (fileName); result.CompilationUnit = (ICompilationUnit)visitor.VisitCompilationUnit(parser.CompilationUnit, null); /* visitor.Cu.ErrorsDuringCompile = p.Errors.Count > 0; visitor.Cu.Tag = p.CompilationUnit; RetrieveRegions(visitor.Cu, p.Lexer.SpecialTracker); foreach (IType c in visitor.Cu.Classes) c.Region.FileName = fileName; AddCommentTags(visitor.Cu, p.Lexer.TagComments);*/ return result; }
IEnumerable<MemberReference> SearchMember (INode member, ProjectDom dom, FilePath fileName, Mono.TextEditor.TextEditorData editor, Mono.TextEditor.Document buildDocument, List<LocalDocumentInfo.OffsetInfo> offsetInfos, ParsedDocument parsedDocument) { var resolver = new NRefactoryResolver (dom, parsedDocument.CompilationUnit, ICSharpCode.NRefactory.SupportedLanguage.CSharp, editor, fileName); FindMemberAstVisitor visitor = new FindMemberAstVisitor (buildDocument, member); visitor.IncludeXmlDocumentation = IncludeDocumentation; visitor.RunVisitor (resolver); foreach (var result in visitor.FoundReferences) { var offsetInfo = offsetInfos.FirstOrDefault (info => info.ToOffset <= result.Position && result.Position < info.ToOffset + info.Length); if (offsetInfo == null) continue; var offset = offsetInfo.FromOffset + result.Position - offsetInfo.ToOffset; var loc = editor.OffsetToLocation (offset); yield return new MemberReference (null, fileName, offset, loc.Line, loc.Column, result.Name, null); } }
string RetrieveDocumentation (int upToLine) { StringBuilder result = null; while (lastSpecial < specials.Count) { ISpecial cur = specials[lastSpecial]; if (cur.StartPosition.Line >= upToLine) break; ICSharpCode.NRefactory.Comment comment = cur as ICSharpCode.NRefactory.Comment; if (comment != null && comment.CommentType == ICSharpCode.NRefactory.CommentType.Documentation) { if (result == null) result = new StringBuilder (); result.Append (comment.CommentText); } lastSpecial++; } return result == null ? null : result.ToString (); }
public override ParsedDocument Parse (ProjectDom dom, string fileName, string content) { ParsedDocument doc = new ParsedDocument (fileName); doc.Flags |= ParsedDocumentFlags.NonSerializable; Project p = (null == dom || null == dom.Project)? IdeApp.Workspace.GetProjectContainingFile (fileName): dom.Project; ProjectInformation pi = ProjectInformationManager.Instance.Get (p); CompilationUnit cu; doc.CompilationUnit = cu = new CompilationUnit (fileName); IType tmp; IMember member; string[] contentLines = content.Split (new string[]{Environment.NewLine}, StringSplitOptions.None); DomType globals = new DomType (cu, ClassType.Unknown, GettextCatalog.GetString ("(Global Scope)"), new DomLocation (1, 1), string.Empty, new DomRegion (1, int.MaxValue), new List<IMember> ()); lock (pi) { // Add containers to type list foreach (LanguageItem li in pi.Containers ()) { if (null == li.Parent && FilePath.Equals (li.File, fileName)) { tmp = LanguageItemToIMember (pi, li, contentLines) as IType; if (null != tmp){ cu.Add (tmp); } } } // Add global category for unscoped symbols foreach (LanguageItem li in pi.InstanceMembers ()) { if (null == li.Parent && FilePath.Equals (li.File, fileName)) { member = LanguageItemToIMember (pi, li, contentLines); if (null != member) { globals.Add (member); } } } } cu.Add (globals); return doc; }
public ConversionVisitior (MonoDevelop.Projects.Dom.ParsedDocument result, List<ISpecial> specials) { this.specials = specials; this.result = result; namespaceEndLocationStack.Push (new Location (Int32.MaxValue, Int32.MaxValue)); }
public override ParsedDocument Parse (ProjectDom dom, string fileName, string content) { var result = new ParsedDocument (fileName); var unit = new MonoDevelop.Projects.Dom.CompilationUnit (fileName); result.CompilationUnit = unit; if (string.IsNullOrEmpty (content)) return result; lock (CompilerCallableEntryPoint.parseLock) { var tagComments = ProjectDomService.SpecialCommentTags.GetNames (); List<string > compilerArguments = new List<string> (); if (dom != null && dom.Project != null && MonoDevelop.Ide.IdeApp.Workspace != null) { DotNetProjectConfiguration configuration = dom.Project.GetConfiguration (MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration; CSharpCompilerParameters par = configuration != null ? configuration.CompilationParameters as CSharpCompilerParameters : null; if (par != null) { if (!string.IsNullOrEmpty (par.DefineSymbols)) { compilerArguments.Add ("-define:" + string.Join (";", par.DefineSymbols.Split (';', ',', ' ', '\t').Where (s => !string.IsNullOrWhiteSpace (s)))); } if (par.UnsafeCode) compilerArguments.Add ("-unsafe"); if (par.TreatWarningsAsErrors) compilerArguments.Add ("-warnaserror"); if (!string.IsNullOrEmpty (par.NoWarnings)) compilerArguments.Add ("-nowarn:" + string.Join (",", par.NoWarnings.Split (';', ',', ' ', '\t'))); compilerArguments.Add ("-warn:" + par.WarningLevel); compilerArguments.Add ("-langversion:" + GetLangString (par.LangVersion)); if (par.GenerateOverflowChecks) compilerArguments.Add ("-checked"); } } CompilerCompilationUnit top; ErrorReportPrinter errorReportPrinter = new ErrorReportPrinter (); using (var stream = new MemoryStream (Encoding.UTF8.GetBytes (content))) { top = CompilerCallableEntryPoint.ParseFile (compilerArguments.ToArray (), stream, fileName, errorReportPrinter); } if (top == null) return null; foreach (var special in top.SpecialsBag.Specials) { var comment = special as SpecialsBag.Comment; if (comment != null) { VisitComment (result, comment, tagComments); } else { VisitPreprocessorDirective (result, special as SpecialsBag.PreProcessorDirective); } } // convert DOM var conversionVisitor = new ConversionVisitor (top.LocationsBag); try { conversionVisitor.Dom = dom; conversionVisitor.ParsedDocument = result; conversionVisitor.Unit = unit; top.UsingsBag.Global.Accept (conversionVisitor); top.ModuleCompiled.Accept (conversionVisitor); } catch (Exception ex) { System.Console.WriteLine (ex); } result.LanguageAST = new ICSharpCode.NRefactory.CSharp.CSharpParser().Parse (top, 0); // parser errorse errorReportPrinter.Errors.ForEach (e => conversionVisitor.ParsedDocument.Add (e)); return result; } }
void AddCurRegion (ParsedDocument result, int line, int col) { if (ConditionalRegion == null) return; ConditionalRegion.End = new DomLocation (line, col); result.Add (ConditionalRegion); conditionalRegions.Pop (); }
void ParseCompilationUnit (ParsedDocument cu) { // No new errors if (cu.Errors == null || cu.Errors.Count < 1) return; // Else we underline the error foreach (MonoDevelop.Projects.Dom.Error info in cu.Errors) UnderLineError (info); }
internal void UpdateParsedDocument (ParsedDocument document) { if (this.isDisposed || document == null || this.view == null) return; if (MonoDevelop.Core.PropertyService.Get ("EnableSemanticHighlighting", false) && TextEditor != null) { var margin = TextEditor.TextViewMargin; if (margin != null) Gtk.Application.Invoke (delegate { margin.PurgeLayoutCache (); }); } SetParsedDocument (document, parsedDocument != null); }
Widget MonoDevelop.DesignerSupport.IOutlinedDocument.GetOutlineWidget () { if (outlineTreeView != null) return outlineTreeView; outlineTreeStore = new TreeStore (typeof(object)); outlineTreeModelSort = new TreeModelSort (outlineTreeStore); settings = ClassOutlineSettings.Load (); comparer = new ClassOutlineNodeComparer (GetAmbience (), settings, outlineTreeModelSort); outlineTreeModelSort.SetSortFunc (0, comparer.CompareNodes); outlineTreeModelSort.SetSortColumnId (0, SortType.Ascending); outlineTreeView = new MonoDevelop.Ide.Gui.Components.PadTreeView (outlineTreeStore); var pixRenderer = new CellRendererPixbuf (); pixRenderer.Xpad = 0; pixRenderer.Ypad = 0; outlineTreeView.TextRenderer.Xpad = 0; outlineTreeView.TextRenderer.Ypad = 0; TreeViewColumn treeCol = new TreeViewColumn (); treeCol.PackStart (pixRenderer, false); treeCol.SetCellDataFunc (pixRenderer, new TreeCellDataFunc (OutlineTreeIconFunc)); treeCol.PackStart (outlineTreeView.TextRenderer, true); treeCol.SetCellDataFunc (outlineTreeView.TextRenderer, new TreeCellDataFunc (OutlineTreeTextFunc)); outlineTreeView.AppendColumn (treeCol); outlineTreeView.HeadersVisible = false; outlineTreeView.Selection.Changed += delegate { JumpToDeclaration (false); }; outlineTreeView.RowActivated += delegate { JumpToDeclaration (true); }; this.lastCU = Document.ParsedDocument; outlineTreeView.Realized += delegate { RefillOutlineStore (); }; UpdateSorting (); var sw = new CompactScrolledWindow (); sw.Add (outlineTreeView); sw.ShowAll (); return sw; }
static void BuildTreeChildren (TreeStore store, TreeIter parent, ParsedDocument parsedDocument) { if (parsedDocument.CompilationUnit == null) return; foreach (IType cls in parsedDocument.CompilationUnit.Types) { TreeIter childIter; if (!parent.Equals (TreeIter.Zero)) childIter = store.AppendValues (parent, cls); else childIter = store.AppendValues (cls); AddTreeClassContents (store, childIter, parsedDocument, cls); } }
string GetSemanticStyle (ParsedDocument parsedDocument, Chunk chunk, ref int endOffset) { var unit = parsedDocument.LanguageAST as ICSharpCode.NRefactory.CSharp.CompilationUnit; if (unit == null) return null; var loc = doc.OffsetToLocation (chunk.Offset); if (contextualKeywords.Contains (wordbuilder.ToString ())) { var node = unit.GetNodeAt (loc.Line, loc.Column); if (node is Identifier) { switch (((Identifier)node).Name) { case "value": // highlight 'value' in property setters and event add/remove var n = node.Parent; while (n != null) { if (n is Accessor && n.Role != PropertyDeclaration.GetterRole) return null; n = n.Parent; } break; case "var": if (node.Parent != null) { var vds = node.Parent.Parent as VariableDeclarationStatement; if (node.Parent.Parent is ForeachStatement && ((ForeachStatement)node.Parent.Parent).VariableType.StartLocation == node.StartLocation || vds != null && node.StartLocation == vds.Type.StartLocation) return null; } break; } } if (node is CSharpTokenNode) return null; endOffset = doc.LocationToOffset (node.EndLocation.Line, node.EndLocation.Column); return spanParser.CurSpan != null ? spanParser.CurSpan.Color : "text"; } else { var type = unit.GetNodeAt<AstType> (loc.Line, loc.Column); if (type is SimpleType) { var st = (SimpleType)type; if (st.IdentifierToken.Contains (loc.Line, loc.Column) && unit.GetNodeAt<UsingDeclaration> (loc.Line, loc.Column) == null) { endOffset = doc.LocationToOffset (st.IdentifierToken.EndLocation.Line, st.IdentifierToken.EndLocation.Column); return "keyword.semantic.type"; } return null; } if (type is ICSharpCode.NRefactory.CSharp.MemberType) { var mt = (ICSharpCode.NRefactory.CSharp.MemberType)type; if (mt.MemberNameToken.Contains (loc.Line, loc.Column) && unit.GetNodeAt<UsingDeclaration> (loc.Line, loc.Column) == null) { endOffset = doc.LocationToOffset (mt.MemberNameToken.EndLocation.Line, mt.MemberNameToken.EndLocation.Column); return "keyword.semantic.type"; } return null; } var node = unit.GetNodeAt (loc.Line, loc.Column); if (node is Identifier) { if (node.Parent is TypeDeclaration && node.Role == TypeDeclaration.Roles.Identifier) { endOffset = doc.LocationToOffset (node.EndLocation.Line, node.EndLocation.Column); return "keyword.semantic.type"; } if (node.Parent is VariableInitializer && node.Parent.Parent is FieldDeclaration || node.Parent is FixedVariableInitializer || node.Parent is EnumMemberDeclaration) { endOffset = doc.LocationToOffset (node.EndLocation.Line, node.EndLocation.Column); return "keyword.semantic.field"; } } var identifierExpression = unit.GetNodeAt<IdentifierExpression> (loc.Line, loc.Column); if (identifierExpression != null) { var result = identifierExpression.ResolveExpression (document, resolver, loc); if (result is MemberResolveResult) { var member = ((MemberResolveResult)result).ResolvedMember; if (member is IField) { endOffset = doc.LocationToOffset (identifierExpression.EndLocation.Line, identifierExpression.EndLocation.Column); return "keyword.semantic.field"; } if (member == null && result.ResolvedType != null && !string.IsNullOrEmpty (result.ResolvedType.FullName)) { endOffset = doc.LocationToOffset (identifierExpression.EndLocation.Line, identifierExpression.EndLocation.Column); return "keyword.semantic.type"; } } } var memberReferenceExpression = unit.GetNodeAt<MemberReferenceExpression> (loc.Line, loc.Column); if (memberReferenceExpression != null) { if (!memberReferenceExpression.MemberNameToken.Contains (loc.Line, loc.Column)) return null; var result = memberReferenceExpression.ResolveExpression (document, resolver, loc); if (result is MemberResolveResult) { var member = ((MemberResolveResult)result).ResolvedMember; if (member is IField) { endOffset = doc.LocationToOffset (memberReferenceExpression.MemberNameToken.EndLocation.Line, memberReferenceExpression.MemberNameToken.EndLocation.Column); return "keyword.semantic.field"; } if (member == null && result.ResolvedType != null && !string.IsNullOrEmpty (result.ResolvedType.FullName)) { endOffset = doc.LocationToOffset (memberReferenceExpression.MemberNameToken.EndLocation.Line, memberReferenceExpression.MemberNameToken.EndLocation.Column); return "keyword.semantic.type"; } } } } return null; }
Widget MonoDevelop.DesignerSupport.IOutlinedDocument.GetOutlineWidget () { if (outlineTreeView != null) return outlineTreeView; outlineTreeStore = new TreeStore (typeof(object)); outlineTreeView = new MonoDevelop.Ide.Gui.Components.PadTreeView (outlineTreeStore); var pixRenderer = new CellRendererPixbuf (); pixRenderer.Xpad = 0; pixRenderer.Ypad = 0; outlineTreeView.TextRenderer.Xpad = 0; outlineTreeView.TextRenderer.Ypad = 0; TreeViewColumn treeCol = new TreeViewColumn (); treeCol.PackStart (pixRenderer, false); treeCol.SetCellDataFunc (pixRenderer, new TreeCellDataFunc (OutlineTreeIconFunc)); treeCol.PackStart (outlineTreeView.TextRenderer, true); treeCol.SetCellDataFunc (outlineTreeView.TextRenderer, new TreeCellDataFunc (OutlineTreeTextFunc)); outlineTreeView.AppendColumn (treeCol); outlineTreeView.HeadersVisible = false; outlineTreeView.Selection.Changed += delegate { TreeIter iter; if (!outlineTreeView.Selection.GetSelected (out iter)) return; object o = outlineTreeStore.GetValue (iter, 0); int line = -1, col = -1; if (o is IType) { line = ((IType)o).BodyRegion.Start.Line; col = ((IType)o).BodyRegion.Start.Column; } else if (o is IMember) { line = ((IMember)o).BodyRegion.Start.Line; col = ((IMember)o).BodyRegion.Start.Column; } if (line > -1) { Editor.JumpTo (line, Math.Max (1, col)); } }; this.lastCU = Document.ParsedDocument; outlineTreeView.Realized += delegate { RefillOutlineStore (); }; var sw = new CompactScrolledWindow (); sw.Add (outlineTreeView); sw.ShowAll (); return sw; }
public override ParsedDocument Parse (ProjectDom dom, string fileName, string content) { ParsedDocument doc = new ParsedDocument (fileName); if(null == doc.CompilationUnit) doc.CompilationUnit = new CompilationUnit (fileName); CompilationUnit cu = (CompilationUnit)doc.CompilationUnit; DomType currentFile = null; DomProperty currentRegion = null; string eol = Environment.NewLine; Match eolMatch = eolExpression.Match (content); if (eolMatch != null && eolMatch.Success) eol = eolMatch.Groups["eol"].Value; string[] lines = content.Split (new string[]{eol}, StringSplitOptions.None); int linenum = 1; Match lineMatch; foreach (string line in lines) { lineMatch = fileHeaderExpression.Match (line.Trim()); if (lineMatch != null && lineMatch.Success) { if (currentFile != null) // Close out previous file region currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.Start.Line, currentFile.BodyRegion.Start.Column, linenum-1, int.MaxValue); if (currentRegion != null) // Close out previous chunk region currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.Start.Line, currentRegion.BodyRegion.Start.Column, linenum-1, int.MaxValue); // Create new file region currentFile = new DomType (cu, ClassType.Unknown, Modifiers.None, lastToken (lineMatch.Groups["filepath"].Value), new DomLocation (linenum, 1), string.Empty, new DomRegion (linenum, line.Length+1, linenum, int.MaxValue)); cu.Add (currentFile); } else { lineMatch = chunkExpression.Match (line); if (lineMatch != null && lineMatch.Success) { if (currentRegion != null) // Close out previous chunk region currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.Start.Line, currentRegion.BodyRegion.Start.Column, linenum-1, int.MaxValue); // Create new chunk region currentRegion = new DomProperty (lineMatch.Groups["chunk"].Value, Modifiers.None, new DomLocation (linenum, 1), new DomRegion (linenum, line.Length+1, linenum, int.MaxValue), null); currentFile.Add (currentRegion); } } ++linenum; } // Close out trailing regions if (currentFile != null) currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.Start.Line, currentFile.BodyRegion.Start.Column, Math.Max (1, linenum-2), int.MaxValue); if (currentRegion != null) currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.Start.Line, currentRegion.BodyRegion.Start.Column, Math.Max (1, linenum-2), int.MaxValue); return doc; }
void UpdateErrorUndelines (ParsedDocument parsedDocument) { if (!options.UnderlineErrors || parsedDocument == null) return; // this may be run in another thread, therefore we've to synchronize // with the gtk main loop. lock (this) { if (resetTimerId > 0) { GLib.Source.Remove (resetTimerId); resetTimerId = 0; } const uint timeout = 500; resetTimerId = GLib.Timeout.Add (timeout, delegate { lock (this) { // this runs in the gtk main loop. RemoveErrorUnderlines (); // Else we underline the error if (parsedDocument.Errors != null) { foreach (MonoDevelop.Projects.Dom.Error info in parsedDocument.Errors) UnderLineError (info); } resetTimerId = 0; } return false; }); } }
protected virtual void RefillOutlineStore (ParsedDocument doc, Gtk.TreeStore store) { XDocument xdoc = ((XmlParsedDocument)doc).XDocument; if (xdoc == null) return; BuildTreeChildren (store, Gtk.TreeIter.Zero, xdoc); }
void OnParseInformationChanged (object sender, MonoDevelop.Projects.Dom.ParsedDocumentEventArgs args) { if (this.FileName == args.FileName && args.ParsedDocument != null) { lastCU = args.ParsedDocument; OnParsedDocumentUpdated (); } }
void UpdateDocumentOutline (object sender, EventArgs args) { lastCU = Document.ParsedDocument; //limit update rate to 3s if (!refreshingOutline) { refreshingOutline = true; refillOutlineStoreId = GLib.Timeout.Add (3000, RefillOutlineStore); } }
public static MonoDevelop.Projects.Dom.INode ConvertDParserToDomNode(D_Parser.Dom.INode n, ParsedDocument doc) { //TODO: DDoc comments! if (n is DMethod) { var dm = n as DMethod; var domMethod = new DomMethod( n.Name, GetNodeModifiers(dm), dm.SpecialType == DMethod.MethodType.Constructor ? MethodModifier.IsConstructor : MethodModifier.None, FromCodeLocation(n.StartLocation), GetBlockBodyRegion(dm), GetReturnType(n)); foreach (var pn in dm.Parameters) domMethod.Add(new DomParameter(domMethod, pn.Name, GetReturnType(pn))); domMethod.AddTypeParameter(GetTypeParameters(dm)); foreach (var subNode in dm) domMethod.AddChild(ConvertDParserToDomNode(subNode, doc)); return domMethod; } else if (n is DEnum) { var de = n as DEnum; var domType = new DomType( doc.CompilationUnit, ClassType.Enum, GetNodeModifiers(de), n.Name, FromCodeLocation(n.StartLocation), BuildTypeNamespace(n), GetBlockBodyRegion(de)); foreach (var subNode in de) domType.Add(ConvertDParserToDomNode(subNode, doc) as IMember); return domType; } else if (n is DClassLike) { var dc = n as DClassLike; ClassType ct = ClassType.Unknown; switch (dc.ClassType) { case DTokens.Template: case DTokens.Class: ct = ClassType.Class; break; case DTokens.Interface: ct = ClassType.Interface; break; case DTokens.Union: case DTokens.Struct: ct = ClassType.Struct; break; } var domType = new DomType( doc.CompilationUnit, ct, GetNodeModifiers(dc), n.Name, FromCodeLocation(n.StartLocation), BuildTypeNamespace(n), GetBlockBodyRegion(dc)); domType.AddTypeParameter(GetTypeParameters(dc)); foreach (var subNode in dc) domType.Add(ConvertDParserToDomNode(subNode, doc) as IMember); return domType; } else if (n is DVariable) { var dv = n as DVariable; return new DomField(n.Name, GetNodeModifiers(dv), FromCodeLocation(n.StartLocation), GetReturnType(n)); } return null; }
static void AddTreeClassContents (TreeStore store, TreeIter parent, ParsedDocument parsedDocument, IType cls) { List<object> items = new List<object> (); foreach (object o in cls.Members) items.Add (o); items.Sort (ClassOutlineNodeComparer.CompareRegion); List<FoldingRegion> regions = new List<FoldingRegion> (); foreach (FoldingRegion fr in parsedDocument.UserRegions) //check regions inside class if (cls.BodyRegion.Contains (fr.Region)) regions.Add (fr); regions.Sort (delegate(FoldingRegion x, FoldingRegion y) { return x.Region.CompareTo (y.Region); }); IEnumerator<FoldingRegion> regionEnumerator = regions.GetEnumerator (); if (!regionEnumerator.MoveNext ()) regionEnumerator = null; FoldingRegion currentRegion = null; TreeIter currentParent = parent; foreach (object item in items) { //no regions left; quick exit if (regionEnumerator != null) { DomRegion itemRegion = ClassOutlineNodeComparer.GetRegion (item); //advance to a region that could potentially contain this member while (regionEnumerator != null && !OuterEndsAfterInner (regionEnumerator.Current.Region, itemRegion)) if (!regionEnumerator.MoveNext ()) regionEnumerator = null; //if member is within region, make sure it's the current parent. //If not, move target iter back to class parent if (regionEnumerator != null && regionEnumerator.Current.Region.Contains (itemRegion)) { if (currentRegion != regionEnumerator.Current) { currentParent = store.AppendValues (parent, regionEnumerator.Current); currentRegion = regionEnumerator.Current; } } else { currentParent = parent; } } TreeIter childIter = store.AppendValues (currentParent, item); if (item is IType) AddTreeClassContents (store, childIter, parsedDocument, (IType)item); } }
public override ParsedDocument Parse (ProjectDom dom, string fileName, string content) { using (ICSharpCode.NRefactory.IParser parser = ICSharpCode.NRefactory.ParserFactory.CreateParser (ICSharpCode.NRefactory.SupportedLanguage.CSharp, new StringReader (content))) { ParsedDocument result = new ParsedDocument (fileName); result.CompilationUnit = new MonoDevelop.Projects.Dom.CompilationUnit (fileName); parser.ParseMethodBodies = false; parser.Errors.Error += delegate(int line, int col, string message) { result.Add (new Error (ErrorType.Error, line, col, message)); }; parser.Lexer.SpecialCommentTags = ProjectDomService.SpecialCommentTags.GetNames (); parser.Lexer.EvaluateConditionalCompilation = true; if (dom != null && dom.Project != null && MonoDevelop.Ide.IdeApp.Workspace != null) { DotNetProjectConfiguration configuration = dom.Project.GetConfiguration (MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration; CSharpCompilerParameters par = configuration != null ? configuration.CompilationParameters as CSharpCompilerParameters : null; if (par != null) parser.Lexer.SetConditionalCompilationSymbols (par.DefineSymbols); } parser.Parse (); SpecialTracker tracker = new SpecialTracker (result); foreach (ICSharpCode.NRefactory.ISpecial special in parser.Lexer.SpecialTracker.CurrentSpecials) { special.AcceptVisitor (tracker, null); } foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in parser.Lexer.TagComments) { result.Add (new Tag (tagComment.Tag, tagComment.CommentText, new DomRegion (tagComment.StartPosition.Y, tagComment.StartPosition.X, tagComment.EndPosition.Y, tagComment.EndPosition.X))); } ConversionVisitior visitor = new ConversionVisitior (dom, result, parser.Lexer.SpecialTracker.CurrentSpecials); visitor.VisitCompilationUnit (parser.CompilationUnit, null); result.CompilationUnit.Tag = parser.CompilationUnit; LastUnit = parser.CompilationUnit; return result; } }
void VisitComment (ParsedDocument result, SpecialsBag.Comment comment) { var cmt = new MonoDevelop.Projects.Dom.Comment (comment.Content); cmt.CommentStartsLine = comment.StartsLine; switch (comment.CommentType) { case SpecialsBag.CommentType.Multi: cmt.CommentType = MonoDevelop.Projects.Dom.CommentType.MultiLine; cmt.OpenTag = "/*"; cmt.ClosingTag = "*/"; break; case SpecialsBag.CommentType.Single: cmt.CommentType = MonoDevelop.Projects.Dom.CommentType.SingleLine; cmt.OpenTag = "//"; break; case SpecialsBag.CommentType.Documentation: cmt.CommentType = MonoDevelop.Projects.Dom.CommentType.SingleLine; cmt.IsDocumentation = true; cmt.OpenTag = "///"; break; } cmt.Region = new DomRegion (comment.Line, comment.Col, comment.EndLine, comment.EndCol); result.Comments.Add (cmt); }
public ConversionVisitior (ProjectDom dom, MonoDevelop.Projects.Dom.ParsedDocument result, List<ISpecial> specials) { this.dom = dom; this.specials = specials; this.result = result; namespaceEndLocationStack.Push (new Location (Int32.MaxValue, Int32.MaxValue)); }
internal void SetParsedDocument (ParsedDocument newDocument, bool runInThread) { this.parsedDocument = newDocument; if (parsedDocument == null || parseInformationUpdaterWorkerThread == null) return; StopParseInfoThread (); if (runInThread) { parseInformationUpdaterWorkerThread.RunWorkerAsync (parsedDocument); } else { HandleParseInformationUpdaterWorkerThreadDoWork (null, new DoWorkEventArgs (parsedDocument)); } }
void VisitComment (ParsedDocument result, SpecialsBag.Comment comment, string[] tagComments) { var cmt = new MonoDevelop.Projects.Dom.Comment (comment.Content); cmt.CommentStartsLine = comment.StartsLine; switch (comment.CommentType) { case SpecialsBag.CommentType.Multi: cmt.CommentType = MonoDevelop.Projects.Dom.CommentType.MultiLine; cmt.OpenTag = "/*"; cmt.ClosingTag = "*/"; break; case SpecialsBag.CommentType.Single: cmt.CommentType = MonoDevelop.Projects.Dom.CommentType.SingleLine; cmt.OpenTag = "//"; break; case SpecialsBag.CommentType.Documentation: cmt.CommentType = MonoDevelop.Projects.Dom.CommentType.SingleLine; cmt.IsDocumentation = true; cmt.OpenTag = "///"; break; } cmt.Region = new DomRegion (comment.Line, comment.Col, comment.EndLine, comment.EndCol); result.Comments.Add (cmt); foreach (string tag in tagComments) { int idx = comment.Content.IndexOf (tag); if (idx < 0) continue; result.Add (new Tag (tag, comment.Content, cmt.Region)); } }
public SpecialTracker (ParsedDocument result) { this.result = result; }
void VisitPreprocessorDirective (ParsedDocument result, SpecialsBag.PreProcessorDirective directive) { DomLocation loc = new DomLocation (directive.Line, directive.Col); switch (directive.Cmd) { case Tokenizer.PreprocessorDirective.If: conditionalRegions.Push (new ConditionalRegion (visitor.Text)); ifBlocks.Push (directive); ConditionalRegion.Start = loc; break; case Tokenizer.PreprocessorDirective.Elif: CloseConditionBlock (new DomLocation (directive.EndLine, directive.EndCol)); if (ConditionalRegion != null) ConditionalRegion.ConditionBlocks.Add (new ConditionBlock (visitor.Text, loc)); break; case Tokenizer.PreprocessorDirective.Else: CloseConditionBlock (new DomLocation (directive.EndLine, directive.EndCol)); if (ConditionalRegion != null) ConditionalRegion.ElseBlock = new DomRegion (loc, DomLocation.Empty); break; case Tokenizer.PreprocessorDirective.Endif: DomLocation endLoc = new DomLocation (directive.EndLine, directive.EndCol); CloseConditionBlock (endLoc); if (ConditionalRegion != null && !ConditionalRegion.ElseBlock.Start.IsEmpty) ConditionalRegion.ElseBlock = new DomRegion (ConditionalRegion.ElseBlock.Start, endLoc); AddCurRegion (result, directive.EndLine, directive.EndCol); if (ifBlocks.Count > 0) { var ifBlock = ifBlocks.Pop (); DomRegion dr = new DomRegion (ifBlock.Line, ifBlock.Col, directive.EndLine, directive.EndCol); result.Add (new FoldingRegion ("#if " + ifBlock.Arg.Trim (), dr, FoldType.UserRegion, false)); foreach (var d in elifBlocks) { dr.Start = new DomLocation (d.Line, d.Col); result.Add (new FoldingRegion ("#elif " + ifBlock.Arg.Trim (), dr, FoldType.UserRegion, false)); } if (elseBlock != null) { dr.Start = new DomLocation (elseBlock.Line, elseBlock.Col); result.Add (new FoldingRegion ("#else", dr, FoldType.UserRegion, false)); } } elseBlock = null; break; case Tokenizer.PreprocessorDirective.Define: result.Add (new PreProcessorDefine (directive.Arg, loc)); break; case Tokenizer.PreprocessorDirective.Region: regions.Push (directive); break; case Tokenizer.PreprocessorDirective.Endregion: if (regions.Count > 0) { var start = regions.Pop (); DomRegion dr = new DomRegion (start.Line, start.Col, directive.EndLine, directive.EndCol); result.Add (new FoldingRegion (start.Arg, dr, FoldType.UserRegion, true)); } break; } }
void UpdateDocumentOutline (object sender, EventArgs args) { bool refreshNow = lastCU == null; lastCU = Document.ParsedDocument; if (!refreshingOutline) { refreshingOutline = true; if (refreshNow) { RefillOutlineStore (); } else { //limit update rate to 1s GLib.Timeout.Add (1000, new GLib.TimeoutHandler (RefillOutlineStore)); } } }
public unsafe ParsedDocument Parse (string fileName, string content) { var regionStack = new Stack<Tuple<string, DomLocation>> (); var result = new ParsedDocument (fileName); bool inSingleComment = false, inMultiLineComment = false; bool inString = false, inVerbatimString = false; bool inChar = false; bool inLineStart = true, hasStartedAtLine = false; int line = 1, column = 1; var startLoc = DomLocation.Empty; fixed (char* startPtr = content) { char* endPtr = startPtr + content.Length; char* ptr = startPtr; char* beginPtr = ptr; while (ptr < endPtr) { switch (*ptr) { case '#': if (!inLineStart) break; ptr++; if (StartsIdentifier (ptr, endPtr, "region")) { var regionLocation = new DomLocation (line, column); column++; ptr += "region".Length; column += "region".Length; SkipWhitespaces (ref ptr, endPtr, ref column); regionStack.Push (Tuple.Create (ReadToEol (content, ref ptr, endPtr, ref line, ref column), regionLocation)); continue; } else if (StartsIdentifier (ptr, endPtr, "endregion")) { column++; ptr += "endregion".Length; column += "endregion".Length; if (regionStack.Count > 0) { var beginRegion = regionStack.Pop (); result.Add (new FoldingRegion ( beginRegion.Item1, new DomRegion (beginRegion.Item2.Line, beginRegion.Item2.Column, line, column), FoldType.UserRegion, true)); } continue; } else { column++; } break; case '/': if (inString || inChar || inVerbatimString || inMultiLineComment || inSingleComment) break; if (ptr + 1 < endPtr) { char nextCh = *(ptr + 1); if (nextCh == '/') { hasStartedAtLine = inLineStart; beginPtr = ptr + 2; startLoc = new DomLocation (line, column); ptr++; column++; inSingleComment = true; } else if (nextCh == '*') { hasStartedAtLine = inLineStart; beginPtr = ptr + 2; startLoc = new DomLocation (line, column); ptr++; column++; inMultiLineComment = true; } } break; case '*': if (inString || inChar || inVerbatimString || inSingleComment) break; if (inMultiLineComment && ptr + 1 < endPtr) { if (ptr + 1 < endPtr && *(ptr + 1) == '/') { ptr += 2; column += 2; inMultiLineComment = false; result.Add (new Comment () { Region = new DomRegion (startLoc, new DomLocation (line, column)), CommentType = CommentType.MultiLine, Text = content.Substring ((int)(beginPtr - startPtr), (int)(ptr - beginPtr)), CommentStartsLine = hasStartedAtLine }); continue; } } break; case '@': if (inString || inChar || inVerbatimString || inSingleComment || inMultiLineComment) break; if (ptr + 1 < endPtr && *(ptr + 1) == '"') { ptr++; column++; inVerbatimString = true; } break; case '\n': if (inSingleComment) { bool isDocumentation = *beginPtr == '/'; if (isDocumentation) beginPtr++; result.Add (new Comment () { Region = new DomRegion (startLoc, new DomLocation (line, column)), CommentType = CommentType.SingleLine, Text = content.Substring ((int)(beginPtr - startPtr), (int)(ptr - beginPtr)), CommentStartsLine = hasStartedAtLine, IsDocumentation = isDocumentation }); inSingleComment = false; } inString = false; inChar = false; inLineStart = true; line++; column = 1; ptr++; continue; case '\r': if (ptr + 1 < endPtr && *(ptr + 1) == '\n') ptr++; goto case '\n'; case '\\': if (inString || inChar) ptr++; break; case '"': if (inSingleComment || inMultiLineComment || inChar) break; if (inVerbatimString) { if (ptr + 1 < endPtr && *(ptr + 1) == '"') { ptr++; column++; break; } inVerbatimString = false; break; } inString = !inString; break; case '\'': if (inSingleComment || inMultiLineComment || inString || inVerbatimString) break; inChar = !inChar; break; } column++; ptr++; } } return result; }
public ParsedDocumentEventArgs(ParsedDocument parsedDocument) { this.ParsedDocument = parsedDocument; }