public override void SaveSettingsToStorage() { EnsureOptionPageCreated(); // Allow page controls to perist their settings to the option store before updating the // option service. pageControl.OnSave(); // Save the changes that were accumulated in the option store. var oldOptions = s_optionService.GetOptions(); var newOptions = s_optionStore.GetOptions(); // Must log the option change before setting the new option values via s_optionService, // otherwise oldOptions and newOptions would be identical and nothing will be logged. OptionLogger.Log(oldOptions, newOptions); s_optionService.SetOptions(newOptions); // Make sure we load the next time a page is activated, in case that options changed // programmatically between now and the next time the page is activated s_needsToUpdateOptionStore = true; // For pages that don't use option bindings we need to load settings when it is // activated next. _needsLoadOnNextActivate = true; }
public void UpdatePreview(string text) { var service = VisualStudioMefHostServices.Create(_componentModel.GetService <ExportProvider>()); var workspace = new PreviewWorkspace(service); var fileName = "project." + (Language == "C#" ? "csproj" : "vbproj"); var project = workspace.CurrentSolution.AddProject(fileName, "assembly.dll", Language); // use the mscorlib, system, and system.core that are loaded in the current process. string[] references = { "mscorlib", "System", "System.Core" }; var metadataService = workspace.Services.GetService <IMetadataService>(); var referenceAssemblies = Thread.GetDomain().GetAssemblies() .Where(x => references.Contains(x.GetName(true).Name, StringComparer.OrdinalIgnoreCase)) .Select(a => metadataService.GetReference(a.Location, MetadataReferenceProperties.Assembly)); project = project.WithMetadataReferences(referenceAssemblies); var document = project.AddDocument("document", SourceText.From(text, Encoding.UTF8)); var fallbackFormattingOptions = _globalOptions.GetSyntaxFormattingOptions(document.Project.LanguageServices); var optionService = workspace.Services.GetRequiredService <IOptionService>(); var configOptions = OptionStore.GetOptions().AsAnalyzerConfigOptions(optionService, document.Project.Language); var formattingService = document.GetRequiredLanguageService <ISyntaxFormattingService>(); var formattingOptions = formattingService.GetFormattingOptions(configOptions, fallbackFormattingOptions); var formatted = Formatter.FormatAsync(document, formattingOptions, CancellationToken.None).WaitAndGetResult(CancellationToken.None); var textBuffer = _textBufferFactoryService.CreateTextBuffer(formatted.GetTextSynchronously(CancellationToken.None).ToString(), _contentType); var container = textBuffer.AsTextContainer(); var projection = _projectionBufferFactory.CreateProjectionBufferWithoutIndentation(_contentTypeRegistryService, _editorOptions.CreateOptions(), textBuffer.CurrentSnapshot, separator: "", exposedLineSpans: GetExposedLineSpans(textBuffer.CurrentSnapshot).ToArray()); var textView = _textEditorFactoryService.CreateTextView(projection, _textEditorFactoryService.CreateTextViewRoleSet(PredefinedTextViewRoles.Interactive)); this.TextViewHost = _textEditorFactoryService.CreateTextViewHost(textView, setFocus: false); workspace.TryApplyChanges(document.Project.Solution); workspace.OpenDocument(document.Id, container); this.TextViewHost.Closed += (s, a) => { workspace.Dispose(); workspace = null; }; }
public override void SaveSettingsToStorage() { EnsureOptionPageCreated(); // Save the changes that were accumulated in the option store. s_optionService.SetOptions(s_optionStore.GetOptions()); // Make sure we load the next time a page is activated, in case that options changed // programmatically between now and the next time the page is activated s_needsLoadOnNextActivate = true; }