internal void UpdateProjectionEntry(MonoDevelop.Projects.ProjectFile projectFile, IReadOnlyList <Projection> projections)
            {
                if (projectFile == null)
                {
                    throw new ArgumentNullException(nameof(projectFile));
                }
                if (projections == null)
                {
                    throw new ArgumentNullException(nameof(projections));
                }

                lock (projectionListUpdateLock) {
                    foreach (var entry in projectionList)
                    {
                        if (entry?.File?.FilePath == projectFile.FilePath)
                        {
                            projectionList = projectionList.Remove(entry);
                            // Since it's disposing projected editor, it needs to dispose in MainThread.
                            Runtime.RunInMainThread(() => entry.Dispose()).Ignore();
                            break;
                        }
                    }
                    projectionList = projectionList.Add(new ProjectionEntry {
                        File = projectFile, Projections = projections
                    });
                }
            }
Exemplo n.º 2
0
 internal void UpdateProjectionEnntry(MonoDevelop.Projects.ProjectFile projectFile, IReadOnlyList <Projection> projections)
 {
     foreach (var entry in projectionList)
     {
         if (entry.File.FilePath == projectFile.FilePath)
         {
             projectionList.Remove(entry);
             break;
         }
     }
     projectionList.Add(new ProjectionEntry {
         File = projectFile, Projections = projections
     });
 }
Exemplo n.º 3
0
            async Task <List <DocumentInfo> > GenerateProjections(MonoDevelop.Projects.ProjectFile f, DocumentMap documentMap, MonoDevelop.Projects.Project p, CancellationToken token, ProjectData oldProjectData, HashSet <DocumentId> duplicates)
            {
                var mimeType = DesktopService.GetMimeTypeForUri(f.FilePath);
                var node     = TypeSystemService.GetTypeSystemParserNode(mimeType, f.BuildAction);

                if (node == null || !node.Parser.CanGenerateProjection(mimeType, f.BuildAction, p.SupportedLanguages))
                {
                    return(new List <DocumentInfo> ());
                }

                var options = new ParseOptions {
                    FileName = f.FilePath,
                    Project  = p,
                    Content  = TextFileProvider.Instance.GetReadOnlyTextEditorData(f.FilePath),
                };
                var generatedProjections = await node.Parser.GenerateProjections(options, token);

                var list  = new List <Projection> ();
                var entry = new ProjectionEntry {
                    File        = f,
                    Projections = list,
                };

                var result = new List <DocumentInfo> (generatedProjections.Count);

                foreach (var projection in generatedProjections)
                {
                    list.Add(projection);
                    if (duplicates != null && !duplicates.Add(documentMap.GetOrCreate(projection.Document.FileName, oldProjectData?.DocumentData)))
                    {
                        continue;
                    }
                    var plainName = projection.Document.FileName.FileName;
                    var folders   = GetFolders(p.Name, f);
                    result.Add(DocumentInfo.Create(
                                   documentMap.GetOrCreate(projection.Document.FileName, oldProjectData?.DocumentData),
                                   plainName,
                                   folders,
                                   SourceCodeKind.Regular,
                                   TextLoader.From(TextAndVersion.Create(new MonoDevelopSourceText(projection.Document), VersionStamp.Create(), projection.Document.FileName)),
                                   projection.Document.FileName,
                                   false)
                               );
                }
                projections.AddProjectionEntry(entry);
                return(result);
            }
Exemplo n.º 4
0
        protected override void ApplyDocumentAdded(DocumentInfo info, SourceText text)
        {
            var id = info.Id;

            MonoDevelop.Projects.Project mdProject = null;

            if (id.ProjectId != null)
            {
                var project = CurrentSolution.GetProject(id.ProjectId);
                mdProject = GetMonoProject(project);
                if (mdProject == null)
                {
                    LoggingService.LogWarning("Couldn't find project for newly generated file {0} (Project {1}).", info.Name, info.Id.ProjectId);
                }
            }
            var path = DetermineFilePath(info.Id, info.Name, info.FilePath, info.Folders, mdProject?.FileName.ParentDirectory, true);

            string formattedText;
            var    formatter = CodeFormatterService.GetFormatter(DesktopService.GetMimeTypeForUri(path));

            if (formatter != null && mdProject != null)
            {
                formattedText = formatter.FormatText(mdProject.Policies, text.ToString());
            }
            else
            {
                formattedText = text.ToString();
            }

            var textSource = new StringTextSource(formattedText, text.Encoding ?? System.Text.Encoding.UTF8);

            try {
                textSource.WriteTextTo(path);
            } catch (Exception e) {
                LoggingService.LogError("Exception while saving file to " + path, e);
            }

            if (mdProject != null)
            {
                var file = new MonoDevelop.Projects.ProjectFile(path);
                Application.Invoke(delegate {
                    mdProject.Files.Add(file);
                    IdeApp.ProjectOperations.SaveAsync(mdProject);
                });
            }
        }
Exemplo n.º 5
0
        IEnumerable <DocumentInfo> GenerateProjections(MonoDevelop.Projects.ProjectFile f, ProjectData projectData, MonoDevelop.Projects.Project p, HashSet <DocumentId> duplicates = null)
        {
            var mimeType = DesktopService.GetMimeTypeForUri(f.FilePath);
            var node     = TypeSystemService.GetTypeSystemParserNode(mimeType, f.BuildAction);

            if (node == null || !node.Parser.CanGenerateProjection(mimeType, f.BuildAction, p.SupportedLanguages))
            {
                yield break;
            }
            var options = new ParseOptions {
                FileName = f.FilePath,
                Project  = p,
                Content  = StringTextSource.ReadFrom(f.FilePath),
            };
            var projections = node.Parser.GenerateProjections(options);
            var entry       = new ProjectionEntry();

            entry.File = f;
            var list = new List <Projection> ();

            entry.Projections = list;
            foreach (var projection in projections.Result)
            {
                list.Add(projection);
                if (duplicates != null && !duplicates.Add(projectData.GetOrCreateDocumentId(projection.Document.FileName)))
                {
                    continue;
                }
                var plainName = projection.Document.FileName.FileName;
                yield return(DocumentInfo.Create(
                                 projectData.GetOrCreateDocumentId(projection.Document.FileName),
                                 plainName,
                                 new [] { p.Name }.Concat(f.ProjectVirtualPath.ParentDirectory.ToString().Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)),
                                 SourceCodeKind.Regular,
                                 TextLoader.From(TextAndVersion.Create(new MonoDevelopSourceText(projection.Document), VersionStamp.Create(), projection.Document.FileName)),
                                 projection.Document.FileName,
                                 false
                                 ));
            }
            projectionList.Add(entry);
        }
Exemplo n.º 6
0
        private void RegisterControllerInModule(MonoDevelop.Projects.ProjectFile projectFile, string fullName)
        {
            var document       = IdeApp.Workbench.OpenDocument(projectFile.FilePath, projectFile.Project, false);
            var textEditorData = document.GetContent <ITextEditorDataProvider> ().GetTextEditorData();

            DocumentLine line = textEditorData.GetLine(textEditorData.Lines.Count() - 2);

            for (int i = 1; i < textEditorData.Lines.Count(); i++)
            {
                var lineText = textEditorData.GetLineText(i);

                if (lineText.ToLowerInvariant().Contains("registerservices"))
                {
                    int j = 1;
                    i++;
                    while (j != 0)
                    {
                        i++;
                        lineText = textEditorData.GetLineText(i);

                        if (lineText.Contains("}"))
                        {
                            j--;
                        }
                        else if (lineText.Contains("{"))
                        {
                            j++;
                        }
                    }
                    line = textEditorData.GetLine(i);
                    break;
                }
            }

            textEditorData.Insert(line.Offset, string.Format("\t\t\tbatch.RegisterController (() => new {0}());\n", fullName));

            document.Save();
            document.Close();
        }
Exemplo n.º 7
0
		protected override void ApplyDocumentAdded (DocumentInfo info, SourceText text)
		{
			var id = info.Id;
			MonoDevelop.Projects.Project mdProject = null;

			if (id.ProjectId != null) {
				var project = CurrentSolution.GetProject (id.ProjectId);
				mdProject = GetMonoProject (project);
				if (mdProject == null)
					LoggingService.LogWarning ("Couldn't find project for newly generated file {0} (Project {1}).", info.Name, info.Id.ProjectId);
			}
			var path = DetermineFilePath (info.Id, info.Name, info.FilePath, info.Folders, mdProject?.FileName.ParentDirectory, true);

			string formattedText;
			var formatter = CodeFormatterService.GetFormatter (DesktopService.GetMimeTypeForUri (path)); 
			if (formatter != null && mdProject != null) {
				formattedText = formatter.FormatText (mdProject.Policies, text.ToString ());
			} else {
				formattedText = text.ToString ();
			}

			var textSource = new StringTextSource (formattedText, text.Encoding ?? System.Text.Encoding.UTF8);
			try {
				textSource.WriteTextTo (path);
			} catch (Exception e) {
				LoggingService.LogError ("Exception while saving file to " + path, e);
			}

			if (mdProject != null) {
				var file = new MonoDevelop.Projects.ProjectFile (path);
				Application.Invoke (delegate {
					mdProject.Files.Add (file);
					IdeApp.ProjectOperations.SaveAsync (mdProject);
				});
			}
		}
Exemplo n.º 8
0
        static DocumentInfo CreateDocumentInfo(SolutionData data, string projectName, ProjectData id, MonoDevelop.Projects.ProjectFile f)
        {
            var filePath       = f.FilePath;
            var sourceCodeKind = filePath.Extension == ".sketchcs" ? SourceCodeKind.Script : SourceCodeKind.Regular;

            return(DocumentInfo.Create(
                       id.GetOrCreateDocumentId(filePath),
                       f.FilePath,
                       new [] { projectName }.Concat(f.ProjectVirtualPath.ParentDirectory.ToString().Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)),
                       sourceCodeKind,
                       CreateTextLoader(data, f.Name),
                       f.Name,
                       false
                       ));
        }
Exemplo n.º 9
0
 static IEnumerable <string> GetFolders(string projectName, MonoDevelop.Projects.ProjectFile f)
 {
     return(new [] { projectName }.Concat(f.ProjectVirtualPath.ParentDirectory.ToString().Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)));
 }
Exemplo n.º 10
0
            static DocumentInfo CreateDocumentInfo(SolutionData data, string projectName, ProjectData id, MonoDevelop.Projects.ProjectFile f, SourceCodeKind sourceCodeKind)
            {
                var filePath = f.FilePath;
                var folders  = GetFolders(projectName, f);

                return(DocumentInfo.Create(
                           id.DocumentData.GetOrCreate(filePath),
                           filePath,
                           folders,
                           sourceCodeKind,
                           CreateTextLoader(f.Name),
                           f.Name,
                           isGenerated: false
                           ));

                TextLoader CreateTextLoader(string fileName) => data.Files.GetOrAdd(fileName, a => new MonoDevelopTextLoader(a));
            }
Exemplo n.º 11
0
            static bool CanGenerateAnalysisContextForNonCompileable(MonoDevelop.Projects.Project p, MonoDevelop.Projects.ProjectFile f)
            {
                var mimeType = DesktopService.GetMimeTypeForUri(f.FilePath);
                var node     = TypeSystemService.GetTypeSystemParserNode(mimeType, f.BuildAction);

                if (node?.Parser == null)
                {
                    return(false);
                }
                return(node.Parser.CanGenerateAnalysisDocument(mimeType, f.BuildAction, p.SupportedLanguages));
            }
 internal void UpdateProjectionEntry(MonoDevelop.Projects.ProjectFile projectFile, IReadOnlyList <Projection> projections)
 => Projections.UpdateProjectionEntry(projectFile, projections);