public CSharpCompletion() { projectContent = new CSharpProjectContent(); var assemblies = new List<Assembly> { typeof(object).Assembly, // mscorlib typeof(Uri).Assembly, // System.dll typeof(Enumerable).Assembly, // System.Core.dll typeof(System.Xml.XmlDocument).Assembly, // System.Xml.dll typeof(Sandbox.Common.ObjectBuilders.MyObjectBuilder_AdvancedDoor).Assembly, // SpaceEngineers.ObjectBuilders.dll typeof(SpaceEngineers.Game.ModAPI.IMyButtonPanel).Assembly, // SpaceEngineers.Game.dll typeof(Sandbox.MySandboxGame).Assembly, // Sandbox.Game.dll typeof(Sandbox.ModAPI.MyAPIGateway).Assembly, // Sandbox.Common.dll typeof(Sandbox.Graphics.GUI.MyGuiSandbox).Assembly, // Sandbox.Graphics.dll typeof(VRage.MyModelData).Assembly, // VRage.dll typeof(VRage.Exceptions).Assembly, // VRage.Library.dll typeof(VRageMath.MathHelper).Assembly, // VRage.Math typeof(VRage.Game.ObjectBuilders.MyObjectBuilder_EntityStat).Assembly, //VRage.Game }; var unresolvedAssemblies = new IUnresolvedAssembly[assemblies.Count]; Stopwatch total = Stopwatch.StartNew(); Parallel.For( 0, assemblies.Count, delegate(int i) { var loader = new CecilLoader(); var path = assemblies[i].Location; loader.DocumentationProvider = GetXmlDocumentation(assemblies[i].Location); unresolvedAssemblies[i] = loader.LoadAssemblyFile(assemblies[i].Location); }); Debug.WriteLine("Init project content, loading base assemblies: " + total.Elapsed); projectContent = projectContent.AddAssemblyReferences((IEnumerable<IUnresolvedAssembly>)unresolvedAssemblies); }
IClass GetClassIfTypeNameIsNotEmpty(IProjectContent projectContent, string modelTypeName) { if (!String.IsNullOrEmpty(modelTypeName)) { return projectContent.GetClass(modelTypeName, 0); } return null; }
public ProjectContentContainer(MSBuildBasedProject project, IProjectContent initialProjectContent) { if (project == null) throw new ArgumentNullException("project"); this.project = project; this.projectContent = initialProjectContent.SetAssemblyName(project.AssemblyName).SetLocation(project.OutputAssemblyFullPath); this.assemblyModel = (IUpdateableAssemblyModel)project.AssemblyModel; this.assemblyModel.AssemblyName = this.projectContent.AssemblyName; this.assemblyModel.FullAssemblyName = this.projectContent.FullAssemblyName; this.cacheFileName = GetCacheFileName(project.FileName); SD.ProjectService.ProjectItemAdded += OnProjectItemAdded; SD.ProjectService.ProjectItemRemoved += OnProjectItemRemoved; SD.AssemblyParserService.AssemblyRefreshed += OnAssemblyRefreshed; List<FileName> filesToParse = new List<FileName>(); foreach (var file in project.Items.OfType<FileProjectItem>()) { if (IsParseableFile(file)) { var fileName = file.FileName; parserService.AddOwnerProject(fileName, project, startAsyncParse: false, isLinkedFile: file.IsLink); filesToParse.Add(fileName); } } SD.ParserService.LoadSolutionProjectsThread.AddJob( monitor => Initialize(monitor, filesToParse), "Loading " + project.Name + "...", filesToParse.Count + LoadingReferencesWorkAmount); }
void CreateCompilationUnit(IProjectContent projectContent, string fileName) { compilationUnit = new DefaultCompilationUnit(projectContent); compilationUnit.FileName = fileName; CreateUsingScopeForCompilationUnit(fileName); }
public override void Load(OpenedFile file, Stream stream) { XmlDocument doc = new XmlDocument(); doc.Load(stream); projectContent = ParserService.GetProjectContent(ProjectService.CurrentProject); canvas.LoadFromXml(doc, projectContent); }
IProject GetProject(IProjectContent projectContent) { if (this.project.ProjectContent == projectContent) { return project; } return null; }
public VoidClass(IProjectContent pc) : base(new DefaultCompilationUnit(pc), VoidName) { this.ClassType = ClassType.Struct; this.Modifiers = ModifierEnum.Public | ModifierEnum.Sealed; Freeze(); }
public ParseInformationEventArgs(string fileName, IProjectContent projectContent, ICompilationUnit oldCompilationUnit, ICompilationUnit newCompilationUnit) { this.fileName = fileName; this.projectContent = projectContent; this.oldCompilationUnit = oldCompilationUnit; this.newCompilationUnit = newCompilationUnit; }
/// <summary> /// Note that projectContent may be different to the IClass.ProjectContent since the class /// is retrieved from the namespace contents and could belong to a separate project or /// referenced assembly. /// </summary> public CodeType(IProjectContent projectContent, IClass c) : base(c) { this.Class = c; this.ProjectContent = projectContent; InfoLocation = GetInfoLocation(projectContent, c); }
public CodeNamespace(IProjectContent projectContent, NamespaceName namespaceName) { this.projectContent = projectContent; this.namespaceName = namespaceName; this.InfoLocation = global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationExternal; this.Language = projectContent.GetCodeModelLanguage(); }
global::EnvDTE.vsCMInfoLocation GetInfoLocation(IProjectContent projectContent, IClass c) { if (projectContent.Project == c.ProjectContent.Project) { return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationProject; } return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationExternal; }
public NRefactoryASTConvertVisitor(IProjectContent projectContent, SupportedLanguage language) { if (language == SupportedLanguage.VBNet) cu = new VBNetCompilationUnit(projectContent); else cu = new DefaultCompilationUnit(projectContent); }
public override IEnumerable<MemberReference> FindReferences (MonoDevelop.Projects.Project project, IProjectContent content, IEnumerable<FilePath> files, IProgressMonitor monitor, IEnumerable<object> searchedMembers) { // TODO: Type system conversion. yield break; // var editor = TextFileProvider.Instance.GetTextEditorData (fileName); // AspNetAppProject project = dom.Project as AspNetAppProject; // if (project == null) // yield break; // // var unit = AspNetParserService.GetCompileUnit (project, fileName, true); // if (unit == null) // yield break; // var refman = new DocumentReferenceManager (project); // // var parsedAspDocument = (AspNetParsedDocument)new AspNetParser ().Parse (dom, fileName, editor.Text); // refman.Doc = parsedAspDocument; // // var usings = refman.GetUsings (); // var documentInfo = new DocumentInfo (dom, unit, usings, refman.GetDoms ()); // // var builder = new AspLanguageBuilder (); // // // var buildDocument = new Mono.TextEditor.TextDocument (); // var offsetInfos = new List<LocalDocumentInfo.OffsetInfo> (); // buildDocument.Text = builder.BuildDocumentString (documentInfo, editor, offsetInfos, true); // var parsedDocument = AspLanguageBuilder.Parse (dom, fileName, buildDocument.Text); // foreach (var member in searchedMembers) { // foreach (var reference in SearchMember (member, dom, fileName, editor, buildDocument, offsetInfos, parsedDocument)) { // yield return reference; // } // } }
public ICompilationUnit Parse(IProjectContent projectContent, string fileName, string fileContent) { LoggingService.Debug("Parse " + fileName); int lineCount = 1; foreach (char c in fileContent) { if (c == '\n') { lineCount++; } } int[] lineLength = new int[lineCount]; int length = 0; int i = 0; foreach (char c in fileContent) { if (c == '\n') { lineLength[i] = length; i += 1; length = 0; } else if (c != '\r') { length += 1; } } lineLength[i] = length; BooCompiler compiler = new BooCompiler(); compiler.Parameters.Input.Add(new StringInput(fileName, fileContent)); ICompilationUnit cu = Parse(projectContent, fileName, lineLength, compiler); AddCommentsAndRegions(cu, fileContent, fileName); return cu; }
public CSharpCompletion() { projectContent = new CSharpProjectContent(); var assemblies = new List<Assembly> { typeof(object).Assembly, // mscorlib typeof(Uri).Assembly, // System.dll typeof(Enumerable).Assembly, // System.Core.dll // typeof(System.Xml.XmlDocument).Assembly, // System.Xml.dll // typeof(System.Drawing.Bitmap).Assembly, // System.Drawing.dll // typeof(Form).Assembly, // System.Windows.Forms.dll // typeof(ICSharpCode.NRefactory.TypeSystem.IProjectContent).Assembly, }; var unresolvedAssemblies = new IUnresolvedAssembly[assemblies.Count]; Stopwatch total = Stopwatch.StartNew(); Parallel.For( 0, assemblies.Count, delegate(int i) { var loader = new CecilLoader(); var path = assemblies[i].Location; loader.DocumentationProvider = GetXmlDocumentation(assemblies[i].Location); unresolvedAssemblies[i] = loader.LoadAssemblyFile(assemblies[i].Location); }); Debug.WriteLine("Init project content, loading base assemblies: " + total.Elapsed); projectContent = projectContent.AddAssemblyReferences((IEnumerable<IUnresolvedAssembly>)unresolvedAssemblies); }
public GetClassReturnType(IProjectContent content, string fullName, int typeArgumentCount, GetClassOptions options) { this.content = content; this.typeArgumentCount = typeArgumentCount; SetFullyQualifiedName(fullName); this.options = options; }
public VoidTypeDefinition(IProjectContent projectContent) : base(projectContent, "System", "Void") { this.Kind = TypeKind.Void; this.Accessibility = Accessibility.Public; this.IsSealed = true; }
bool Initialize(ParseInformation parseInfo, int caretLine, int caretColumn) { if (parseInfo == null) { return false; } this.cu = parseInfo.CompilationUnit; if (cu == null) { return false; } this.pc = cu.ProjectContent; this.caretLine = caretLine; this.caretColumn = caretColumn; this.callingClass = GetCallingClass(pc); callingMember = ResolveCurrentMember(callingClass); if (callingMember == null) { if (cu != parseInfo.CompilationUnit) { IClass olderClass = GetCallingClass(parseInfo.CompilationUnit.ProjectContent); if (olderClass != null && callingClass == null) { this.callingClass = olderClass; } callingMember = ResolveCurrentMember(olderClass); } } if (callingMember != null) { if (caretLine > callingMember.BodyRegion.EndLine) { this.caretLine = callingMember.BodyRegion.EndLine; this.caretColumn = callingMember.BodyRegion.EndColumn - 1; } else if (caretLine == callingMember.BodyRegion.EndLine && caretColumn >= callingMember.BodyRegion.EndColumn) { this.caretColumn = callingMember.BodyRegion.EndColumn - 1; } } return true; }
public ResolveVisitor(BooResolver resolver) { this.resolver = resolver; this.callingClass = resolver.CallingClass; this.projectContent = resolver.ProjectContent; this.cu = resolver.CompilationUnit; }
static void AddAttributes(IProjectContent pc, IList<IAttribute> list, CustomAttributeCollection attributes) { foreach (CustomAttribute att in attributes) { DefaultAttribute a = new DefaultAttribute(CreateType(pc, null, att.Constructor.DeclaringType)); // Currently Cecil returns string instead of TypeReference for typeof() arguments to attributes var parameters = att.Constructor.Parameters; for (int i = 0; i < Math.Min(parameters.Count, att.ConstructorParameters.Count); i++) { object o = att.ConstructorParameters[i]; if (parameters[i].ParameterType.FullName == "System.Type" && o is string) { try { a.PositionalArguments.Add(ReflectionReturnType.Parse(pc, (string)o)); } catch (ReflectionTypeNameSyntaxError ex) { LoggingService.Warn("parsing '" + o + "'", ex); a.PositionalArguments.Add(o); } } else { a.PositionalArguments.Add(o); } } foreach (DictionaryEntry entry in att.Properties) { a.NamedArguments.Add(entry.Key.ToString(), entry.Value); } list.Add(a); } }
public ElementReturnType(IProjectContent pc, IReturnType enumerableType) { if (pc == null) throw new ArgumentNullException("pc"); this.enumerableType = enumerableType; this.pc = pc; }
public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent) { var modelTypeLocater = new RazorCSharpModelTypeLocater(fileContent); return new RazorCompilationUnit(projectContent) { ModelTypeName = modelTypeLocater.ModelTypeName }; }
public CodeNamespace(IProjectContent projectContent, NamespaceName namespaceName) { this.projectContent = projectContent; this.namespaceName = namespaceName; this.InfoLocation = vsCMInfoLocation.vsCMInfoLocationExternal; this.Language = GetLanguage(projectContent); }
public VoidTypeDefinition(IProjectContent projectContent) : base(projectContent, "System", "Void") { this.ClassType = ClassType.Struct; this.Accessibility = Accessibility.Public; this.IsSealed = true; }
internal static IClass FindMyFormsClass(IProjectContent pc, string myNamespace) { if (pc != null) { return pc.GetClass(myNamespace + ".MyForms", 0); } return null; }
static object GetValue(IProjectContent pc, IEntity member, CustomAttributeArgument argument) { if (argument.Value is TypeReference) return CreateType(pc, member, (TypeReference)argument.Value); else return argument.Value; }
static void AddAttributes(IProjectContent pc, IList<IAttribute> list, CustomAttributeCollection attributes) { foreach (CustomAttribute att in attributes) { DefaultAttribute a = new DefaultAttribute(att.Constructor.DeclaringType.FullName); // TODO: add only attributes marked "important", and include attribute arguments list.Add(a); } }
protected void UpdateCodeFile(string fileName, string code) { var oldFile = projectContent.GetFile(fileName); Assert.IsNotNull(oldFile); var newFile = Parse(fileName, code); projectContent = projectContent.AddOrUpdateFiles(newFile); testProject.NotifyParseInformationChanged(oldFile, newFile); }
public MemberLookup(ITypeResolveContext context, ITypeDefinition currentTypeDefinition, IProjectContent currentProject) { if (context == null) throw new ArgumentNullException("context"); this.context = context; this.currentTypeDefinition = currentTypeDefinition; this.currentProject = currentProject; }
/// <summary> /// Returns null if base type is not an interface. /// </summary> public static CodeInterface CreateFromBaseType(IProjectContent projectContent, IReturnType baseType) { IClass baseTypeClass = baseType.GetUnderlyingClass(); if (baseTypeClass.ClassType == ClassType.Interface) { return new CodeInterface(projectContent, baseType, baseTypeClass); } return null; }
private static ICompilationUnit Parse(IParser p, string fileName, IProjectContent projectContent) { p.Lexer.SpecialCommentTags = LexerTags; p.ParseMethodBodies = false; p.Parse(); var visitor = new NRefactoryASTConvertVisitor(projectContent, SupportedLanguage.CSharp) { Specials = p.Lexer.SpecialTracker.CurrentSpecials }; visitor.VisitCompilationUnit(p.CompilationUnit, null); visitor.Cu.FileName = fileName; visitor.Cu.ErrorsDuringCompile = p.Errors.Count > 0; RetrieveRegions(visitor.Cu, p.Lexer.SpecialTracker); AddCommentTags(visitor.Cu, p.Lexer.TagComments); return(visitor.Cu); }
public SystemTypes(IProjectContent pc) { _pc = pc; Object = CreateFromName("System.Object"); Delegate = CreateFromName("System.Delegate"); ValueType = CreateFromName("System.ValueType"); Enum = CreateFromName("System.Enum"); Boolean = CreateFromName("System.Boolean"); Int32 = CreateFromName("System.Int32"); String = CreateFromName("System.String"); Array = CreateFromName("System.Array"); Attribute = CreateFromName("System.Attribute"); Type = CreateFromName("System.Type"); AsyncCallback = CreateFromName("System.AsyncCallback"); IAsyncResult = CreateFromName("System.IAsyncResult"); }
/// <summary> /// Parses the python code and returns an ICompilationUnit. /// </summary> public ICompilationUnit Parse(IProjectContent projectContent, string fileName, string fileContent) { if (fileContent != null) { try { PythonAst ast = CreateAst(fileName, fileContent); PythonAstWalker walker = new PythonAstWalker(projectContent, fileName); walker.Walk(ast); return(walker.CompilationUnit); } catch (InvalidCastException) { // Ignore. } } DefaultCompilationUnit compilationUnit = new DefaultCompilationUnit(projectContent); compilationUnit.FileName = fileName; return(compilationUnit); }
protected CSharpCompletionEngineBase(IProjectContent content, ICompletionContextProvider completionContextProvider, CSharpTypeResolveContext ctx) { if (content == null) { throw new ArgumentNullException("content"); } if (ctx == null) { throw new ArgumentNullException("ctx"); } if (completionContextProvider == null) { throw new ArgumentNullException("completionContextProvider"); } this.ProjectContent = content; this.CompletionContextProvider = completionContextProvider; this.ctx = ctx; }
public CodeCompletionItem(IEntity entity, IProjectContent projectContent) { if (entity == null) { throw new ArgumentNullException("entity"); } _entity = entity; _projectContent = projectContent; IAmbience ambience = AmbienceService.GetCurrentAmbience(); ambience.ConversionFlags = entity is IClass ? ConversionFlags.ShowTypeParameterList : ConversionFlags.None; Text = entity.Name; Content = ambience.Convert(entity); Overloads = 1; Priority = CodeCompletionDataUsageCache.GetPriority(entity.DotNetName, true); }
public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContentBuffer) { string fileContent = fileContentBuffer.Text; LoggingService.Debug("Parse " + fileName); int lineCount = 1; foreach (char c in fileContent) { if (c == '\n') { lineCount++; } } int[] lineLength = new int[lineCount]; int length = 0; int i = 0; foreach (char c in fileContent) { if (c == '\n') { lineLength[i] = length; i += 1; length = 0; } else if (c != '\r') { length += 1; } } lineLength[i] = length; ICompilationUnit cu; lock (typeof(BooCompiler)) { BooCompiler compiler = new BooCompiler(); compiler.Parameters.Input.Add(new StringInput(fileName, fileContent)); cu = Parse(projectContent, fileName, lineLength, compiler); } AddCommentsAndRegions(cu, fileContent, fileName); return(cu); }
bool Initialize(ParseInformation parseInfo, int caretLine, int caretColumn) { if (parseInfo == null) { return(false); } this.cu = parseInfo.MostRecentCompilationUnit; if (cu == null) { return(false); } this.pc = cu.ProjectContent; this.caretLine = caretLine; this.caretColumn = caretColumn; this.callingClass = GetCallingClass(pc); callingMember = ResolveCurrentMember(callingClass); if (callingMember == null) { if (cu != parseInfo.BestCompilationUnit) { IClass olderClass = GetCallingClass(parseInfo.BestCompilationUnit.ProjectContent); if (olderClass != null && callingClass == null) { this.callingClass = olderClass; } callingMember = ResolveCurrentMember(olderClass); } } if (callingMember != null) { if (caretLine > callingMember.BodyRegion.EndLine) { this.caretLine = callingMember.BodyRegion.EndLine; this.caretColumn = callingMember.BodyRegion.EndColumn - 1; } else if (caretLine == callingMember.BodyRegion.EndLine && caretColumn >= callingMember.BodyRegion.EndColumn) { this.caretColumn = callingMember.BodyRegion.EndColumn - 1; } } return(true); }
static void SaveToCache(string cacheFileName, IProjectContent pc) { try { Directory.CreateDirectory(Path.GetDirectoryName(cacheFileName)); using (FileStream fs = new FileStream(cacheFileName, FileMode.Create, FileAccess.Write)) { using (BinaryWriter writer = new BinaryWriterWith7BitEncodedInts(fs)) { writer.Write(cacheMagicNumber); FastSerializer s = new FastSerializer(); s.Serialize(writer, pc); } } } catch (IOException ex) { LoggingService.Warn(ex); // Can happen if two SD instances are trying to access the file at the same time. // We'll just let one of them win, and the instance that got the exception won't write to the cache at all. // Similarly, we also ignore the other kinds of IO exceptions. } catch (UnauthorizedAccessException ex) { LoggingService.Warn(ex); } }
static IReturnType FindTypeInAssembly(IProjectContent projectContent, string xmlNamespace, string className) { foreach (IAttribute att in projectContent.GetAssemblyAttributes()) { if (att.PositionalArguments.Count == 2 && att.AttributeType.FullyQualifiedName == "System.Windows.Markup.XmlnsDefinitionAttribute") { string namespaceName = att.PositionalArguments[1] as string; if (xmlNamespace.Equals(att.PositionalArguments[0]) && namespaceName != null) { IClass c = projectContent.GetClass(namespaceName + "." + className, 0); if (c != null) { return(c.DefaultReturnType); } } } } return(null); }
ResolveResult ResolveFromPosition(string editorText, int offset, string fileName) { if (Project == null) { return(null); } var location = new ReadOnlyDocument(editorText).GetLocation(offset); var syntaxTree = new CSharpParser().Parse(editorText, fileName); syntaxTree.Freeze(); var unresolvedFile = syntaxTree.ToTypeSystem(); Project = Project.AddOrUpdateFiles(unresolvedFile); var compilation = Project.CreateCompilation(); return(ResolveAtLocation.Resolve(compilation, unresolvedFile, syntaxTree, location)); }
public ClassFinder(IClass callingClass, int caretLine, int caretColumn) { if (callingClass == null) { throw new ArgumentNullException("callingClass"); } if (callingClass is CompoundClass) { throw new ArgumentException("Cannot use compound class for ClassFinder - must pass a specific class part."); } this.caretLine = caretLine; this.caretColumn = caretColumn; this.callingClass = callingClass; this.cu = callingClass.CompilationUnit; this.projectContent = cu.ProjectContent; if (projectContent == null) { throw new ArgumentException("callingClass must have a project content!"); } }
public static IList <IUnresolvedTypeDefinition> GetPossibleStartupObjects(IProject project) { List <IUnresolvedTypeDefinition> results = new List <IUnresolvedTypeDefinition>(); IProjectContent pc = project.ProjectContent; if (pc != null) { foreach (var c in pc.TopLevelTypeDefinitions) { foreach (var m in c.Methods) { if (m.IsStatic && m.Name == "Main") { results.Add(c); } } } } return(results); }
private void AddOrUpdateFiles() { var unresolvedFiles = new IUnresolvedFile[this.sourceFiles.Count]; Parallel.For(0, unresolvedFiles.Length, i => { var file = this.sourceFiles[i]; var syntaxTree = new CSharpParser().Parse(System.IO.File.ReadAllText(file), file); if (this.CanFreeze) { //syntaxTree.Freeze(); } unresolvedFiles[i] = syntaxTree.ToTypeSystem(); }); this.project = this.project.AddOrUpdateFiles(unresolvedFiles); this.compilation = this.project.CreateCompilation(); }
ArrayList SearchClasses(string text) { int dotPos = text.IndexOf('.'); string needle = text; string member = ""; if (dotPos > 0) { needle = text.Substring(0, dotPos).Trim(); member = text.Substring(dotPos + 1).Trim(); } ArrayList list = new ArrayList(); if (ProjectService.OpenSolution != null) { foreach (IProject project in ProjectService.OpenSolution.Projects) { IProjectContent projectContent = ParserService.GetProjectContent(project); if (projectContent != null) { AddClasses(needle, member, list, projectContent.Classes); } } } return list; }
public static IList <IClass> GetPossibleStartupObjects(IProject project) { List <IClass> results = new List <IClass>(); IProjectContent pc = ParserService.GetProjectContent(project); if (pc != null) { foreach (IClass c in pc.Classes) { foreach (IMethod m in c.Methods) { if (m.IsStatic && m.Name == "Main") { results.Add(c); } } } } return(results); }
public void ParseInformationUpdated(IUnresolvedFile oldFile, IUnresolvedFile newFile) { // This method is called by the parser service within the parser service (per-file) lock. lock (lockObj) { if (!disposed) { if (newFile != null) { projectContent = projectContent.AddOrUpdateFiles(newFile); } else { projectContent = projectContent.RemoveFiles(oldFile.FileName); } serializedProjectContentIsUpToDate = false; SD.ParserService.InvalidateCurrentSolutionSnapshot(); SD.MainThread.InvokeAsyncAndForget(delegate { assemblyModel.Update(oldFile, newFile); }); } } }
public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent) { try { var astFactory = new JavaScriptAstFactory(fileContent); JavaScriptAst ast = astFactory.Create(); var unit = new JavaScriptCompilationUnit(projectContent, fileName); var walker = new JavaScriptAstWalker(unit, ast); walker.Walk(); return(unit); } catch (Exception ex) { LoggingService.Debug(ex.ToString()); } return(new DefaultCompilationUnit(projectContent) { FileName = fileName }); }
static void RunCompile(string openedFileName, string openedFileContent, IProjectContent pc) { var codeProvider = pc.Language.CodeDomProvider; if (codeProvider == null) { return; } string fileContent1 = CreateLineMarker(1, openedFileName) + "\n" + openedFileContent; StringWriter writer = new StringWriter(); Stopwatch watch = new Stopwatch(); watch.Start(); WriteClasses(pc, writer, openedFileName); watch.Stop(); Console.WriteLine("WriteClasses for {0} took {1}ms", (pc.Project as IProject).Name, watch.ElapsedMilliseconds); watch.Restart(); Compiler.CompilerResults cr = codeProvider.CompileAssemblyFromSource(GetParameters(pc.Project as CompilableProject), fileContent1, writer.ToString()); watch.Stop(); writer.Close(); var errors = cr.Errors.OfType <Compiler.CompilerError>().ToArray(); Console.WriteLine("CompileFile for {0} took {1}ms", (pc.Project as IProject).Name, watch.ElapsedMilliseconds); WorkbenchSingleton.SafeThreadAsyncCall( delegate() { List <Task> tasks = new List <Task>(); foreach (Compiler.CompilerError e in errors) { tasks.Add(new Task(string.IsNullOrEmpty(e.FileName) ? null : new FileName(e.FileName), e.ErrorText + " (" + e.ErrorNumber + ")", e.Column, e.Line, e.IsWarning ? TaskType.Warning : TaskType.Error)); } TaskService.ClearExceptCommentTasks(); TaskService.AddRange(tasks); } ); }
static Task SerializeAsync(string cacheFileName, IProjectContent pc) { if (cacheFileName == null) { return(Task.FromResult <object>(null)); } Task task = IOTaskScheduler.Factory.StartNew( delegate { pc = pc.RemoveAssemblyReferences(pc.AssemblyReferences); int serializableFileCount = 0; List <string> nonSerializableUnresolvedFiles = new List <string>(); foreach (var unresolvedFile in pc.Files) { if (IsSerializable(unresolvedFile)) { serializableFileCount++; } else { nonSerializableUnresolvedFiles.Add(unresolvedFile.FileName); } } // remove non-serializable parsed files if (nonSerializableUnresolvedFiles.Count > 0) { pc = pc.RemoveFiles(nonSerializableUnresolvedFiles); } if (serializableFileCount > 3) { LoggingService.Debug("Serializing " + serializableFileCount + " files to " + cacheFileName); SaveToCache(cacheFileName, pc); } else { RemoveCache(cacheFileName); } }, SD.ShutdownService.DelayedShutdownToken); SD.ShutdownService.AddBackgroundTask(task); return(task); }
public void AddWellKnownReferenceFromFile(string assemblyName, string assemblyLocation, bool tryPersistence = true, bool doAsync = false) { if (_cacheReferences.ContainsKey(assemblyName)) { return; } if (!Directory.Exists(GetPersistencePath())) { Directory.CreateDirectory(GetPersistencePath()); } RunMethod( delegate { lock (_contentRegistry) { DomPersistence persistence = _contentRegistry.ActivatePersistence(GetPersistencePath()); if (true == tryPersistence) { IProjectContent persistenceContent = persistence.LoadProjectContentByAssemblyName(assemblyName); if (null != persistenceContent) { _cacheReferences[assemblyName] = persistenceContent; //_projectContent.AddReferencedContent(persistenceContent); _projectContent.ReferencedContents.Add(persistenceContent); return; } } IProjectContent result = _contentRegistry.GetProjectContentForReference(assemblyName, assemblyLocation); if (null != result) { _cacheReferences[assemblyName] = result; _projectContent.ReferencedContents.Add(result); //_projectContent.AddReferencedContent(result); } } }, doAsync); }
void Init(ParseInformation parseInfo) { if (parseInfo != null) { cu = parseInfo.MostRecentCompilationUnit; } if (cu != null) { callingClass = cu.GetInnermostClass(caretLine, caretColumn); projectContent = cu.ProjectContent; } else { projectContent = DefaultProjectContent.DummyProjectContent; } if (projectContent == null) { throw new ArgumentException("projectContent not found!"); } }
static IClass GetPrimitiveClass(IProjectContent pc, string systemType, string newName) { IClass c = pc.GetClass(systemType, 0); if (c == null) { LoggingService.Warn("Could not find " + systemType); return(null); } DefaultClass c2 = new DefaultClass(c.CompilationUnit, newName); c2.ClassType = c.ClassType; c2.Modifiers = c.Modifiers; c2.Documentation = c.Documentation; c2.BaseTypes.AddRange(c.BaseTypes); c2.Methods.AddRange(c.Methods); c2.Fields.AddRange(c.Fields); c2.Properties.AddRange(c.Properties); c2.Events.AddRange(c.Events); return(c2); }
IClass GetCallingClass(IProjectContent pc) { IClass callingClass = cu.GetInnermostClass(caretLine, caretColumn); if (callingClass == null) { if (cu.Classes.Count == 0) { return(null); } callingClass = cu.Classes[cu.Classes.Count - 1]; if (!callingClass.Region.IsEmpty) { if (callingClass.Region.BeginLine > caretLine) { callingClass = null; } } } return(callingClass); }
protected override void Initialize() { base.Initialize(); IProjectContent projectContent = ParserService.GetProjectContent(Project); if (projectContent != null) { Nodes.Clear(); ReferenceFolderNode referencesNode = new ReferenceFolderNode(Project); referencesNode.AddTo(this); projectContent.ReferencedContentsChanged += delegate { WorkbenchSingleton.SafeThreadAsyncCall(referencesNode.UpdateReferenceNodes); }; foreach (ProjectItem item in Project.GetItemsOfType(ItemType.Compile)) { ParseInformation parseInformation = ParserService.GetParseInformation(item.FileName); if (parseInformation != null) { InsertParseInformation(parseInformation.BestCompilationUnit as ICompilationUnit); } } } }
/// <summary> /// Looks for the specified type in all the projects in the open solution /// excluding the current project. /// </summary> static IProject FindProjectContainingType(string type) { IProject currentProject = ProjectService.CurrentProject; foreach (IProject project in ProjectService.OpenSolution.Projects) { if (project != currentProject) { IProjectContent projectContent = ParserService.GetProjectContent(project); if (projectContent != null) { if (projectContent.GetClass(type, 0) != null) { LoggingService.Debug("Found project containing type: " + project.FileName); return(project); } } } } return(null); }
public override Assembly LoadAssembly(string name) { if (string.IsNullOrEmpty(name)) { IProjectContent pc = GetProjectContent(file); if (pc != null) { return(this.typeResolutionService.LoadAssembly(pc)); } return(null); } else { Assembly assembly = FindAssemblyInProjectReferences(name); if (assembly != null) { return(assembly); } return(base.LoadAssembly(name)); } }
public AST.Expression ResolveConstant(ITypeResolveContext context) { var csContext = (VSharpTypeResolveContext)context; if (context.CurrentAssembly != context.Compilation.MainAssembly) { // The constant needs to be resolved in a different compilation. IProjectContent pc = context.CurrentAssembly as IProjectContent; if (pc != null) { ICompilation nestedCompilation = context.Compilation.SolutionSnapshot.GetCompilation(pc); if (nestedCompilation != null) { var nestedContext = MapToNestedCompilation(csContext, nestedCompilation); AST.Expression rr = Constantify(new ResolveContext(nestedContext, CompilerContext.report)); return MapToNewContext(rr, context); } } } // Resolve in current context. return Constantify(new ResolveContext(csContext, CompilerContext.report)); }
public void AddCompilation(IProjectContent project, ICompilation compilation) { if (project == null) { throw new ArgumentNullException("project"); } if (compilation == null) { throw new ArgumentNullException("compilation"); } if (!dictionary.TryAdd(project, compilation)) { throw new InvalidOperationException(); } if (project.ProjectFileName != null) { lock (projectDictionary) { projectDictionary.Add(project.ProjectFileName, project); } } }
/// <summary> /// This method can take some time to finish. It's not threaded /// </summary> /// <returns> /// A <see cref="ParsedDocument"/> that contains the current dom. /// </returns> public ParsedDocument UpdateParseDocument() { try { string currentParseFile = FileName; var editor = Editor; if (editor == null || string.IsNullOrEmpty(currentParseFile)) { return(null); } TypeSystemService.AddSkippedFile(currentParseFile); string currentParseText = editor.Text; this.parsedDocument = TypeSystemService.ParseFile(Project, currentParseFile, editor.Document.MimeType, currentParseText); if (Project == null && this.parsedDocument != null) { singleFileContext = GetProjectContext().AddOrUpdateFiles(parsedDocument.ParsedFile); } } finally { OnDocumentParsed(EventArgs.Empty); } return(this.parsedDocument); }
ICompilationUnit Parse(ICSharpCode.NRefactory.IParser p, string fileName, IProjectContent projectContent) { p.Lexer.SpecialCommentTags = lexerTags; p.ParseMethodBodies = false; p.Parse(); NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(projectContent); if (projectContent.Project != null) { visitor.VBRootNamespace = ((IProject)projectContent.Project).RootNamespace; } visitor.Specials = p.Lexer.SpecialTracker.CurrentSpecials; visitor.VisitCompilationUnit(p.CompilationUnit, null); visitor.Cu.FileName = fileName; visitor.Cu.ErrorsDuringCompile = p.Errors.Count > 0; RetrieveRegions(visitor.Cu, p.Lexer.SpecialTracker); AddCommentTags(visitor.Cu, p.Lexer.TagComments); return(visitor.Cu); }