private void RefreshCompilationOfSourceFilesInWorkspace(string bicepFileContents, string bicepConfigFileContents, bool saveBicepConfigFile, out Mock <ITextDocumentLanguageServer> document, out Container <Diagnostic>?diagnostics) { PublishDiagnosticsParams?receivedParams = null; document = BicepCompilationManagerHelper.CreateMockDocument(p => receivedParams = p); ILanguageServerFacade server = BicepCompilationManagerHelper.CreateMockServer(document).Object; string testOutputPath = Path.Combine(TestContext.ResultsDirectory, Guid.NewGuid().ToString()); var bicepFilePath = FileHelper.SaveResultFile(TestContext, "input.bicep", bicepFileContents, testOutputPath); var workspace = new Workspace(); var bicepCompilationManager = new BicepCompilationManager(server, BicepCompilationManagerHelper.CreateEmptyCompilationProvider(), workspace, new FileResolver(), BicepCompilationManagerHelper.CreateMockScheduler().Object, new ConfigurationManager(new IOFileSystem())); bicepCompilationManager.UpsertCompilation(DocumentUri.From(bicepFilePath), null, bicepFileContents, LanguageConstants.LanguageId); var bicepConfigDocumentUri = DocumentUri.FromFileSystemPath(bicepFilePath); if (saveBicepConfigFile) { string bicepConfigFilePath = FileHelper.SaveResultFile(TestContext, "bicepconfig.json", bicepConfigFileContents, testOutputPath); bicepConfigDocumentUri = DocumentUri.FromFileSystemPath(bicepConfigFilePath); } BicepConfigChangeHandler.RefreshCompilationOfSourceFilesInWorkspace(bicepCompilationManager, workspace); diagnostics = receivedParams?.Diagnostics; }
public override Task <Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken) { Container <FileEvent> fileEvents = request.Changes; IEnumerable <FileEvent> bicepConfigFileChangeEvents = fileEvents.Where(x => string.Equals(Path.GetFileName(x.Uri.Path), LanguageConstants.BicepConfigurationFileName, StringComparison.OrdinalIgnoreCase)); // Refresh compilation of source files in workspace when local bicepconfig.json file is created, deleted or changed if (bicepConfigFileChangeEvents.Any()) { Uri uri = bicepConfigFileChangeEvents.First().Uri.ToUri(); BicepConfigChangeHandler.RefreshCompilationOfSourceFilesInWorkspace(compilationManager, workspace); } compilationManager.HandleFileChanges(fileEvents); return(Unit.Task); }