Ejemplo n.º 1
0
        public static IEnumerable <string> GetDefinedSymbols(MonoDevelop.Projects.Project project)
        {
            var workspace = IdeApp.Workspace;

            if (workspace == null || project == null)
            {
                yield break;
            }
            var configuration = project.GetConfiguration(workspace.ActiveConfiguration) as DotNetProjectConfiguration;

            if (configuration != null)
            {
                var cparams = configuration.CompilationParameters as CSharpCompilerParameters;
                if (cparams != null)
                {
                    string[] syms = cparams.DefineSymbols.Split(';', ',', ' ', '\t');
                    foreach (string s in syms)
                    {
                        string ss = s.Trim();
                        if (ss.Length > 0)
                        {
                            yield return(ss);
                        }
                    }
                }
                // Workaround for mcs defined symbol
                if (configuration.TargetRuntime.RuntimeId == "Mono")
                {
                    yield return("__MonoCS__");
                }
            }
        }
Ejemplo n.º 2
0
        public static ICSharpCode.NRefactory.CSharp.CompilerSettings GetCompilerArguments(MonoDevelop.Projects.Project project)
        {
            var compilerArguments = new ICSharpCode.NRefactory.CSharp.CompilerSettings();

            //		compilerArguments.TabSize = 1;

            if (project == null || MonoDevelop.Ide.IdeApp.Workspace == null)
            {
                compilerArguments.AllowUnsafeBlocks = true;
                return(compilerArguments);
            }

            var configuration = project.GetConfiguration(MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration;

            if (configuration == null)
            {
                return(compilerArguments);
            }

            foreach (var sym in configuration.GetDefineSymbols())
            {
                compilerArguments.ConditionalSymbols.Add(sym);
            }

            var par = configuration.CompilationParameters as CSharpCompilerParameters;

            if (par == null)
            {
                return(compilerArguments);
            }

            compilerArguments.AllowUnsafeBlocks     = par.UnsafeCode;
            compilerArguments.LanguageVersion       = ConvertLanguageVersion(par.LangVersion);
            compilerArguments.CheckForOverflow      = par.GenerateOverflowChecks;
            compilerArguments.WarningLevel          = par.WarningLevel;
            compilerArguments.TreatWarningsAsErrors = par.TreatWarningsAsErrors;
            if (!string.IsNullOrEmpty(par.NoWarnings))
            {
                foreach (var warning in par.NoWarnings.Split(';', ',', ' ', '\t'))
                {
                    int w;
                    try {
                        w = int.Parse(warning);
                    } catch (Exception) {
                        continue;
                    }
                    compilerArguments.DisabledWarnings.Add(w);
                }
            }

            return(compilerArguments);
        }
Ejemplo n.º 3
0
        public static CompilerSettings GetCompilerArguments(MonoDevelop.Projects.Project project)
        {
            var compilerArguments = new CompilerSettings();

            compilerArguments.TabSize = 1;

            if (project == null || MonoDevelop.Ide.IdeApp.Workspace == null)
            {
                compilerArguments.Unsafe = true;
                return(compilerArguments);
            }

            var configuration = project.GetConfiguration(MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration;
            var par           = configuration != null ? configuration.CompilationParameters as CSharpCompilerParameters : null;

            if (par == null)
            {
                return(compilerArguments);
            }

            if (!string.IsNullOrEmpty(par.DefineSymbols))
            {
                foreach (var sym in par.DefineSymbols.Split(';', ',', ' ', '\t').Where(s => !string.IsNullOrWhiteSpace(s)))
                {
                    compilerArguments.AddConditionalSymbol(sym);
                }
            }

            compilerArguments.Unsafe           = par.UnsafeCode;
            compilerArguments.Version          = ConvertLanguageVersion(par.LangVersion);
            compilerArguments.Checked          = par.GenerateOverflowChecks;
            compilerArguments.WarningLevel     = par.WarningLevel;
            compilerArguments.EnhancedWarnings = par.TreatWarningsAsErrors;
            if (!string.IsNullOrEmpty(par.NoWarnings))
            {
                foreach (var warning in par.NoWarnings.Split(';', ',', ' ', '\t'))
                {
                    int w;
                    try {
                        w = int.Parse(warning);
                    } catch (Exception) {
                        continue;
                    }
                    compilerArguments.SetIgnoreWarning(w);
                }
            }

            return(compilerArguments);
        }
Ejemplo n.º 4
0
        public static CSharpParseOptions GetCompilerArguments(MonoDevelop.Projects.Project project)
        {
            var compilerArguments = new CSharpParseOptions();

            //		compilerArguments.TabSize = 1;

            if (project == null || MonoDevelop.Ide.IdeApp.Workspace == null)
            {
                // compilerArguments.AllowUnsafeBlocks = true;
                return(compilerArguments);
            }

            var configuration = project.GetConfiguration(MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration;

            if (configuration == null)
            {
                return(compilerArguments);
            }

            compilerArguments = compilerArguments.WithPreprocessorSymbols(configuration.GetDefineSymbols());

            var par = configuration.CompilationParameters as CSharpCompilerParameters;

            if (par == null)
            {
                return(compilerArguments);
            }


            // compilerArguments.AllowUnsafeBlocks = par.UnsafeCode;
            compilerArguments = compilerArguments.WithLanguageVersion(ConvertLanguageVersion(par.LangVersion));
//			compilerArguments.CheckForOverflow = par.GenerateOverflowChecks;

//			compilerArguments.WarningLevel = par.WarningLevel;
//			compilerArguments.TreatWarningsAsErrors = par.TreatWarningsAsErrors;
//			if (!string.IsNullOrEmpty (par.NoWarnings)) {
//				foreach (var warning in par.NoWarnings.Split (';', ',', ' ', '\t')) {
//					int w;
//					try {
//						w = int.Parse (warning);
//					} catch (Exception) {
//						continue;
//					}
//					compilerArguments.DisabledWarnings.Add (w);
//				}
//			}

            return(compilerArguments);
        }
		public override DeployFileCollection GetProjectDeployFiles (DeployContext ctx, Project project, ConfigurationSelector configuration)
		{
			DeployFileCollection deployFiles = new DeployFileCollection ();
			base.GetProjectDeployFiles (ctx, project, configuration);
			// Add the compiled output file
			
			string outputFile = project.GetOutputFileName (configuration);
			if (!string.IsNullOrEmpty (outputFile))
				deployFiles.Add (new DeployFile (project, outputFile, Path.GetFileName (outputFile), TargetDirectory.ProgramFiles));
			
			// Collect deployable files
			foreach (ProjectFile file in project.Files) {
				// skip CopyToOutputDirectory files when it's just a project build, because 
				// MonoDevelop.Project.Projects already copies these files using more subtle overwriting
				// semantics
				if (file.CopyToOutputDirectory != FileCopyMode.None)
					continue;
				    
				DeployProperties props = new DeployProperties (file);
				if (props.ShouldDeploy) {
					DeployFile dp = new DeployFile (file);
					deployFiles.Add (dp);
					
					if (string.Compare (Path.GetFileName (dp.SourcePath), "app.config", true)==0 && string.Compare (Path.GetFileName (dp.RelativeTargetPath), "app.config", true)==0) {
						string newName = Path.GetFileName (outputFile) + ".config";
						dp.RelativeTargetPath = Path.Combine (Path.GetDirectoryName (dp.RelativeTargetPath), newName);
					}
				}
			}
			
			foreach (FileCopySet.Item item in project.GetSupportFileList (configuration)) {
				 deployFiles.Add (new DeployFile (project, item.Src, item.Target, TargetDirectory.ProgramFiles));
			}
			
			DotNetProject netProject = project as DotNetProject;
			if (netProject != null) {
				DotNetProjectConfiguration conf = (DotNetProjectConfiguration) project.GetConfiguration (configuration);
				if (conf.DebugMode) {
					string mdbFile = netProject.TargetRuntime.GetAssemblyDebugInfoFile (conf.CompiledOutputName);
					deployFiles.Add (new DeployFile (project, mdbFile, Path.GetFileName (mdbFile), TargetDirectory.ProgramFiles));
				}
			}
			
			return deployFiles;
		}
Ejemplo n.º 6
0
            static async Task <DotNetProjectConfiguration> GetDotNetProjectConfiguration(MonoDevelop.Projects.Project p, string framework)
            {
                var dotNetProject = p as DotNetProject;

                if (dotNetProject == null)
                {
                    return(null);
                }

                var workspace = Runtime.PeekService <RootWorkspace> ();
                var config    = workspace != null?p.GetConfiguration(workspace.ActiveConfiguration) as DotNetProjectConfiguration : p.DefaultConfiguration as DotNetProjectConfiguration;

                if (config == null || string.IsNullOrEmpty(framework))
                {
                    return(config);
                }

                return(await dotNetProject.GetConfigurationAsync(config.Name, config.Platform, framework).ConfigureAwait(false));
            }
		public override DeployFileCollection GetProjectDeployFiles (DeployContext ctx, Project project, ConfigurationSelector configuration)
		{
			DeployFileCollection deployFiles = new DeployFileCollection ();
			base.GetProjectDeployFiles (ctx, project, configuration);
			
			// Add the compiled output files
			
			ProjectConfiguration pconf = (ProjectConfiguration) project.GetConfiguration (configuration);
			FilePath outDir = pconf.OutputDirectory;
			foreach (FilePath file in project.GetOutputFiles (configuration)) {
				deployFiles.Add (new DeployFile (project, file, file.ToRelative (outDir), TargetDirectory.ProgramFiles));
			}
			
			FilePath outputFile = project.GetOutputFileName (configuration);
			
			// Collect deployable files
			foreach (ProjectFile file in project.Files) {
				// skip CopyToOutputDirectory files when it's just a project build, because 
				// MonoDevelop.Project.Projects already copies these files using more subtle overwriting
				// semantics
				if (file.CopyToOutputDirectory != FileCopyMode.None)
					continue;
				    
				DeployProperties props = new DeployProperties (file);
				if (props.ShouldDeploy) {
					DeployFile dp = new DeployFile (file);
					deployFiles.Add (dp);
					
					if (string.Compare (Path.GetFileName (dp.SourcePath), "app.config", true)==0 && string.Compare (Path.GetFileName (dp.RelativeTargetPath), "app.config", true)==0) {
						string newName = Path.GetFileName (outputFile) + ".config";
						dp.RelativeTargetPath = Path.Combine (Path.GetDirectoryName (dp.RelativeTargetPath), newName);
					}
				}
			}
			
			foreach (FileCopySet.Item item in project.GetSupportFileList (configuration)) {
				 deployFiles.Add (new DeployFile (project, item.Src, item.Target, TargetDirectory.ProgramFiles));
			}
			
			return deployFiles;
		}
        public static IEnumerable <string> GetDefinedSymbols(MonoDevelop.Projects.Project project)
        {
            var workspace = IdeApp.Workspace;

            if (workspace == null || project == null)
            {
                yield break;
            }
            var configuration = project.GetConfiguration(workspace.ActiveConfiguration) as DotNetProjectConfiguration;

            if (configuration != null)
            {
                foreach (string s in configuration.GetDefineSymbols())
                {
                    yield return(s);
                }
                // Workaround for mcs defined symbol
                if (configuration.TargetRuntime.RuntimeId == "Mono")
                {
                    yield return("__MonoCS__");
                }
            }
        }
Ejemplo n.º 9
0
        public static string GetCompletionData(Project project, string classPath, string fileName, int position)
        {
            if (!PropertyService.HasValue ("HaxeBinding.EnableCompilationServer"))
            {
                PropertyService.Set ("HaxeBinding.EnableCompilationServer", true);
                PropertyService.Set ("HaxeBinding.CompilationServerPort", 6000);
                PropertyService.SaveProperties();
            }

            string exe = "haxe";
            string args = "";

            if (project is NMEProject) {

                NMEProjectConfiguration configuration = project.GetConfiguration (MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as NMEProjectConfiguration;

                string platform = configuration.Platform.ToLower ();
                string path = ((NMEProject)project).TargetNMMLFile;

                if (!File.Exists (path))
                {
                    path = Path.Combine (project.BaseDirectory, path);
                }

                DateTime time = File.GetLastWriteTime (Path.GetFullPath (path));

                if (!time.Equals (cacheNMMLTime) || platform != cachePlatform || configuration.AdditionalArguments != cacheArgumentsPlatform || ((NMEProject)project).AdditionalArguments != cacheArgumentsGlobal)
                {
                    cacheHXML = NMECommandLineToolsManager.GetHXMLData ((NMEProject)project, configuration);
                    cacheNMMLTime = time;
                    cachePlatform = platform;
                    cacheArgumentsGlobal = ((NMEProject)project).AdditionalArguments;
                    cacheArgumentsPlatform = configuration.AdditionalArguments;
                }

                args = cacheHXML + " -D code_completion";

            } else if (project is HaxeProject) {

                HaxeProjectConfiguration configuration = project.GetConfiguration (MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as HaxeProjectConfiguration;

                args = "\"" + ((HaxeProject)project).TargetHXMLFile + "\" " + ((HaxeProject)project).AdditionalArguments + " " + configuration.AdditionalArguments;

            } else {

                return "";

            }

            args += " -cp \"" + classPath + "\" --display \"" + fileName + "\"@" + position + " -D use_rtti_doc";

            if (PropertyService.Get<bool> ("HaxeBinding.EnableCompilationServer")) {

                var port = PropertyService.Get<int> ("HaxeBinding.CompilationServerPort");

                if (compilationServer == null || compilationServer.HasExited || port != compilationServerPort)
                {
                    StartServer ();
                }

                try
                {
                    if (!compilationServer.HasExited)
                    {
                        var client = new TcpClient("127.0.0.1", port);
                        var writer = new StreamWriter(client.GetStream());
                        writer.WriteLine("--cwd " + project.BaseDirectory);
                        string[] argList = args.Split (' ');
                        foreach (var arg in argList)
                            writer.WriteLine(arg);
                        //writer.WriteLine("--connect " + port);
                        writer.Write("\0");
                        writer.Flush();
                        var reader = new StreamReader(client.GetStream());
                        var lines = reader.ReadToEnd().Split('\n');
                        client.Close();
                        return String.Join ("\n", lines);
                    }
                }
                catch(Exception)
                {
                    //MonoDevelop.Ide.MessageService.ShowError (ex.ToString ());
                    //TraceManager.AddAsync(ex.Message);
                    //if (!failure && FallbackNeeded != null)
                       // FallbackNeeded(false);
                    //failure = true;
                    //return "";
                }

            }

            //MonoDevelop.Ide.MessageService.ShowError ("Falling back to standard completion");

            Process process = new Process ();
            process.StartInfo.FileName = exe;
            process.StartInfo.Arguments = args;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.WorkingDirectory = project.BaseDirectory;
            process.Start ();

            string result = process.StandardError.ReadToEnd ();
            process.WaitForExit ();

            return result;
        }
Ejemplo n.º 10
0
            static DotNetProjectConfiguration GetDotNetProjectConfiguration(MonoDevelop.Projects.Project p)
            {
                var workspace = Runtime.PeekService <RootWorkspace> ();

                return(workspace != null?p.GetConfiguration(workspace.ActiveConfiguration) as MonoDevelop.Projects.DotNetProjectConfiguration : p.DefaultConfiguration as MonoDevelop.Projects.DotNetProjectConfiguration);
            }
            internal async Task <ProjectInfo> LoadProject(MonoDevelop.Projects.Project p, CancellationToken token, MonoDevelop.Projects.Project oldProject)
            {
                var projectId = projectMap.GetOrCreateId(p, oldProject);

                var config = IdeApp.Workspace != null?p.GetConfiguration(IdeApp.Workspace.ActiveConfiguration) as MonoDevelop.Projects.DotNetProjectConfiguration : null;

                MonoDevelop.Projects.DotNetCompilerParameters cp = config?.CompilationParameters;
                FilePath fileName = IdeApp.Workspace != null?p.GetOutputFileName(IdeApp.Workspace.ActiveConfiguration) : (FilePath)"";

                if (fileName.IsNullOrEmpty)
                {
                    fileName = new FilePath(p.Name + ".dll");
                }

                if (!hackyCache.TryGetCachedItems(p, workspace.MetadataReferenceManager, projectMap, out var sourceFiles, out var analyzerFiles, out var references, out var projectReferences))
                {
                    (references, projectReferences) = await metadataHandler.Value.CreateReferences(p, token).ConfigureAwait(false);

                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }

                    sourceFiles = await p.GetSourceFilesAsync(config?.Selector).ConfigureAwait(false);

                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }

                    analyzerFiles = await p.GetAnalyzerFilesAsync(config?.Selector).ConfigureAwait(false);

                    if (config != null)
                    {
                        hackyCache.Update(config, p, projectMap, sourceFiles, analyzerFiles, references, projectReferences);
                    }
                }

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var loader = workspace.Services.GetService <IAnalyzerService> ().GetLoader();

                ProjectData         projectData, oldProjectData;
                List <DocumentInfo> mainDocuments, additionalDocuments;

                try {
                    await workspace.LoadLock.WaitAsync().ConfigureAwait(false);

                    //when reloading e.g. after a save, preserve document IDs
                    oldProjectData = projectMap.RemoveData(projectId);
                    projectData    = projectMap.CreateData(projectId, references);

                    var documents = await CreateDocuments(projectData, p, token, sourceFiles, oldProjectData).ConfigureAwait(false);

                    if (documents == null)
                    {
                        return(null);
                    }

                    mainDocuments       = documents.Item1;
                    additionalDocuments = documents.Item2;
                } finally {
                    workspace.LoadLock.Release();
                }

                // TODO: Pass in the WorkspaceMetadataFileReferenceResolver
                var info = ProjectInfo.Create(
                    projectId,
                    VersionStamp.Create(),
                    p.Name,
                    fileName.FileNameWithoutExtension,
                    (p as MonoDevelop.Projects.DotNetProject)?.RoslynLanguageName ?? LanguageNames.CSharp,
                    p.FileName,
                    fileName,
                    cp?.CreateCompilationOptions(),
                    cp?.CreateParseOptions(config),
                    mainDocuments,
                    projectReferences,
                    references.Select(x => x.CurrentSnapshot),
                    analyzerReferences: analyzerFiles.SelectAsArray(x => {
                    var analyzer = new MonoDevelopAnalyzer(x, hostDiagnosticUpdateSource.Value, projectId, workspace, loader, LanguageNames.CSharp);
                    analyzersToDispose.Add(analyzer);
                    return(analyzer.GetReference());
                }),
                    additionalDocuments: additionalDocuments
                    );

                return(info);
            }