public void UpsertCompilation(DocumentUri documentUri, int?version, string fileContents, string?languageId = null) { if (this.ShouldUpsertCompilation(documentUri, languageId)) { var newFile = SourceFileFactory.CreateSourceFile(documentUri.ToUri(), fileContents); UpsertCompilationInternal(documentUri, version, newFile); } }
public static SourceFileGrouping CreateForFiles(IReadOnlyDictionary <Uri, string> fileContentsByUri, Uri entryFileUri, IFileResolver fileResolver) { var workspace = new Workspace(); var sourceFiles = fileContentsByUri.Select(kvp => SourceFileFactory.CreateSourceFile(kvp.Key, kvp.Value)); workspace.UpsertSourceFiles(sourceFiles); return(SourceFileGroupingBuilder.Build(fileResolver, new ModuleDispatcher(new DefaultModuleRegistryProvider(fileResolver)), workspace, entryFileUri)); }
private static Compilation GetCompilation(string fileContents) { var fileUri = new Uri("inmemory:///main.bicep"); var workspace = new Workspace(); var sourceFile = SourceFileFactory.CreateSourceFile(fileUri, fileContents); workspace.UpsertSourceFile(sourceFile); var fileResolver = new FileResolver(); var dispatcher = new ModuleDispatcher(new EmptyModuleRegistryProvider()); var sourceFileGrouping = SourceFileGroupingBuilder.Build(fileResolver, dispatcher, workspace, fileUri); return(new Compilation(resourceTypeProvider, sourceFileGrouping)); }
private static Compilation GetCompilation(string fileContents) { var fileUri = new Uri("inmemory:///main.bicep"); var workspace = new Workspace(); var sourceFile = SourceFileFactory.CreateSourceFile(fileUri, fileContents); workspace.UpsertSourceFile(sourceFile); var fileResolver = new FileResolver(); var dispatcher = new ModuleDispatcher(new EmptyModuleRegistryProvider()); var configurationManager = new ConfigurationManager(new IOFileSystem()); var configuration = configurationManager.GetBuiltInConfiguration(); var sourceFileGrouping = SourceFileGroupingBuilder.Build(fileResolver, dispatcher, workspace, fileUri, configuration); return(new Compilation(namespaceProvider, sourceFileGrouping, configuration)); }
public static SourceFileGrouping CreateForFiles(IReadOnlyDictionary <Uri, string> fileContentsByUri, Uri entryFileUri, IFileResolver fileResolver, RootConfiguration configuration, IFeatureProvider?features = null) { features ??= BicepTestConstants.Features; var workspace = new Workspace(); var sourceFiles = fileContentsByUri.Select(kvp => SourceFileFactory.CreateSourceFile(kvp.Key, kvp.Value)); workspace.UpsertSourceFiles(sourceFiles); return(SourceFileGroupingBuilder.Build( fileResolver, new ModuleDispatcher( new DefaultModuleRegistryProvider( fileResolver, BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory, features)), workspace, entryFileUri, configuration)); }
public void Create_ShouldReturnValidCompilation() { var fileUri = DocumentUri.Parse($"/{DataSets.Parameters_LF.Name}.bicep"); var fileResolver = CreateFileResolver(fileUri.ToUri(), DataSets.Parameters_LF.Bicep); var dispatcher = new ModuleDispatcher(new DefaultModuleRegistryProvider(fileResolver)); var provider = new BicepCompilationProvider(TestTypeHelper.CreateEmptyProvider(), fileResolver, dispatcher); var sourceFile = SourceFileFactory.CreateSourceFile(fileUri.ToUri(), DataSets.Parameters_LF.Bicep); var workspace = new Workspace(); workspace.UpsertSourceFile(sourceFile); var context = provider.Create(workspace, fileUri, ImmutableDictionary <ISourceFile, ISemanticModel> .Empty); context.Compilation.Should().NotBeNull(); // TODO: remove Where when the support of modifiers is dropped. context.Compilation.GetEntrypointSemanticModel().GetAllDiagnostics(new ConfigHelper().GetDisabledLinterConfig()).Should().BeEmpty(); context.LineStarts.Should().NotBeEmpty(); context.LineStarts[0].Should().Be(0); }
public void Create_ShouldReturnValidCompilation() { var fileUri = DocumentUri.Parse($"/{DataSets.Parameters_LF.Name}.bicep"); var fileResolver = CreateFileResolver(fileUri.ToUri(), DataSets.Parameters_LF.Bicep); var dispatcher = new ModuleDispatcher(new DefaultModuleRegistryProvider(fileResolver, BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory, BicepTestConstants.Features)); var provider = new BicepCompilationProvider(BicepTestConstants.Features, TestTypeHelper.CreateWithAzTypes(), fileResolver, dispatcher); var sourceFile = SourceFileFactory.CreateSourceFile(fileUri.ToUri(), DataSets.Parameters_LF.Bicep); var workspace = new Workspace(); workspace.UpsertSourceFile(sourceFile); var configuration = BicepTestConstants.BuiltInConfigurationWithAnalyzersDisabled; var context = provider.Create(workspace, fileUri, ImmutableDictionary <ISourceFile, ISemanticModel> .Empty, configuration, new LinterAnalyzer(configuration)); context.Compilation.Should().NotBeNull(); // TODO: remove Where when the support of modifiers is dropped. context.Compilation.GetEntrypointSemanticModel().GetAllDiagnostics().Should().BeEmpty(); context.LineStarts.Should().NotBeEmpty(); context.LineStarts[0].Should().Be(0); }
public void UpsertCompilation(DocumentUri documentUri, int?version, string fileContents, string?languageId = null) { if (this.ShouldUpsertCompilation(documentUri, languageId)) { var newFile = SourceFileFactory.CreateSourceFile(documentUri.ToUri(), fileContents); var firstChanges = workspace.UpsertSourceFile(newFile); var removedFiles = firstChanges.removed; var modelLookup = new Dictionary <ISourceFile, ISemanticModel>(); if (newFile is BicepFile) { // Do not update compilation if it is an ARM template file, since it cannot be an entrypoint. UpdateCompilationInternal(documentUri, version, modelLookup, removedFiles); } foreach (var(entrypointUri, context) in activeContexts) { if (removedFiles.Any(x => context.Compilation.SourceFileGrouping.SourceFiles.Contains(x))) { UpdateCompilationInternal(entrypointUri, null, modelLookup, removedFiles); } } } }