Beispiel #1
0
        public static XSourceEntity FindElementInFile(XFile file, XPETypeSymbol petype, XSymbol element)
        {
            var walker = new SourceWalker(file, false);

            walker.Parse(false);
            var           entities = walker.EntityList;
            XSourceEntity result   = null;

            if (petype.IsFunctionsClass)
            {
                foreach (var entity in entities)
                {
                    if (entity.Prototype == element.Prototype)
                    {
                        result = entity;
                        break;
                    }
                }
            }
            else
            {
                foreach (var entity in entities)
                {
                    if (entity.FullName == element.FullName)
                    {
                        result = entity;
                        break;
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        private static void GotoSystemType(ITextView TextView, XPETypeSymbol petype, XPESymbol element)
        {
            var xFile  = CreateFileForSystemType(petype, element);
            var entity = FindElementInFile(xFile, petype, element);
            var file   = TextView.TextBuffer.GetFile();
            // Copy references to the Orphan file project so type lookup works as expected
            var orphProject = XSolution.OrphanedFilesProject;
            var project     = file.Project;

            if (project != orphProject)
            {
                orphProject.ClearAssemblyReferences();
                foreach (var asm in project.AssemblyReferences)
                {
                    orphProject.AddAssemblyReference(asm.FileName);
                }
            }
            XSettings.OpenDocument(xFile.FullPath, entity.Range.StartLine, 1, true);
        }
Beispiel #3
0
        internal static XFile CreateFileForSystemType(XPETypeSymbol petype, XPESymbol element)
        {
            asmName = petype.Assembly;
            bool mustCreate = false;

            if (Semaphore == null)
            {
                // we create a semaphore file in the workfolder to make sure that if 2 copies of VS are running
                // that we will not delete the files from the other copy
                var tempFolder = Path.GetTempPath();
                tempFolder = Path.Combine(tempFolder, folderName);
                var semFile = Path.Combine(tempFolder, semName);
                // clean up files from previous run
                if (Directory.Exists(tempFolder))
                {
                    if (File.Exists(semFile))
                    {
                        try
                        {
                            File.Delete(semFile);
                            DeleteFolderRecursively(new DirectoryInfo(tempFolder));
                        }
                        catch
                        {
                            // if deletion fails, other copy of VS is running, so do not delete the folder
                        }
                    }
                }
                if (!Directory.Exists(tempFolder))
                {
                    Directory.CreateDirectory(tempFolder);
                }
                WorkFolder = tempFolder;
                if (!File.Exists(semFile))
                {
                    Semaphore = File.Create(semFile);
                }
            }
            var ns     = petype.Namespace + "." + petype.Assembly.Version;
            var name   = petype.Name;
            var nspath = Path.Combine(WorkFolder, ns);

            if (!Directory.Exists(nspath))
            {
                Directory.CreateDirectory(nspath);
            }
            var temp = Path.Combine(nspath, petype.Name) + ".prg";

            mustCreate = !File.Exists(temp);
            if (mustCreate)
            {
                VS.StatusBar.ShowMessageAsync("Generating reference source for " + petype.FullName).FireAndForget();
                VS.StatusBar.StartAnimationAsync(StatusAnimation.General).FireAndForget();
                var aLines = XClassCreator.Create(petype, LookupXml);
                File.WriteAllLines(temp, aLines, System.Text.Encoding.UTF8);
                File.SetAttributes(temp, FileAttributes.ReadOnly);
                VS.StatusBar.ClearAsync().FireAndForget();
                VS.StatusBar.EndAnimationAsync(StatusAnimation.General).FireAndForget();
            }
            var xFile = XSolution.AddOrphan(temp);

            return(xFile);
        }