internal static ParseProjectContent CreateUninitalized(IProject project) { ParseProjectContent newProjectContent = new ParseProjectContent(); newProjectContent.project = project; newProjectContent.Language = project.LanguageProperties; newProjectContent.initializing = true; IProjectContent mscorlib = ParserService.GetRegistryForReference(new ReferenceProjectItem(project, "mscorlib")).Mscorlib; newProjectContent.AddReferencedContent(mscorlib); return(newProjectContent); }
public static IProjectContent GetExistingProjectContentForReference(ReferenceProjectItem item) { if (item is ProjectReferenceProjectItem) { if (((ProjectReferenceProjectItem)item).ReferencedProject == null) { return(null); } return(ParserService.GetProjectContent(((ProjectReferenceProjectItem)item).ReferencedProject)); } return(GetRegistryForReference(item).GetExistingProjectContent(item.FileName)); }
internal void ReInitialize1(IProgressMonitor progressMonitor) { lock (ReferencedContents) { ReferencedContents.Clear(); AddReferencedContent(ParserService.GetRegistryForReference(new ReferenceProjectItem(project, "mscorlib")).Mscorlib); } // prevent adding event handler twice ProjectService.ProjectItemAdded -= OnProjectItemAdded; ProjectService.ProjectItemRemoved -= OnProjectItemRemoved; initializing = true; Initialize1(progressMonitor); initializing = false; }
void AddReference(ReferenceProjectItem reference, bool updateInterDependencies) { try { AddReferencedContent(ParserService.GetProjectContentForReference(reference)); if (updateInterDependencies) { UpdateReferenceInterDependencies(); } OnReferencedContentsChanged(EventArgs.Empty); } catch (Exception e) { MessageService.ShowError(e); } }
static void ParserService_ParseInformationUpdated(object sender, ParseInformationEventArgs e) { if (e.NewParseInformation == ParserService.GetExistingParseInformation(e.FileName)) { // Call UpdateCommentTags only for the main parse information (if a file is in multiple projects), // and only if the results haven't already been replaced with a more recent ParseInformation. if (e.NewCompilationUnit != null) { UpdateCommentTags(e.FileName, e.NewCompilationUnit.TagComments); } else { UpdateCommentTags(e.FileName, new List <TagComment>()); } } }
internal void Initialize2(IProgressMonitor progressMonitor) { if (!initializing) { return; } int progressStart = progressMonitor.WorkDone; ParseableFileContentEnumerator enumerator = new ParseableFileContentEnumerator(project); try { progressMonitor.TaskName = "${res:ICSharpCode.SharpDevelop.Internal.ParserService.Parsing} " + project.Name + "..."; IProjectContent[] referencedContents; lock (this.ReferencedContents) { referencedContents = new IProjectContent[this.ReferencedContents.Count]; this.ReferencedContents.CopyTo(referencedContents, 0); } foreach (IProjectContent referencedContent in referencedContents) { if (referencedContent is ReflectionProjectContent) { ((ReflectionProjectContent)referencedContent).InitializeReferences(); } } while (enumerator.MoveNext()) { int i = enumerator.Index; if ((i % 5) == 2) { progressMonitor.WorkDone = progressStart + i; } ParserService.ParseFile(this, enumerator.CurrentFileName, enumerator.CurrentFileContent, true); if (!initializing) { return; } } } finally { initializing = false; progressMonitor.WorkDone = progressStart + enumerator.ItemCount; enumerator.Dispose(); } }
void AddReference(ReferenceProjectItem reference, bool updateInterDependencies) { try { AddReferencedContent(ParserService.GetProjectContentForReference(reference)); if (updateInterDependencies) { UpdateReferenceInterDependencies(); } OnReferencedContentsChanged(EventArgs.Empty); // Refresh the reference if required. // If the user removes the reference and then re-adds it, there might be other references // in the project depending on it, so we do the refresh after the old reference was added. ParserService.RefreshProjectContentForReference(reference); } catch (Exception e) { MessageService.ShowError(e); } }
public static void Reparse(IProject project, bool initReferences, bool parseCode) { if (jobs == null) { return; // do nothing if service wasn't initialized (e.g. some unit tests) } ParseProjectContent pc = ParserService.GetProjectContent(project) as ParseProjectContent; if (pc != null) { if (initReferences) { lock (reParse1) { if (!reParse1.Contains(pc)) { LoggingService.Debug("Enqueue for reinitializing references: " + project); reParse1.Add(pc); jobs.AddJob(new JobTask(pm => ReInitializeReferences(pc, pm), GetLoadReferenceTaskTitle(project.Name), 10 )); } } } if (parseCode) { lock (reParse2) { if (!reParse2.Contains(pc)) { LoggingService.Debug("Enqueue for reparsing code: " + project); reParse2.Add(pc); jobs.AddJob(new JobTask(pm => ReparseCode(pc, pm), GetParseTaskTitle(project.Name), pc.GetInitializationWorkAmount() )); } } } jobs.StartRunningIfRequired(); } }
void OnProjectItemRemoved(object sender, ProjectItemEventArgs e) { if (e.Project != project) { return; } ReferenceProjectItem reference = e.ProjectItem as ReferenceProjectItem; if (reference != null) { try { IProjectContent referencedContent = AssemblyParserService.GetExistingProjectContentForReference(reference); if (referencedContent != null) { lock (ReferencedContents) { ReferencedContents.Remove(referencedContent); } OnReferencedContentsChanged(EventArgs.Empty); } } catch (Exception ex) { MessageService.ShowException(ex); } } if (e.ProjectItem.ItemType == ItemType.Import) { UpdateDefaultImports(project.Items); } else if (e.ProjectItem.ItemType == ItemType.Compile) { ParserService.ClearParseInformation(e.ProjectItem.FileName); } }
void OnProjectItemAdded(object sender, ProjectItemEventArgs e) { if (e.Project != project) { return; } ReferenceProjectItem reference = e.ProjectItem as ReferenceProjectItem; if (reference != null) { if (reference.ItemType == ItemType.COMReference) { System.Windows.Forms.MethodInvoker action = delegate { // Compile project to ensure interop library is generated project.Save(); // project is not yet saved when ItemAdded fires, so save it here TaskService.BuildMessageViewCategory.AppendText("\n${res:MainWindow.CompilerMessages.CreatingCOMInteropAssembly}\n"); BuildCallback afterBuildCallback = delegate { lock (callAfterAddComReference) { if (callAfterAddComReference.Count > 0) { // run next enqueued action callAfterAddComReference.Dequeue()(); } else { buildingComReference = false; ParserService.Reparse(project, true, false); } } }; BuildEngine.BuildInGui(project, new BuildOptions(BuildTarget.ResolveComReferences, afterBuildCallback)); }; // enqueue actions when adding multiple COM references so that multiple builds of the same project // are not started parallely lock (callAfterAddComReference) { if (buildingComReference) { callAfterAddComReference.Enqueue(action); } else { buildingComReference = true; action(); } } } else { ParserService.Reparse(project, true, false); } } if (e.ProjectItem.ItemType == ItemType.Import) { UpdateDefaultImports(project.Items); } else if (e.ProjectItem.ItemType == ItemType.Compile) { if (System.IO.File.Exists(e.ProjectItem.FileName)) { ParserService.EnqueueForParsing(e.ProjectItem.FileName); } } }
void OnProjectItemAdded(object sender, ProjectItemEventArgs e) { if (e.Project != project) { return; } ReferenceProjectItem reference = e.ProjectItem as ReferenceProjectItem; if (reference != null) { if (reference.ItemType == ItemType.COMReference) { System.Windows.Forms.MethodInvoker action = delegate { // Compile project to ensure interop library is generated project.Save(); // project is not yet saved when ItemAdded fires, so save it here TaskService.BuildMessageViewCategory.AppendText("\n${res:MainWindow.CompilerMessages.CreatingCOMInteropAssembly}\n"); BuildCallback callback = delegate { System.Threading.ThreadPool.QueueUserWorkItem(AddReference, reference); lock (callAfterAddComReference) { if (callAfterAddComReference.Count > 0) { callAfterAddComReference.Dequeue()(); } else { buildingComReference = false; } } }; project.StartBuild(new BuildOptions(BuildTarget.ResolveComReferences, callback)); }; lock (callAfterAddComReference) { if (buildingComReference) { callAfterAddComReference.Enqueue(action); } else { buildingComReference = true; action(); } } } else { System.Threading.ThreadPool.QueueUserWorkItem(AddReference, reference); } } if (e.ProjectItem.ItemType == ItemType.Import) { UpdateDefaultImports(project.Items); } else if (e.ProjectItem.ItemType == ItemType.Compile) { if (System.IO.File.Exists(e.ProjectItem.FileName)) { ParserService.EnqueueForParsing(e.ProjectItem.FileName); } } }
internal void Initialize2(IProgressMonitor progressMonitor) { if (!initializing) { return; } try { IProjectContent[] referencedContents; lock (this.ReferencedContents) { referencedContents = new IProjectContent[this.ReferencedContents.Count]; this.ReferencedContents.CopyTo(referencedContents, 0); } foreach (IProjectContent referencedContent in referencedContents) { if (referencedContent is ReflectionProjectContent) { ((ReflectionProjectContent)referencedContent).InitializeReferences(referencedContents); } } ParseableFileContentFinder finder = new ParseableFileContentFinder(); var fileContents = ( from p in project.Items.AsParallel().WithCancellation(progressMonitor.CancellationToken) where !ItemType.NonFileItemTypes.Contains(p.ItemType) && !String.IsNullOrEmpty(p.FileName) select FileName.Create(p.FileName) ).ToList(); object progressLock = new object(); double fileCountInverse = 1.0 / fileContents.Count; Parallel.ForEach( fileContents, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount * 2, CancellationToken = progressMonitor.CancellationToken }, fileName => { // Don't read files we don't have a parser for. // This avoids loading huge files (e.g. sdps) when we have no intention of parsing them. if (ParserService.GetParser(fileName) != null) { ITextBuffer content = finder.Create(fileName); if (content != null) { ParserService.ParseFile(this, fileName, content); } } lock (progressLock) { progressMonitor.Progress += fileCountInverse; } } ); } finally { initializing = false; progressMonitor.Progress = 1; } }