internal ProjectState(ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices) { Contract.ThrowIfNull(projectInfo); Contract.ThrowIfNull(languageServices); Contract.ThrowIfNull(solutionServices); _languageServices = languageServices; _solutionServices = solutionServices; _projectInfo = FixProjectInfo(projectInfo); _documentIds = _projectInfo.Documents.Select(d => d.Id).ToImmutableArray(); _additionalDocumentIds = this.ProjectInfo.AdditionalDocuments.Select(d => d.Id).ToImmutableArray(); var docStates = ImmutableDictionary.CreateRange<DocumentId, DocumentState>( _projectInfo.Documents.Select(d => new KeyValuePair<DocumentId, DocumentState>(d.Id, CreateDocument(this.ProjectInfo, d, languageServices, solutionServices)))); _documentStates = docStates; var additionalDocStates = ImmutableDictionary.CreateRange<DocumentId, TextDocumentState>( _projectInfo.AdditionalDocuments.Select(d => new KeyValuePair<DocumentId, TextDocumentState>(d.Id, TextDocumentState.Create(d, solutionServices)))); _additionalDocumentStates = additionalDocStates; _lazyLatestDocumentVersion = new AsyncLazy<VersionStamp>(c => ComputeLatestDocumentVersionAsync(docStates, additionalDocStates, c), cacheResult: true); _lazyLatestDocumentTopLevelChangeVersion = new AsyncLazy<VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(docStates, additionalDocStates, c), cacheResult: true); }
public void TestInit() { try { workspace = new AdhocWorkspace(); project = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "TestProj", "TestProj", LanguageNames.CSharp) .WithMetadataReferences(new[] { MetadataReference.CreateFromFile(typeof(DotvvmConfiguration).Assembly.Location), MetadataReference.CreateFromFile(typeof(object).Assembly.Location) }); workspace.AddProject(project); workspace.AddDocument(project.Id, "test", SourceText.From("class A {}")); context = new DothtmlCompletionContext() { Configuration = DotvvmConfiguration.CreateDefault(), RoslynWorkspace = workspace }; } catch (ReflectionTypeLoadException ex) { throw new Exception(string.Join("\r\n", ex.LoaderExceptions.Select(e => e.ToString()))); } }
public ProjectState(ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices) { Contract.ThrowIfNull(projectInfo); Contract.ThrowIfNull(languageServices); Contract.ThrowIfNull(solutionServices); _languageServices = languageServices; _solutionServices = solutionServices; _projectInfo = FixProjectInfo(projectInfo); _documentIds = _projectInfo.Documents.Select(d => d.Id).ToImmutableArray(); _additionalDocumentIds = _projectInfo.AdditionalDocuments.Select(d => d.Id).ToImmutableArray(); var docStates = ImmutableDictionary.CreateRange<DocumentId, DocumentState>( _projectInfo.Documents.Select(d => new KeyValuePair<DocumentId, DocumentState>(d.Id, CreateDocument(_projectInfo, d, languageServices, solutionServices)))); _documentStates = docStates; var additionalDocStates = ImmutableDictionary.CreateRange<DocumentId, TextDocumentState>( _projectInfo.AdditionalDocuments.Select(d => new KeyValuePair<DocumentId, TextDocumentState>(d.Id, TextDocumentState.Create(d, solutionServices)))); _additionalDocumentStates = additionalDocStates; _lazyLatestDocumentVersion = new AsyncLazy<VersionStamp>(c => ComputeLatestDocumentVersionAsync(docStates, additionalDocStates, c), cacheResult: true); _lazyLatestDocumentTopLevelChangeVersion = new AsyncLazy<VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(docStates, additionalDocStates, c), cacheResult: true); // for now, let it re-calculate if anything changed. // TODO: optimize this so that we only re-calcuate checksums that are actually changed _lazyChecksums = new AsyncLazy<ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true); }
private ProjectState( ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices, IEnumerable<DocumentId> documentIds, IEnumerable<DocumentId> additionalDocumentIds, ImmutableDictionary<DocumentId, DocumentState> documentStates, ImmutableDictionary<DocumentId, TextDocumentState> additionalDocumentStates, AsyncLazy<VersionStamp> lazyLatestDocumentVersion, AsyncLazy<VersionStamp> lazyLatestDocumentTopLevelChangeVersion, ValueSource<ProjectStateChecksums> lazyChecksums) { _projectInfo = projectInfo; _solutionServices = solutionServices; _languageServices = languageServices; _documentIds = documentIds.ToImmutableReadOnlyListOrEmpty(); _additionalDocumentIds = additionalDocumentIds.ToImmutableReadOnlyListOrEmpty(); _documentStates = documentStates; _additionalDocumentStates = additionalDocumentStates; _lazyLatestDocumentVersion = lazyLatestDocumentVersion; _lazyLatestDocumentTopLevelChangeVersion = lazyLatestDocumentTopLevelChangeVersion; // for now, let it re-calculate if anything changed. // TODO: optimize this so that we only re-calcuate checksums that are actually changed _lazyChecksums = new AsyncLazy<ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true); }
/// <summary> /// Adds a project to the workspace. All previous projects remain intact. /// </summary> public void AddProject(ProjectInfo projectInfo) { if (projectInfo == null) { throw new ArgumentNullException("projectInfo"); } this.OnProjectAdded(projectInfo); }
/// <summary> /// Adds a project to the workspace. All previous projects remain intact. /// </summary> public Project AddProject(ProjectInfo projectInfo) { if (projectInfo == null) { throw new ArgumentNullException("projectInfo"); } this.OnProjectAdded(projectInfo); return this.CurrentSolution.GetProject(projectInfo.Id); }
/// <summary> /// Adds a project to the workspace. All previous projects remain intact. /// </summary> public Project AddProject(ProjectInfo projectInfo) { if (projectInfo == null) { throw new ArgumentNullException(nameof(projectInfo)); } this.OnProjectAdded(projectInfo); this.UpdateReferencesAfterAdd(); return this.CurrentSolution.GetProject(projectInfo.Id); }
private ProjectState( ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices, IEnumerable<DocumentId> documentIds, ImmutableDictionary<DocumentId, DocumentState> documentStates, AsyncLazy<VersionStamp> lazyLatestDocumentVersion, AsyncLazy<VersionStamp> lazyLatestDocumentTopLevelChangeVersion) { this.projectInfo = projectInfo; this.solutionServices = solutionServices; this.languageServices = languageServices; this.documentIds = documentIds.ToImmutableReadOnlyListOrEmpty(); this.documentStates = documentStates; this.lazyLatestDocumentVersion = lazyLatestDocumentVersion; this.lazyLatestDocumentTopLevelChangeVersion = lazyLatestDocumentTopLevelChangeVersion; }
private ProjectState( ProjectInfo projectInfo, ILanguageServiceProvider languageServices, SolutionServices solutionServices, ImmutableList<DocumentId> documentIds, ImmutableDictionary<DocumentId, DocumentState> documentStates, AsyncLazy<VersionStamp> lazyLatestDocumentVersion, AsyncLazy<VersionStamp> lazyLatestDocumentTopLevelChangeVersion) { this.projectInfo = projectInfo; this.solutionServices = solutionServices; this.languageServices = languageServices; this.documentIds = documentIds; this.documentStates = documentStates; this.lazyLatestDocumentVersion = lazyLatestDocumentVersion; this.lazyLatestDocumentTopLevelChangeVersion = lazyLatestDocumentTopLevelChangeVersion; }
private void AddSourceFile(PInfo projectInfo, string file) { if (!File.Exists(file)) { return; } using (var stream = File.OpenRead(file)) { var sourceText = SourceText.From(stream, Encoding.UTF8); var id = DocumentId.CreateNewId(projectInfo.Id); var version = VersionStamp.Create(); var loader = TextLoader.From(TextAndVersion.Create(sourceText, version)); OnDocumentAdded(DocumentInfo.Create(id, file, filePath: file, loader: loader)); } }
private ProjectInfo FixProjectInfo(ProjectInfo projectInfo) { if (projectInfo.CompilationOptions == null) { var compilationFactory = this.languageServices.GetService<ICompilationFactoryService>(); if (compilationFactory != null) { projectInfo = projectInfo.WithCompilationOptions(compilationFactory.GetDefaultCompilationOptions()); } } if (projectInfo.ParseOptions == null) { var syntaxTreeFactory = this.languageServices.GetService<ISyntaxTreeFactoryService>(); if (syntaxTreeFactory != null) { projectInfo = projectInfo.WithParseOptions(syntaxTreeFactory.GetDefaultParseOptions()); } } return projectInfo; }
private ProjectState( ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices, IEnumerable<DocumentId> documentIds, IEnumerable<DocumentId> additionalDocumentIds, ImmutableDictionary<DocumentId, DocumentState> documentStates, ImmutableDictionary<DocumentId, TextDocumentState> additionalDocumentStates, AsyncLazy<VersionStamp> lazyLatestDocumentVersion, AsyncLazy<VersionStamp> lazyLatestDocumentTopLevelChangeVersion) { _projectInfo = projectInfo; _solutionServices = solutionServices; _languageServices = languageServices; _documentIds = documentIds.ToImmutableReadOnlyListOrEmpty(); _additionalDocumentIds = additionalDocumentIds.ToImmutableReadOnlyListOrEmpty(); _documentStates = documentStates; _additionalDocumentStates = additionalDocumentStates; _lazyLatestDocumentVersion = lazyLatestDocumentVersion; _lazyLatestDocumentTopLevelChangeVersion = lazyLatestDocumentTopLevelChangeVersion; _lazyChecksums = new AsyncLazy<ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true); }
internal ProjectState(ProjectInfo projectInfo, ILanguageServiceProvider languageServiceProvider, SolutionServices solutionServices) { Contract.ThrowIfNull(projectInfo); Contract.ThrowIfNull(languageServiceProvider); Contract.ThrowIfNull(solutionServices); this.languageServices = languageServiceProvider; this.solutionServices = solutionServices; this.projectInfo = FixProjectInfo(projectInfo); this.documentIds = this.projectInfo.Documents.Select(d => d.Id).ToImmutableList(); var docStates = ImmutableDictionary.CreateRange<DocumentId, DocumentState>( this.projectInfo.Documents.Select(d => new KeyValuePair<DocumentId, DocumentState>(d.Id, CreateDocument(this.ProjectInfo, d, languageServiceProvider, solutionServices)))); this.documentStates = docStates; this.lazyLatestDocumentVersion = new AsyncLazy<VersionStamp>(this.ComputeLatestDocumentVersionAsync, cacheResult: true); this.lazyLatestDocumentTopLevelChangeVersion = new AsyncLazy<VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(docStates, c), cacheResult: true); }
private ProjectId AddProject(IProjectContext context, string configuration) { var fullPath = context.ProjectFullPath; var projectInfo = PInfo.Create( ProjectId.CreateNewId(), VersionStamp.Create(), context.ProjectName, context.AssemblyName, LanguageNames.CSharp, fullPath); OnProjectAdded(projectInfo); foreach (var file in context.CompilationItems) { var filePath = Path.IsPathRooted(file) ? file : Path.Combine(Path.GetDirectoryName(fullPath), file); AddSourceFile(projectInfo, filePath); } return(projectInfo.Id); }
/// <summary> /// Create a new solution instance that includes a project with the specified project information. /// </summary> public SolutionState AddProject(ProjectInfo projectInfo) { if (projectInfo == null) { throw new ArgumentNullException(nameof(projectInfo)); } var projectId = projectInfo.Id; var language = projectInfo.Language; if (language == null) { throw new ArgumentNullException(nameof(language)); } var displayName = projectInfo.Name; if (displayName == null) { throw new ArgumentNullException(nameof(displayName)); } CheckNotContainsProject(projectId); var languageServices = this.Workspace.Services.GetLanguageServices(language); if (languageServices == null) { throw new ArgumentException(string.Format(WorkspacesResources.The_language_0_is_not_supported, language)); } var newProject = new ProjectState(projectInfo, languageServices, _solutionServices); return this.AddProject(newProject.Id, newProject); }
protected internal void OnProjectAdded(ProjectInfo projectInfo) { CurrentSolution.AddProject(projectInfo); }
/// <summary> /// Create a <see cref="ProjectInfo"/> structure initialized from a compilers command line arguments. /// </summary> public static ProjectInfo CreateProjectInfo(string projectName, string language, IEnumerable <string> commandLineArgs, string projectDirectory, Workspace workspace = null) { // TODO (tomat): the method may throw all sorts of exceptions. var tmpWorkspace = workspace ?? new AdhocWorkspace(DesktopMefHostServices.DefaultServices); var languageServices = tmpWorkspace.Services.GetLanguageServices(language); if (languageServices == null) { throw new ArgumentException(WorkspacesResources.Unrecognized_language_name); } var commandLineParser = languageServices.GetRequiredService <ICommandLineParserService>(); var commandLineArguments = commandLineParser.Parse(commandLineArgs, projectDirectory, isInteractive: false, sdkDirectory: RuntimeEnvironment.GetRuntimeDirectory()); var metadataService = tmpWorkspace.Services.GetRequiredService <IMetadataService>(); // we only support file paths in /r command line arguments var relativePathResolver = new RelativePathResolver(commandLineArguments.ReferencePaths, commandLineArguments.BaseDirectory); var commandLineMetadataReferenceResolver = new WorkspaceMetadataFileReferenceResolver( metadataService, relativePathResolver); var analyzerLoader = tmpWorkspace.Services.GetRequiredService <IAnalyzerService>().GetLoader(); var xmlFileResolver = new XmlFileResolver(commandLineArguments.BaseDirectory); var strongNameProvider = new DesktopStrongNameProvider(commandLineArguments.KeyFileSearchPaths); // resolve all metadata references. var boundMetadataReferences = commandLineArguments.ResolveMetadataReferences(commandLineMetadataReferenceResolver); var unresolvedMetadataReferences = boundMetadataReferences.FirstOrDefault(r => r is UnresolvedMetadataReference); if (unresolvedMetadataReferences != null) { throw new ArgumentException(string.Format(WorkspacesResources.Can_t_resolve_metadata_reference_colon_0, ((UnresolvedMetadataReference)unresolvedMetadataReferences).Reference)); } // resolve all analyzer references. foreach (var path in commandLineArguments.AnalyzerReferences.Select(r => r.FilePath)) { analyzerLoader.AddDependencyLocation(relativePathResolver.ResolvePath(path, baseFilePath: null)); } var boundAnalyzerReferences = commandLineArguments.ResolveAnalyzerReferences(analyzerLoader); var unresolvedAnalyzerReferences = boundAnalyzerReferences.FirstOrDefault(r => r is UnresolvedAnalyzerReference); if (unresolvedAnalyzerReferences != null) { throw new ArgumentException(string.Format(WorkspacesResources.Can_t_resolve_analyzer_reference_colon_0, ((UnresolvedAnalyzerReference)unresolvedAnalyzerReferences).Display)); } AssemblyIdentityComparer assemblyIdentityComparer; if (commandLineArguments.AppConfigPath != null) { try { using var appConfigStream = new FileStream(commandLineArguments.AppConfigPath, FileMode.Open, FileAccess.Read); assemblyIdentityComparer = DesktopAssemblyIdentityComparer.LoadFromXml(appConfigStream); } catch (Exception e) { throw new ArgumentException(string.Format(WorkspacesResources.An_error_occurred_while_reading_the_specified_configuration_file_colon_0, e.Message)); } } else { assemblyIdentityComparer = DesktopAssemblyIdentityComparer.Default; } var projectId = ProjectId.CreateNewId(debugName: projectName); // construct file infos var docs = new List <DocumentInfo>(); foreach (var fileArg in commandLineArguments.SourceFiles) { var absolutePath = Path.IsPathRooted(fileArg.Path) || string.IsNullOrEmpty(projectDirectory) ? Path.GetFullPath(fileArg.Path) : Path.GetFullPath(Path.Combine(projectDirectory, fileArg.Path)); var relativePath = PathUtilities.GetRelativePath(projectDirectory, absolutePath); var isWithinProject = PathUtilities.IsChildPath(projectDirectory, absolutePath); var folderRoot = isWithinProject ? Path.GetDirectoryName(relativePath) : ""; var folders = isWithinProject ? GetFolders(relativePath) : null; var name = Path.GetFileName(relativePath); var id = DocumentId.CreateNewId(projectId, absolutePath); var doc = DocumentInfo.Create( id: id, name: name, folders: folders, sourceCodeKind: fileArg.IsScript ? SourceCodeKind.Script : SourceCodeKind.Regular, loader: new FileTextLoader(absolutePath, commandLineArguments.Encoding), filePath: absolutePath); docs.Add(doc); } // construct file infos for additional files. var additionalDocs = new List <DocumentInfo>(); foreach (var fileArg in commandLineArguments.AdditionalFiles) { var absolutePath = Path.IsPathRooted(fileArg.Path) || string.IsNullOrEmpty(projectDirectory) ? Path.GetFullPath(fileArg.Path) : Path.GetFullPath(Path.Combine(projectDirectory, fileArg.Path)); var relativePath = PathUtilities.GetRelativePath(projectDirectory, absolutePath); var isWithinProject = PathUtilities.IsChildPath(projectDirectory, absolutePath); var folderRoot = isWithinProject ? Path.GetDirectoryName(relativePath) : ""; var folders = isWithinProject ? GetFolders(relativePath) : null; var name = Path.GetFileName(relativePath); var id = DocumentId.CreateNewId(projectId, absolutePath); var doc = DocumentInfo.Create( id: id, name: name, folders: folders, sourceCodeKind: SourceCodeKind.Regular, loader: new FileTextLoader(absolutePath, commandLineArguments.Encoding), filePath: absolutePath); additionalDocs.Add(doc); } // If /out is not specified and the project is a console app the csc.exe finds out the Main method // and names the compilation after the file that contains it. We don't want to create a compilation, // bind Mains etc. here. Besides the msbuild always includes /out in the command line it produces. // So if we don't have the /out argument we name the compilation "<anonymous>". string assemblyName = (commandLineArguments.OutputFileName != null) ? Path.GetFileNameWithoutExtension(commandLineArguments.OutputFileName) : "<anonymous>"; // TODO (tomat): what should be the assemblyName when compiling a netmodule? Should it be /moduleassemblyname var projectInfo = ProjectInfo.Create( projectId, VersionStamp.Create(), projectName, assemblyName, language: language, compilationOptions: commandLineArguments.CompilationOptions .WithXmlReferenceResolver(xmlFileResolver) .WithAssemblyIdentityComparer(assemblyIdentityComparer) .WithStrongNameProvider(strongNameProvider) // TODO (https://github.com/dotnet/roslyn/issues/4967): .WithMetadataReferenceResolver(new WorkspaceMetadataFileReferenceResolver(metadataService, new RelativePathResolver(ImmutableArray <string> .Empty, projectDirectory))), parseOptions: commandLineArguments.ParseOptions, documents: docs, additionalDocuments: additionalDocs, metadataReferences: boundMetadataReferences, analyzerReferences: boundAnalyzerReferences); return(projectInfo); }
private static ProjectInfo ClearAllDocumentsFromProjectInfo(ProjectInfo projectInfo) { return(projectInfo.WithDocuments(ImmutableArray <DocumentInfo> .Empty).WithAdditionalDocuments(ImmutableArray <DocumentInfo> .Empty)); }
/// <summary> /// Creates a new solution instance that includes a project with the specified language and names. /// </summary> public Solution AddProject(ProjectId projectId, string name, string assemblyName, string language) { return(this.AddProject(ProjectInfo.Create(projectId, VersionStamp.Create(), name, assemblyName, language))); }
public void TestInit() { workspace = new AdhocWorkspace(); project = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "TestProj", "TestProj", LanguageNames.CSharp) .WithMetadataReferences(new[] { MetadataReference.CreateFromAssembly(typeof(RedwoodConfiguration).Assembly), MetadataReference.CreateFromAssembly(typeof(object).Assembly) }); workspace.AddProject(project); workspace.AddDocument(project.Id, "test", SourceText.From("class A {}")); context = new RwHtmlCompletionContext() { Configuration = RedwoodConfiguration.CreateDefault(), RoslynWorkspace = workspace }; }
/// <summary> /// Adds a project to the workspace. All previous projects remain intact. /// </summary> public Project AddProject(string name, string language) { var info = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), name, name, language); return(this.AddProject(info)); }
public void OnProjectAdded(ProjectInfo projectInfo) { }
/// <summary> /// Create a new solution instance that includes a project with the specified project information. /// </summary> public Solution AddProject(ProjectInfo projectInfo) { var newState = _state.AddProject(projectInfo); if (newState == _state) { return this; } return new Solution(newState); }
private ProjectState With( ProjectInfo projectInfo = null, ImmutableArray<DocumentId> documentIds = default(ImmutableArray<DocumentId>), ImmutableArray<DocumentId> additionalDocumentIds = default(ImmutableArray<DocumentId>), ImmutableDictionary<DocumentId, DocumentState> documentStates = null, ImmutableDictionary<DocumentId, TextDocumentState> additionalDocumentStates = null, AsyncLazy<VersionStamp> latestDocumentVersion = null, AsyncLazy<VersionStamp> latestDocumentTopLevelChangeVersion = null, ValueSource<ProjectStateChecksums> lazyChecksums = null) { // for now, re-calculate all checksums when anything changed return new ProjectState( projectInfo ?? _projectInfo, _languageServices, _solutionServices, documentIds.IsDefault ? _documentIds : documentIds, additionalDocumentIds.IsDefault ? _additionalDocumentIds : additionalDocumentIds, documentStates ?? _documentStates, additionalDocumentStates ?? _additionalDocumentStates, latestDocumentVersion ?? _lazyLatestDocumentVersion, latestDocumentTopLevelChangeVersion ?? _lazyLatestDocumentTopLevelChangeVersion, lazyChecksums ?? _lazyChecksums); }
/// <summary> /// Create a new solution instance that includes a project with the specified project information. /// </summary> public Solution AddProject(ProjectInfo projectInfo) { if (projectInfo == null) { throw new ArgumentNullException("projectInfo"); } var projectId = projectInfo.Id; var language = projectInfo.Language; if (language == null) { throw new ArgumentNullException("language"); } var displayName = projectInfo.Name; if (displayName == null) { throw new ArgumentNullException("name"); } CheckNotContainsProject(projectId); var languageServiceProvider = this.solutionServices.LanguageServicesFactory.GetLanguageServiceProvider(language); if (languageServiceProvider == null) { throw new ArgumentException(string.Format(WorkspacesResources.UnsupportedLanguage, language)); } var newProject = new ProjectState(projectInfo, languageServiceProvider, this.solutionServices); return this.AddProject(newProject.Id, newProject); }
private void AddSourceFile(ProjectInfo projectInfo, string file) { using (var stream = File.OpenRead(file)) { var sourceText = SourceText.From(stream, encoding: Encoding.UTF8); var id = DocumentId.CreateNewId(projectInfo.Id); var version = VersionStamp.Create(); var loader = TextLoader.From(TextAndVersion.Create(sourceText, version)); OnDocumentAdded(DocumentInfo.Create(id, file, filePath: file, loader: loader)); } }
// public bool Initialized { get; set; } // // public BufferManager BufferManager { get; private set; } // // public OmnisharpWorkspace() : this(MefHostServices.DefaultHost) // { // } // public OmnisharpWorkspace(MefHostServices hostServices) : base(hostServices, "Custom") // { // BufferManager = new BufferManager(this); // } public void AddProject(ProjectInfo projectInfo) { OnProjectAdded(projectInfo); }
private static DocumentState CreateDocument(ProjectInfo projectInfo, DocumentInfo documentInfo, ILanguageServiceProvider languageServices, SolutionServices solutionServices) { var doc = DocumentState.Create(documentInfo, projectInfo.ParseOptions, languageServices, solutionServices); if (doc.SourceCodeKind != documentInfo.SourceCodeKind) { doc = doc.UpdateSourceCodeKind(documentInfo.SourceCodeKind); } return doc; }
protected internal void OnProjectAdded(ProjectInfo projectInfo) { CurrentSolution.AddProject (projectInfo); }
private ProjectState With( ProjectInfo projectInfo = null, ImmutableList<DocumentId> documentIds = null, ImmutableDictionary<DocumentId, DocumentState> documentStates = null, AsyncLazy<VersionStamp> latestDocumentVersion = null, AsyncLazy<VersionStamp> latestDocumentTopLevelChangeVersion = null) { return new ProjectState( projectInfo ?? this.projectInfo, this.languageServices, this.solutionServices, documentIds ?? this.documentIds, documentStates ?? this.documentStates, latestDocumentVersion ?? this.lazyLatestDocumentVersion, latestDocumentTopLevelChangeVersion ?? this.lazyLatestDocumentTopLevelChangeVersion); }
private ProjectState With( ProjectInfo projectInfo = null, ImmutableArray<DocumentId> documentIds = default(ImmutableArray<DocumentId>), ImmutableArray<DocumentId> additionalDocumentIds = default(ImmutableArray<DocumentId>), ImmutableDictionary<DocumentId, DocumentState> documentStates = null, ImmutableDictionary<DocumentId, TextDocumentState> additionalDocumentStates = null, AsyncLazy<VersionStamp> latestDocumentVersion = null, AsyncLazy<VersionStamp> latestDocumentTopLevelChangeVersion = null, Lazy<AnalyzerOptions> lazyAnalyzerOptions = null) { return new ProjectState( projectInfo ?? _projectInfo, _languageServices, _solutionServices, documentIds.IsDefault ? _documentIds : documentIds, additionalDocumentIds.IsDefault ? _additionalDocumentIds : additionalDocumentIds, documentStates ?? _documentStates, additionalDocumentStates ?? _additionalDocumentStates, latestDocumentVersion ?? _lazyLatestDocumentVersion, latestDocumentTopLevelChangeVersion ?? _lazyLatestDocumentTopLevelChangeVersion); }
/// <summary> /// Call this method to respond to a project being added/opened in the host environment. /// </summary> protected internal void OnProjectAdded(ProjectInfo projectInfo) { this.OnProjectAdded(projectInfo, silent: false); }
/// <summary> /// Create a ProjectInfo structure initialized from a compilers command line arguments. /// </summary> public static ProjectInfo CreateProjectInfo(Workspace workspace, string projectName, string language, IEnumerable <string> commandLineArgs, string projectDirectory) { // TODO (tomat): the method may throw all sorts of exceptions. var languageServices = LanguageService.GetProvider(workspace, language); if (languageServices == null) { throw new ArgumentException(WorkspacesResources.UnrecognizedLanguageName); } var commandLineArgumentsFactory = languageServices.GetService <ICommandLineArgumentsFactoryService>(); var commandLineArguments = commandLineArgumentsFactory.CreateCommandLineArguments(commandLineArgs, projectDirectory, isInteractive: false); // TODO (tomat): to match csc.exe/vbc.exe we should use CommonCommandLineCompiler.ExistingReferencesResolver to deal with #r's var referenceResolver = new MetadataFileReferenceResolver(commandLineArguments.ReferencePaths, commandLineArguments.BaseDirectory); var referenceProvider = workspace.CurrentSolution.MetadataReferenceProvider; var xmlFileResolver = new XmlFileResolver(commandLineArguments.BaseDirectory); var strongNameProvider = new DesktopStrongNameProvider(commandLineArguments.KeyFileSearchPaths); // resolve all metadata references. var boundMetadataReferences = commandLineArguments.ResolveMetadataReferences(referenceResolver, referenceProvider); var unresolvedMetadataReferences = boundMetadataReferences.FirstOrDefault(r => r is UnresolvedMetadataReference); if (unresolvedMetadataReferences != null) { throw new ArgumentException(string.Format(WorkspacesResources.CantResolveMetadataReference, ((UnresolvedMetadataReference)unresolvedMetadataReferences).Reference)); } // resolve all analyzer references. var boundAnalyzerReferences = commandLineArguments.ResolveAnalyzerReferences(); var unresolvedAnalyzerReferences = boundAnalyzerReferences.FirstOrDefault(r => r is UnresolvedAnalyzerReference); if (unresolvedAnalyzerReferences != null) { throw new ArgumentException(string.Format(WorkspacesResources.CantResolveAnalyzerReference, ((UnresolvedAnalyzerReference)unresolvedAnalyzerReferences).Display)); } AssemblyIdentityComparer assemblyIdentityComparer; if (commandLineArguments.AppConfigPath != null) { try { using (var appConfigStream = new FileStream(commandLineArguments.AppConfigPath, FileMode.Open, FileAccess.Read)) { assemblyIdentityComparer = DesktopAssemblyIdentityComparer.LoadFromXml(appConfigStream); } } catch (Exception e) { throw new ArgumentException(string.Format(WorkspacesResources.ErrorWhileReadingSpecifiedConfigFile, e.Message)); } } else { assemblyIdentityComparer = DesktopAssemblyIdentityComparer.Default; } var projectId = ProjectId.CreateNewId(debugName: projectName); // construct file infos var docs = new List <DocumentInfo>(); var ids = new HashSet <DocumentId>(); foreach (var fileArg in commandLineArguments.SourceFiles) { var absolutePath = Path.IsPathRooted(fileArg.Path) || string.IsNullOrEmpty(projectDirectory) ? Path.GetFullPath(fileArg.Path) : Path.GetFullPath(Path.Combine(projectDirectory, fileArg.Path)); var relativePath = FilePathUtilities.GetRelativePath(projectDirectory, absolutePath); var isWithinProject = !Path.IsPathRooted(relativePath); var folderRoot = isWithinProject ? Path.GetDirectoryName(relativePath) : ""; var folders = isWithinProject ? GetFolders(relativePath) : null; var name = Path.GetFileName(relativePath); var id = GetUniqueDocumentId(projectId, name, folderRoot, ids); var doc = DocumentInfo.Create( id: id, name: name, folders: folders, sourceCodeKind: fileArg.IsScript ? SourceCodeKind.Script : SourceCodeKind.Regular, loader: new FileTextLoader(absolutePath), filePath: absolutePath); docs.Add(doc); } // If /out is not specified and the project is a console app the csc.exe finds out the Main method // and names the compilation after the file that contains it. We don't want to create a compilation, // bind Mains etc. here. Besides the msbuild always includes /out in the command line it produces. // So if we don't have the /out argument we name the compilation "<anonymous>". string assemblyName = (commandLineArguments.OutputFileName != null) ? Path.GetFileNameWithoutExtension(commandLineArguments.OutputFileName) : "<anonymous>"; // TODO (tomat): what should be the assemblyName when compiling a netmodule? Should it be /moduleassemblyname var projectInfo = ProjectInfo.Create( projectId, VersionStamp.Create(), projectName, assemblyName, language: language, compilationOptions: commandLineArguments.CompilationOptions .WithXmlReferenceResolver(xmlFileResolver) .WithAssemblyIdentityComparer(assemblyIdentityComparer) .WithStrongNameProvider(strongNameProvider) .WithMetadataReferenceResolver(referenceResolver) .WithMetadataReferenceProvider(referenceProvider), parseOptions: commandLineArguments.ParseOptions, documents: docs, metadataReferences: boundMetadataReferences, analyzerReferences: boundAnalyzerReferences); return(projectInfo); }