Beispiel #1
0
        public DocumentId TryAddMiscellaneousDocument(string filePath, string language)
        {
            if (GetDocument(filePath) != null)
            {
                return(null); //if the workspace already knows about this document then it is not a miscellaneous document
            }
            var projectInfo = miscDocumentsProjectInfos.GetOrAdd(language, (lang) => CreateMiscFilesProject(lang));
            var documentId  = AddDocument(projectInfo.Id, filePath);

            _logger.LogInformation($"Miscellaneous file: {filePath} added to workspace");

            if (!EditorConfigEnabled)
            {
                return(documentId);
            }

            var analyzerConfigFiles    = projectInfo.AnalyzerConfigDocuments.Select(document => document.FilePath);
            var newAnalyzerConfigFiles = EditorConfigFinder
                                         .GetEditorConfigPaths(filePath)
                                         .Except(analyzerConfigFiles);

            foreach (var analyzerConfigFile in newAnalyzerConfigFiles)
            {
                AddAnalyzerConfigDocument(projectInfo.Id, analyzerConfigFile);
            }

            return(documentId);
        }
            public static SolutionInfo LoadSolutionInfo(string folderPath, SourceFileMatcher fileMatcher)
            {
                var absoluteFolderPath = Path.GetFullPath(folderPath, Directory.GetCurrentDirectory());

                var filePaths         = GetMatchingFilePaths(absoluteFolderPath, fileMatcher);
                var editorConfigPaths = EditorConfigFinder.GetEditorConfigPaths(folderPath);

                var projectInfos = ImmutableArray.CreateBuilder <ProjectInfo>(ProjectLoaders.Length);

                // Create projects for each of the supported languages.
                foreach (var loader in ProjectLoaders)
                {
                    var projectInfo = loader.LoadProjectInfo(folderPath, filePaths, editorConfigPaths);
                    if (projectInfo is null)
                    {
                        continue;
                    }

                    projectInfos.Add(projectInfo);
                }

                // Construct workspace from loaded project infos.
                return(SolutionInfo.Create(
                           SolutionId.CreateNewId(debugName: absoluteFolderPath),
                           version: default,
Beispiel #3
0
        public ProjectInfo CreateProject(string csxFileName, IEnumerable <MetadataReference> references, string csxFilePath, Type globalsType, IEnumerable <string> namespaces = null)
        {
            var csharpCommandLineArguments = _commandLineArgs.Value;

            // if RSP file was used, include the metadata references from RSP merged with the provided set
            // otherwise just use the provided metadata references
            if (csharpCommandLineArguments != null && csharpCommandLineArguments.MetadataReferences.Any())
            {
                var resolvedRspReferences = csharpCommandLineArguments.ResolveMetadataReferences(_compilationOptions.Value.MetadataReferenceResolver);
                foreach (var resolvedRspReference in resolvedRspReferences)
                {
                    if (resolvedRspReference is UnresolvedMetadataReference)
                    {
                        _logger.LogWarning($"{csxFileName} project. Skipping RSP reference to: {resolvedRspReference.Display} as it can't be resolved.");
                    }
                    else
                    {
                        _logger.LogDebug($"{csxFileName} project. Adding RSP reference to: {resolvedRspReference.Display}");
                    }
                }

                references = resolvedRspReferences.
                             Where(reference => !(reference is UnresolvedMetadataReference)).
                             Union(references, MetadataReferenceEqualityComparer.Instance);
            }

            var projectId = ProjectId.CreateNewId();
            var analyzerConfigDocuments = _editorConfigEnabled
                ? EditorConfigFinder
                                          .GetEditorConfigPaths(csxFilePath)
                                          .Select(path =>
                                                  DocumentInfo.Create(
                                                      DocumentId.CreateNewId(projectId),
                                                      name: ".editorconfig",
                                                      loader: new FileTextLoader(path, Encoding.UTF8),
                                                      filePath: path))
                                          .ToImmutableArray()
                : ImmutableArray <DocumentInfo> .Empty;

            var project = ProjectInfo.Create(
                filePath: csxFilePath,
                id: projectId,
                version: VersionStamp.Create(),
                name: csxFileName,
                assemblyName: $"{csxFileName}.dll",
                language: LanguageNames.CSharp,
                compilationOptions: namespaces == null
                    ? _compilationOptions.Value
                    : _compilationOptions.Value.WithUsings(namespaces),
                metadataReferences: references,
                parseOptions: ParseOptions,
                isSubmission: true,
                hostObjectType: globalsType)
                          .WithAnalyzerConfigDocuments(analyzerConfigDocuments);

            return(project);
        }
Beispiel #4
0
        public static IEnumerable <ProjectId> AddProjectToWorkspace(OmniSharpWorkspace workspace, string filePath, string[] frameworks, TestFile[] testFiles, TestFile[] otherFiles = null, ImmutableArray <AnalyzerReference> analyzerRefs = default)
        {
            otherFiles ??= Array.Empty <TestFile>();

            var versionStamp = VersionStamp.Create();
            var references   = GetReferences();

            frameworks = frameworks ?? new[] { string.Empty };
            var projectsIds       = new List <ProjectId>();
            var editorConfigPaths = EditorConfigFinder.GetEditorConfigPaths(filePath);

            foreach (var framework in frameworks)
            {
                var projectId = ProjectId.CreateNewId();
                var analyzerConfigDocuments = editorConfigPaths.Select(path =>
                                                                       DocumentInfo.Create(
                                                                           DocumentId.CreateNewId(projectId),
                                                                           name: ".editorconfig",
                                                                           loader: new FileTextLoader(path, Encoding.UTF8),
                                                                           filePath: path))
                                              .ToImmutableArray();

                var projectInfo = ProjectInfo.Create(
                    id: projectId,
                    version: versionStamp,
                    name: "OmniSharp+" + framework,
                    assemblyName: "AssemblyName",
                    language: LanguageNames.CSharp,
                    filePath: filePath,
                    metadataReferences: references,
                    analyzerReferences: analyzerRefs)
                                  .WithDefaultNamespace("OmniSharpTest")
                                  .WithAnalyzerConfigDocuments(analyzerConfigDocuments);

                workspace.AddProject(projectInfo);

                foreach (var testFile in testFiles)
                {
                    workspace.AddDocument(projectInfo.Id, testFile.FileName, TextLoader.From(TextAndVersion.Create(testFile.Content.Text, versionStamp)), SourceCodeKind.Regular);
                }

                foreach (var otherFile in otherFiles)
                {
                    workspace.AddAdditionalDocument(projectInfo.Id, otherFile.FileName, TextLoader.From(TextAndVersion.Create(otherFile.Content.Text, versionStamp)));
                }

                projectsIds.Add(projectInfo.Id);
            }

            return(projectsIds);
        }
        private ProjectInfo GetProject(CakeScript cakeScript, string filePath)
        {
            var name = Path.GetFileName(filePath);

            if (!File.Exists(cakeScript.Host.AssemblyPath))
            {
                throw new FileNotFoundException($"Cake is not installed. Path {cakeScript.Host.AssemblyPath} does not exist.");
            }
            var hostObjectType = Type.GetType(cakeScript.Host.TypeName, a => _assemblyLoader.LoadFrom(cakeScript.Host.AssemblyPath, dontLockAssemblyOnDisk: true), null, false);

            if (hostObjectType == null)
            {
                throw new InvalidOperationException($"Could not get host object type: {cakeScript.Host.TypeName}.");
            }

            var projectId = ProjectId.CreateNewId(Guid.NewGuid().ToString());
            var analyzerConfigDocuments = _workspace.EditorConfigEnabled
                ? EditorConfigFinder
                                          .GetEditorConfigPaths(filePath)
                                          .Select(path =>
                                                  DocumentInfo.Create(
                                                      DocumentId.CreateNewId(projectId),
                                                      name: ".editorconfig",
                                                      loader: new FileTextLoader(path, Encoding.UTF8),
                                                      filePath: path))
                                          .ToImmutableArray()
                : ImmutableArray <DocumentInfo> .Empty;

            return(ProjectInfo.Create(
                       id: projectId,
                       version: VersionStamp.Create(),
                       name: name,
                       filePath: filePath,
                       assemblyName: $"{name}.dll",
                       language: LanguageNames.CSharp,
                       compilationOptions: cakeScript.Usings == null ? _compilationOptions.Value : _compilationOptions.Value.WithUsings(cakeScript.Usings),
                       parseOptions: new CSharpParseOptions(LanguageVersion.Latest, DocumentationMode.Parse, SourceCodeKind.Script),
                       metadataReferences: GetMetadataReferences(cakeScript.References),
                       // TODO: projectReferences?
                       isSubmission: true,
                       hostObjectType: hostObjectType)
                   .WithAnalyzerConfigDocuments(analyzerConfigDocuments));
        }
            public virtual async Task <ProjectInfo?> LoadProjectInfoAsync(string folderPath, Matcher fileMatcher, CancellationToken cancellationToken)
            {
                var projectId = ProjectId.CreateNewId(debugName: folderPath);

                var documents = await LoadDocumentInfosAsync(projectId, folderPath, FileExtension, fileMatcher);

                if (documents.IsDefaultOrEmpty)
                {
                    return(null);
                }

                var editorConfigDocuments = EditorConfigFinder.GetEditorConfigPaths(folderPath)
                                            .Select(path =>
                                                    DocumentInfo.Create(
                                                        DocumentId.CreateNewId(projectId),
                                                        name: path,
                                                        loader: new FileTextLoader(path, Encoding.UTF8),
                                                        filePath: path))
                                            .ToImmutableArray();

                return(ProjectInfo.Create(
                           projectId,
                           version: default,