Пример #1
0
        /// <summary>
        /// Gets the only <see cref="Document"/> along with related options and conventions.
        /// </summary>
        /// <param name="solution">A Solution containing a single Project containing a single Document.</param>
        /// <param name="editorConfig">The editorconfig to apply to the documents options set.</param>
        /// <returns>The document contained within along with option set and coding conventions.</returns>
        protected async Task <ImmutableArray <(DocumentId, OptionSet, ICodingConventionsSnapshot)> > GetOnlyFileToFormatAsync(Solution solution, IReadOnlyDictionary <string, string> editorConfig)
        {
            var document = GetOnlyDocument(solution);
            var options  = (OptionSet)await document.GetOptionsAsync();

            ICodingConventionsSnapshot codingConventions = new TestCodingConventionsSnapshot(editorConfig);

            options = OptionsApplier.ApplyConventions(options, codingConventions, Language);

            return(ImmutableArray.Create((document.Id, options, codingConventions)));
        }
Пример #2
0
        private protected async Task TestAsync(string testCode, string expectedCode, ICodeFormatter formatter, IReadOnlyDictionary <string, string> editorConfig)
        {
            TestCode = testCode;

            var solution = GetSolution(TestState.Sources.ToArray(), TestState.AdditionalFiles.ToArray(), TestState.AdditionalReferences.ToArray());
            var document = solution.Projects.Single().Documents.Single();
            var options  = (OptionSet)await document.GetOptionsAsync();

            ICodingConventionsSnapshot codingConventions = new TestCodingConventionsSnapshot(editorConfig);

            options = OptionsApplier.ApplyConventions(options, codingConventions, Language);

            var filesToFormat = new[] { (document, options, codingConventions) }.ToImmutableArray();
Пример #3
0
        private protected async Task TestAsync(string testCode, string expectedCode, IReadOnlyDictionary <string, string> editorConfig)
        {
            TestCode = testCode;

            var solution = GetSolution(TestState.Sources.ToArray(), TestState.AdditionalFiles.ToArray(), TestState.AdditionalReferences.ToArray());
            var project  = solution.Projects.Single();
            var document = project.Documents.Single();
            var options  = (OptionSet)await document.GetOptionsAsync();

            var formatOptions = new FormatOptions(
                workspaceFilePath: project.FilePath,
                isSolution: false,
                logLevel: LogLevel.Trace,
                saveFormattedFiles: false,
                changesAreErrors: false,
                filesToFormat: ImmutableHashSet.Create <string>(document.FilePath));

            ICodingConventionsSnapshot codingConventions = new TestCodingConventionsSnapshot(editorConfig);

            options = OptionsApplier.ApplyConventions(options, codingConventions, Language);

            var filesToFormat = new[] { (document, options, codingConventions) }.ToImmutableArray();
 private void SaveSettings()
 {
     NugetOptionsFactory.CreateDefault().Save(_options);
     OptionsApplier.CreateDefault().ApplyOptions(_options);
 }