/// <summary> /// Creates a new node provider /// </summary> /// <param name="parser"></param> /// <param name="buffer">buffer to watch</param> public NodeProvider(ProjectHandler project, string filename, TypeResolver type_resolver) { Project = project; this.type_resolver = type_resolver; Filename = filename; // we need to run rebuildNodes on a separate thread. Using timer // for this seems to be an overkill, but we need the timer anyway so - why not parserTimer = new Timer(rebuildNodes, null, 0, Timeout.Infinite); }
/// <summary> /// Retrieves or creates a node provider for a buffer /// </summary> /// <param name="buffer"></param> /// <returns></returns> public NodeProvider GetNodeProvider(ITextBuffer buffer) { NodeProvider provider; if (!buffer.Properties.TryGetProperty(typeof(NodeProvider), out provider)) { var adapter = editorFactoryService.GetBufferAdapter(buffer); string filename; uint format; ErrorHandler.ThrowOnFailure(((IPersistFileFormat)adapter).GetCurFile(out filename, out format)); IVsHierarchy hier; uint itemId; IntPtr docData; uint cookie; GlobalServices.RDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, filename, out hier, out itemId, out docData, out cookie); if (IntPtr.Zero != docData) { Marshal.Release(docData); } object objDirectory; ErrorHandler.ThrowOnFailure(hier.GetProperty((uint)VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out objDirectory)); var project_directory = (string)objDirectory; ProjectHandler project; lock (projects) { if (!projects.TryGetValue(project_directory, out project)) { project = new ProjectHandler(this, template_directory, tags, filters, project_directory); projects.Add(project_directory, project); } } provider = project.GetNodeProvider(project_directory, buffer, hier, filename); } return(provider); }