protected static void CommonGetObjectData(CompilationOptions options, SerializationInfo info, StreamingContext context)
 {
     info.AddValue(OutputKindString, (int)options.OutputKind);
     info.AddValue(ModuleNameString, options.ModuleName);
     info.AddValue(MainTypeNameString, options.MainTypeName);
     info.AddValue(ScriptClassNameString, options.ScriptClassName);
     info.AddValue(CryptoKeyContainerString, options.CryptoKeyContainer);
     info.AddValue(CryptoKeyFileString, options.CryptoKeyFile);
     info.AddValue(DelaySignString, options.DelaySign);
     info.AddValue(CheckOverflowString, options.CheckOverflow);
     info.AddValue(FileAlignmentString, options.FileAlignment);
     info.AddValue(BaseAddressString, options.BaseAddress);
     info.AddValue(PlatformString, (int)options.Platform);
     info.AddValue(GeneralDiagnosticOptionString, (int)options.GeneralDiagnosticOption);
     info.AddValue(WarningLevelString, options.WarningLevel);
     info.AddValue(SpecificDiagnosticOptionsString, new Dictionary<string, ReportDiagnostic>(options.SpecificDiagnosticOptions));
     info.AddValue(HighEntropyVirtualAddressSpaceString, options.HighEntropyVirtualAddressSpace);
     info.AddValue(DebugInformationKindString, (int)options.DebugInformationKind);
     info.AddValue(OptimizeString, options.Optimize);
     info.AddValue(SubsystemVersionMajorString, options.SubsystemVersion.Major);
     info.AddValue(SubsystemVersionMinorString, options.SubsystemVersion.Minor);
     info.AddValue(ConcurrentBuildString, options.ConcurrentBuild);
     info.AddValue(MetadataImportOptionsString, (byte)options.MetadataImportOptions);
     info.AddValue(FeaturesString, options.Features.ToArray());
 }
示例#2
0
 private void SetOptionsCore(CompilationOptions newCompilationOptions)
 {
     lock (_gate)
     {
         _currentCompilationOptions = newCompilationOptions;
     }
 }
 /// <param name="files">Can pass in multiple file contents with individual source kind: files will be named test1.vb, test2.vbx, etc.</param>
 public static Task<TestWorkspace> CreateWorkspaceFromFilesAsync(
     string[] files,
     ParseOptions[] parseOptions = null,
     CompilationOptions compilationOptions = null,
     ExportProvider exportProvider = null)
 {
     return TestWorkspaceFactory.CreateWorkspaceFromFilesAsync(LanguageNames.VisualBasic, compilationOptions, parseOptions, files, exportProvider);
 }
示例#4
0
 public TestHostSolution(
     HostLanguageServices languageServiceProvider,
     CompilationOptions compilationOptions,
     ParseOptions parseOptions,
     params MetadataReference[] references)
     : this(new TestHostProject(languageServiceProvider, compilationOptions, parseOptions, references))
 {
 }
 /// <param name="files">Can pass in multiple file contents: files will be named test1.vb, test2.vb, etc. and additional metadata references</param>
 public static TestWorkspace CreateWorkspaceFromFiles(
     string[] files,
     ParseOptions parseOptions = null,
     CompilationOptions compilationOptions = null,
     ExportProvider exportProvider = null,
     string[] metadataReferences = null)
 {
     return TestWorkspaceFactory.CreateWorkspaceFromFiles(LanguageNames.VisualBasic, compilationOptions, parseOptions, files, exportProvider, metadataReferences);
 }
 public static Task<TestWorkspace> CreateWorkspaceFromFileAsync(
     string file,
     ParseOptions parseOptions = null,
     CompilationOptions compilationOptions = null,
     ExportProvider exportProvider = null,
     string[] metadataReferences = null)
 {
     return CreateWorkspaceFromFilesAsync(new[] { file }, parseOptions, compilationOptions, exportProvider, metadataReferences);
 }
 protected void TestMissing(
     string initialMarkup,
     ParseOptions parseOptions,
     CompilationOptions compilationOptions,
     Func<dynamic, dynamic> nodeLocator = null)
 {
     using (var workspace = CreateWorkspaceFromFile(initialMarkup, parseOptions, compilationOptions))
     {
         var codeIssueOrRefactoring = GetCodeRefactoring(workspace, nodeLocator);
         Assert.Null(codeIssueOrRefactoring);
     }
 }
        /// <summary>
        /// Sets the given compilation and parse options.
        /// </summary>
        protected void SetOptions(CompilationOptions newCompilationOptions, ParseOptions newParseOptions)
        {
            this.UpdateRuleSetError(this.RuleSetFile);

            // Set options.
            CurrentCompilationOptions = newCompilationOptions;
            CurrentParseOptions = newParseOptions;

            if (_pushingChangesToWorkspaceHosts)
            {
                this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnOptionsChanged(Id, newCompilationOptions, newParseOptions));
            }
        }
 protected static void CommonGetObjectData(CompilationOptions options, SerializationInfo info, StreamingContext context)
 {
     info.AddValue(OutputKindString, (int)options.OutputKind);
     info.AddValue(ModuleNameString, options.ModuleName);
     info.AddValue(MainTypeNameString, options.MainTypeName);
     info.AddValue(ScriptClassNameString, options.ScriptClassName);
     info.AddValue(CryptoKeyContainerString, options.CryptoKeyContainer);
     info.AddValue(CryptoKeyFileString, options.CryptoKeyFile);
     info.AddValue(DelaySignString, options.DelaySign);
     info.AddValue(CheckOverflowString, options.CheckOverflow);
     info.AddValue(PlatformString, (int)options.Platform);
     info.AddValue(GeneralDiagnosticOptionString, (int)options.GeneralDiagnosticOption);
     info.AddValue(WarningLevelString, options.WarningLevel);
     info.AddValue(SpecificDiagnosticOptionsString, new Dictionary<string, ReportDiagnostic>(options.SpecificDiagnosticOptions));
     info.AddValue(OptimizeString, (int)options.OptimizationLevel);
     info.AddValue(ConcurrentBuildString, options.ConcurrentBuild);
     info.AddValue(ExtendedCustomDebugInformationString, options.ExtendedCustomDebugInformation);
     info.AddValue(MetadataImportOptionsString, (byte)options.MetadataImportOptions);
     info.AddValue(FeaturesString, options.Features.ToArray());
 }
示例#10
0
 private ProjectInfo(
     ProjectAttributes attributes,
     CompilationOptions compilationOptions,
     ParseOptions parseOptions,
     IEnumerable<DocumentInfo> documents,
     IEnumerable<ProjectReference> projectReferences,
     IEnumerable<MetadataReference> metadataReferences,
     IEnumerable<AnalyzerReference> analyzerReferences,
     IEnumerable<DocumentInfo> additionalDocuments,
     Type hostObjectType)
 {
     Attributes = attributes;
     CompilationOptions = compilationOptions;
     ParseOptions = parseOptions;
     Documents = documents.ToImmutableReadOnlyListOrEmpty();
     ProjectReferences = projectReferences.ToImmutableReadOnlyListOrEmpty();
     MetadataReferences = metadataReferences.ToImmutableReadOnlyListOrEmpty();
     AnalyzerReferences = analyzerReferences.ToImmutableReadOnlyListOrEmpty();
     AdditionalDocuments = additionalDocuments.ToImmutableReadOnlyListOrEmpty();
     HostObjectType = hostObjectType;
 }
示例#11
0
        private IEnumerable<DiagnosticItem> GetDiagnosticItems(string language, CompilationOptions options)
        {
            // Within an analyzer assembly, an individual analyzer may report multiple different diagnostics
            // with the same ID. Or, multiple analyzers may report diagnostics with the same ID. Or a
            // combination of the two may occur.
            // We only want to show one node in Solution Explorer for a given ID. So we pick one, but we need
            // to be consistent in which one we pick. Diagnostics with the same ID may have different
            // descriptions or messages, and it would be strange if the node's name changed from one run of
            // VS to another. So we group the diagnostics by ID, sort them within a group, and take the first
            // one.

            return _item.AnalyzerReference.GetAnalyzers(language)
                .SelectMany(a => _diagnosticAnalyzerService.GetDiagnosticDescriptors(a))
                .GroupBy(d => d.Id)
                .OrderBy(g => g.Key, StringComparer.CurrentCulture)
                .Select(g =>
                {
                    var selectedDiagnostic = g.OrderBy(d => d, s_comparer).First();
                    var effectiveSeverity = selectedDiagnostic.GetEffectiveSeverity(options);
                    return new DiagnosticItem(_item, selectedDiagnostic, effectiveSeverity, _commandHandler.DiagnosticContextMenuController);
                });
        }
        internal async Task TestAsync(
            string initialMarkup, string expectedMarkup,
            ParseOptions parseOptions, CompilationOptions compilationOptions,
            int index = 0, bool compareTokens = true,
            IDictionary<OptionKey, object> options = null,
            string fixAllActionEquivalenceKey = null,
            object fixProviderData = null,
            CodeActionPriority? priority = null)
        {
            string expected;
            IDictionary<string, IList<TextSpan>> spanMap;
            MarkupTestFile.GetSpans(expectedMarkup.NormalizeLineEndings(), out expected, out spanMap);

            var conflictSpans = spanMap.GetOrAdd("Conflict", _ => new List<TextSpan>());
            var renameSpans = spanMap.GetOrAdd("Rename", _ => new List<TextSpan>());
            var warningSpans = spanMap.GetOrAdd("Warning", _ => new List<TextSpan>());

            using (var workspace = IsWorkspaceElement(initialMarkup)
                ? await TestWorkspace.CreateAsync(initialMarkup)
                : await CreateWorkspaceFromFileAsync(initialMarkup, parseOptions, compilationOptions))
            {
                workspace.ApplyOptions(options);

                var actions = await GetCodeActionsAsync(workspace, fixAllActionEquivalenceKey, fixProviderData);
                await TestActionsAsync(
                    workspace, expected, index,
                    actions,
                    conflictSpans, renameSpans, warningSpans,
                    compareTokens: compareTokens,
                    parseOptions: parseOptions,
                    priority: priority);
            }
        }
 protected abstract Task<TestWorkspace> CreateWorkspaceFromFileAsync(string definition, ParseOptions parseOptions, CompilationOptions compilationOptions);
 private async Task TestAddDocument(
     string initialMarkup, string expectedMarkup,
     int index,
     IList<string> expectedContainers,
     string expectedDocumentName,
     ParseOptions parseOptions, CompilationOptions compilationOptions,
     bool compareTokens, bool isLine)
 {
     using (var workspace = isLine
         ? await CreateWorkspaceFromFileAsync(initialMarkup, parseOptions, compilationOptions)
         : await TestWorkspace.CreateAsync(initialMarkup))
     {
         var codeActions = await GetCodeActionsAsync(workspace, fixAllActionEquivalenceKey: null);
         await TestAddDocument(workspace, expectedMarkup, index, expectedContainers, expectedDocumentName,
             codeActions, compareTokens);
     }
 }
示例#15
0
 /// <summary>
 /// Returns true if all the diagnostics that can be produced by this analyzer are suppressed through options.
 /// </summary>
 public static bool IsDiagnosticAnalyzerSuppressed(this DiagnosticAnalyzer analyzer, CompilationOptions options)
 {
     return(CompilationWithAnalyzers.IsDiagnosticAnalyzerSuppressed(analyzer, options));
 }
示例#16
0
        private ProjectInfo With(
            ProjectAttributes attributes = null,
            CompilationOptions compilationOptions = null,
            ParseOptions parseOptions = null,
            IEnumerable<DocumentInfo> documents = null,
            IEnumerable<ProjectReference> projectReferences = null,
            IEnumerable<MetadataReference> metadataReferences = null,
            IEnumerable<AnalyzerReference> analyzerReferences = null,
            IEnumerable<DocumentInfo> additionalDocuments = null,
            Optional<Type> hostObjectType = default(Optional<Type>))
        {
            var newAttributes = attributes ?? Attributes;
            var newCompilationOptions = compilationOptions ?? CompilationOptions;
            var newParseOptions = parseOptions ?? ParseOptions;
            var newDocuments = documents ?? Documents;
            var newProjectReferences = projectReferences ?? ProjectReferences;
            var newMetadataReferences = metadataReferences ?? MetadataReferences;
            var newAnalyzerReferences = analyzerReferences ?? AnalyzerReferences;
            var newAdditionalDocuments = additionalDocuments ?? AdditionalDocuments;
            var newHostObjectType = hostObjectType.HasValue ? hostObjectType.Value : HostObjectType;

            if (newAttributes == Attributes &&
                newCompilationOptions == CompilationOptions &&
                newParseOptions == ParseOptions &&
                newDocuments == Documents &&
                newProjectReferences == ProjectReferences &&
                newMetadataReferences == MetadataReferences &&
                newAnalyzerReferences == AnalyzerReferences &&
                newAdditionalDocuments == AdditionalDocuments &&
                newHostObjectType == HostObjectType)
            {
                return this;
            }

            return new ProjectInfo(
                    newAttributes,
                    newCompilationOptions,
                    newParseOptions,
                    newDocuments,
                    newProjectReferences,
                    newMetadataReferences,
                    newAnalyzerReferences,
                    newAdditionalDocuments,
                    newHostObjectType);
        }
示例#17
0
 public ProjectInfo WithCompilationOptions(CompilationOptions compilationOptions)
 {
     return With(compilationOptions: compilationOptions);
 }
示例#18
0
        protected bool EqualsHelper(CompilationOptions other)
        {
            if (object.ReferenceEquals(other, null))
            {
                return false;
            }

            // NOTE: StringComparison.Ordinal is used for type name comparisons, even for VB.  That's because
            // a change in the canonical case should still change the option.
            bool equal =
                   this.CheckOverflow == other.CheckOverflow &&
                   this.ConcurrentBuild == other.ConcurrentBuild &&
                   this.ExtendedCustomDebugInformation == other.ExtendedCustomDebugInformation &&
                   this.DebugPlusMode == other.DebugPlusMode &&
                   string.Equals(this.CryptoKeyContainer, other.CryptoKeyContainer, StringComparison.Ordinal) &&
                   string.Equals(this.CryptoKeyFile, other.CryptoKeyFile, StringComparison.Ordinal) &&
                   this.CryptoPublicKey.SequenceEqual(other.CryptoPublicKey) &&
                   this.DelaySign == other.DelaySign &&
                   this.GeneralDiagnosticOption == other.GeneralDiagnosticOption &&
                   string.Equals(this.MainTypeName, other.MainTypeName, StringComparison.Ordinal) &&
                   this.MetadataImportOptions == other.MetadataImportOptions &&
                   string.Equals(this.ModuleName, other.ModuleName, StringComparison.Ordinal) &&
                   this.OptimizationLevel == other.OptimizationLevel &&
                   this.OutputKind == other.OutputKind &&
                   this.Platform == other.Platform &&
                   this.ReportSuppressedDiagnostics == other.ReportSuppressedDiagnostics &&
                   string.Equals(this.ScriptClassName, other.ScriptClassName, StringComparison.Ordinal) &&
                   this.SpecificDiagnosticOptions.SequenceEqual(other.SpecificDiagnosticOptions, (left, right) => (left.Key == right.Key) && (left.Value == right.Value)) &&
                   this.WarningLevel == other.WarningLevel &&
                   object.Equals(this.MetadataReferenceResolver, other.MetadataReferenceResolver) &&
                   object.Equals(this.XmlReferenceResolver, other.XmlReferenceResolver) &&
                   object.Equals(this.SourceReferenceResolver, other.SourceReferenceResolver) &&
                   object.Equals(this.StrongNameProvider, other.StrongNameProvider) &&
                   object.Equals(this.AssemblyIdentityComparer, other.AssemblyIdentityComparer);

            return equal;
        }
示例#19
0
        public ProjectState UpdateCompilationOptions(CompilationOptions options)
        {
            if (options == this.CompilationOptions)
            {
                return this;
            }

            return this.With(projectInfo: this.ProjectInfo.WithCompilationOptions(options).WithVersion(this.Version.GetNewerVersion()));
        }
示例#20
0
        /// <summary>
        /// Create a new solution instance with the project specified updated to have
        /// the specified compilation options.
        /// </summary>
        public SolutionState WithProjectCompilationOptions(ProjectId projectId, CompilationOptions options)
        {
            if (projectId == null)
            {
                throw new ArgumentNullException(nameof(projectId));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            CheckContainsProject(projectId);

            var oldProject = this.GetProjectState(projectId);
            var newProject = oldProject.UpdateCompilationOptions(options);

            if (oldProject == newProject)
            {
                return this;
            }

            return this.ForkProject(newProject, CompilationTranslationAction.ProjectCompilationOptions(options));
        }
示例#21
0
        private ProjectInfo With(
            ProjectId id = null,
            VersionStamp? version = default(VersionStamp?),
            string name = null,
            string assemblyName = null,
            string language = null,
            Optional<string> filePath = default(Optional<string>),
            Optional<string> outputPath = default(Optional<string>),
            CompilationOptions compilationOptions = null,
            ParseOptions parseOptions = null,
            IEnumerable<DocumentInfo> documents = null,
            IEnumerable<ProjectReference> projectReferences = null,
            IEnumerable<MetadataReference> metadataReferences = null,
            IEnumerable<AnalyzerReference> analyzerReferences = null,
            Optional<bool> isSubmission = default(Optional<bool>),
            Optional<Type> hostObjectType = default(Optional<Type>))
        {
            var newId = id ?? this.Id;
            var newVersion = version.HasValue ? version.Value : this.Version;
            var newName = name ?? this.Name;
            var newAssemblyName = assemblyName ?? this.AssemblyName;
            var newLanguage = language ?? this.Language;
            var newFilepath = filePath.HasValue ? filePath.Value : this.FilePath;
            var newOutputPath = outputPath.HasValue ? outputPath.Value : this.OutputFilePath;
            var newCompilationOptions = compilationOptions ?? this.CompilationOptions;
            var newParseOptions = parseOptions ?? this.ParseOptions;
            var newDocuments = documents ?? this.Documents;
            var newProjectReferences = projectReferences ?? this.ProjectReferences;
            var newMetadataReferences = metadataReferences ?? this.MetadataReferences;
            var newAnalyzerReferences = analyzerReferences ?? this.AnalyzerReferences;
            var newIsSubmission = isSubmission.HasValue ? isSubmission.Value : this.IsSubmission;
            var newHostObjectType = hostObjectType.HasValue ? hostObjectType.Value : this.HostObjectType;

            if (newId == this.Id &&
                newVersion == this.Version &&
                newName == this.Name &&
                newAssemblyName == this.AssemblyName &&
                newLanguage == this.Language &&
                newFilepath == this.FilePath &&
                newOutputPath == this.OutputFilePath &&
                newCompilationOptions == this.CompilationOptions &&
                newParseOptions == this.ParseOptions &&
                newDocuments == this.Documents &&
                newProjectReferences == this.ProjectReferences &&
                newMetadataReferences == this.MetadataReferences &&
                newAnalyzerReferences == this.AnalyzerReferences &&
                newIsSubmission == this.IsSubmission &&
                newHostObjectType == this.HostObjectType)
            {
                return this;
            }

            return new ProjectInfo(
                    newId,
                    newVersion,
                    newName,
                    newAssemblyName,
                    newLanguage,
                    newFilepath,
                    newOutputPath,
                    newCompilationOptions,
                    newParseOptions,
                    newDocuments,
                    newProjectReferences,
                    newMetadataReferences,
                    newAnalyzerReferences,
                    newIsSubmission,
                    newHostObjectType);
        }
示例#22
0
 public ProjectInfo WithCompilationOptions(CompilationOptions compilationOptions)
 {
     return(With(compilationOptions: compilationOptions));
 }
示例#23
0
 /// <summary>
 /// Creates a new instance of this project updated to have the specified compilation options.
 /// </summary>
 public Project WithCompilationOptions(CompilationOptions options)
 {
     return(this.Solution.WithProjectCompilationOptions(this.Id, options).GetProject(this.Id));
 }
示例#24
0
        private void GenerateSqmData(CompilationOptions compilationOptions, ImmutableArray <Diagnostic> diagnostics)
        {
            // Generate SQM data file for Compilers
            if (Arguments.SqmSessionGuid != Guid.Empty)
            {
                IVsSqmMulti sqm        = null;
                uint        sqmSession = 0u;
                try
                {
                    sqm = SqmServiceProvider.TryGetSqmService(_clientDirectory);
                    if (sqm != null)
                    {
                        sqm.BeginSession(this.GetSqmAppID(), false, out sqmSession);
                        sqm.SetGlobalSessionGuid(Arguments.SqmSessionGuid);

                        // Build Version
                        sqm.SetStringDatapoint(sqmSession, SqmServiceProvider.DATAID_SQM_BUILDVERSION, GetAssemblyFileVersion());

                        // Write Errors and Warnings from build
                        foreach (var diagnostic in diagnostics)
                        {
                            switch (diagnostic.Severity)
                            {
                            case DiagnosticSeverity.Error:
                                sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_ERRORNUMBERS, (uint)diagnostic.Code);
                                break;

                            case DiagnosticSeverity.Warning:
                                sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_WARNINGNUMBERS, (uint)diagnostic.Code);
                                break;

                            case DiagnosticSeverity.Hidden:
                            case DiagnosticSeverity.Info:
                                break;

                            default:
                                throw ExceptionUtilities.UnexpectedValue(diagnostic.Severity);
                            }
                        }

                        //Suppress Warnings / warningCode as error / warningCode as warning
                        foreach (var item in compilationOptions.SpecificDiagnosticOptions)
                        {
                            uint code;
                            if (TryGetCompilerDiagnosticCode(item.Key, out code))
                            {
                                ReportDiagnostic options = item.Value;
                                switch (options)
                                {
                                case ReportDiagnostic.Suppress:
                                    sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_SUPPRESSWARNINGNUMBERS, code);          // Suppress warning
                                    break;

                                case ReportDiagnostic.Error:
                                    sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_WARNASERRORS_NUMBERS, code);           // Warning as errors
                                    break;

                                case ReportDiagnostic.Warn:
                                    sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_WARNASWARNINGS_NUMBERS, code);         // Warning as warnings
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                        sqm.SetDatapoint(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_OUTPUTKIND, (uint)compilationOptions.OutputKind);
                        CompilerSpecificSqm(sqm, sqmSession);
                    }
                }
                finally
                {
                    if (sqm != null)
                    {
                        sqm.EndSession(sqmSession);
                    }
                }
            }
        }
        protected async Task TestMissingAsync(
            string initialMarkup,
            ParseOptions parseOptions, CompilationOptions compilationOptions,
            IDictionary<OptionKey, object> options = null,
            string fixAllActionEquivalenceKey = null,
            object fixProviderData = null)
        {
            using (var workspace = await CreateWorkspaceFromFileAsync(initialMarkup, parseOptions, compilationOptions))
            {
                workspace.ApplyOptions(options);

                var actions = await GetCodeActionsAsync(workspace, fixAllActionEquivalenceKey, fixProviderData);
                Assert.True(actions == null || actions.Count == 0);
            }
        }
        private void GenerateSqmData(CompilationOptions compilationOptions, ImmutableArray<Diagnostic> diagnostics)
        {
            // Generate SQM data file for Compilers
            if (Arguments.SqmSessionGuid != Guid.Empty)
            {
                IVsSqmMulti sqm = null;
                uint sqmSession = 0u;
                try
                {
                    sqm = SqmServiceProvider.TryGetSqmService(_clientDirectory);
                    if (sqm != null)
                    {
                        sqm.BeginSession(this.GetSqmAppID(), false, out sqmSession);
                        sqm.SetGlobalSessionGuid(Arguments.SqmSessionGuid);

                        // Build Version
                        sqm.SetStringDatapoint(sqmSession, SqmServiceProvider.DATAID_SQM_BUILDVERSION, GetAssemblyFileVersion());

                        // Write Errors and Warnings from build
                        foreach (var diagnostic in diagnostics)
                        {
                            switch (diagnostic.Severity)
                            {
                                case DiagnosticSeverity.Error:
                                    sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_ERRORNUMBERS, (uint)diagnostic.Code);
                                    break;

                                case DiagnosticSeverity.Warning:
                                    sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_WARNINGNUMBERS, (uint)diagnostic.Code);
                                    break;

                                case DiagnosticSeverity.Hidden:
                                case DiagnosticSeverity.Info:
                                    break;

                                default:
                                    throw ExceptionUtilities.UnexpectedValue(diagnostic.Severity);
                            }
                        }

                        //Suppress Warnings / warningCode as error / warningCode as warning
                        foreach (var item in compilationOptions.SpecificDiagnosticOptions)
                        {
                            uint code;
                            if (TryGetCompilerDiagnosticCode(item.Key, out code))
                            {
                                ReportDiagnostic options = item.Value;
                                switch (options)
                                {
                                    case ReportDiagnostic.Suppress:
                                        sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_SUPPRESSWARNINGNUMBERS, code);      // Suppress warning
                                        break;

                                    case ReportDiagnostic.Error:
                                        sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_WARNASERRORS_NUMBERS, code);       // Warning as errors
                                        break;

                                    case ReportDiagnostic.Warn:
                                        sqm.AddItemToStream(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_WARNASWARNINGS_NUMBERS, code);     // Warning as warnings
                                        break;

                                    default:
                                        break;
                                }
                            }
                        }
                        sqm.SetDatapoint(sqmSession, SqmServiceProvider.DATAID_SQM_ROSLYN_OUTPUTKIND, (uint)compilationOptions.OutputKind);
                        CompilerSpecificSqm(sqm, sqmSession);
                    }
                }
                finally
                {
                    if (sqm != null)
                    {
                        sqm.EndSession(sqmSession);
                    }
                }
            }
        }
示例#27
0
 internal bool CanReuseCompilationReferenceManager(CompilationOptions other)
 {
     // This condition has to include all options the Assembly Manager depends on when binding references.
     // In addition, the assembly name is determined based upon output kind. It is special for netmodules.
     // Can't reuse when file resolver or identity comparers change.
     // Can reuse even if StrongNameProvider changes. When resolving a cyclic reference only the simple name is considered, not the strong name.
     return this.MetadataImportOptions == other.MetadataImportOptions
         && this.OutputKind.IsNetModule() == other.OutputKind.IsNetModule()
         && object.Equals(this.XmlReferenceResolver, other.XmlReferenceResolver)
         && object.Equals(this.MetadataReferenceResolver, other.MetadataReferenceResolver)
         && object.Equals(this.AssemblyIdentityComparer, other.AssemblyIdentityComparer);
 }
 protected async Task TestSmartTagTextAsync(
     string initialMarkup,
     string displayText,
     int index = 0,
     ParseOptions parseOptions = null,
     CompilationOptions compilationOptions = null,
     object fixProviderData = null)
 {
     using (var workspace = await CreateWorkspaceFromFileAsync(initialMarkup, parseOptions, compilationOptions))
     {
         var actions = await GetCodeActionsAsync(workspace, fixAllActionEquivalenceKey: null, fixProviderData: fixProviderData);
         Assert.Equal(displayText, actions.ElementAt(index).Title);
     }
 }
示例#29
0
 /// <summary>
 /// Create a new instance of a ProjectInfo.
 /// </summary>
 public static ProjectInfo Create(
     ProjectId id,
     VersionStamp version,
     string name,
     string assemblyName,
     string language,
     string filePath = null,
     string outputFilePath = null,
     CompilationOptions compilationOptions = null,
     ParseOptions parseOptions = null,
     IEnumerable<DocumentInfo> documents = null,
     IEnumerable<ProjectReference> projectReferences = null,
     IEnumerable<MetadataReference> metadataReferences = null,
     IEnumerable<AnalyzerReference> analyzerReferences = null,
     IEnumerable<DocumentInfo> additionalDocuments = null,
     bool isSubmission = false,
     Type hostObjectType = null)
 {
     return Create(
         id, version, name, assemblyName, language,
         filePath, outputFilePath, compilationOptions, parseOptions,
         documents, projectReferences, metadataReferences, analyzerReferences, additionalDocuments,
         isSubmission, hostObjectType, hasAllInformation: true);
 }
        protected async Task TestExactActionSetOfferedAsync(
            string initialMarkup,
            IEnumerable<string> expectedActionSet,
            ParseOptions parseOptions = null,
            CompilationOptions compilationOptions = null)
        {
            using (var workspace = await CreateWorkspaceFromFileAsync(initialMarkup, parseOptions, compilationOptions))
            {
                var actions = await GetCodeActionsAsync(workspace, fixAllActionEquivalenceKey: null);

                var actualActionSet = actions.Select(a => a.Title);
                Assert.True(actualActionSet.SequenceEqual(expectedActionSet),
                    "Expected: " + string.Join(", ", expectedActionSet) +
                    "\nActual: " + string.Join(", ", actualActionSet));
            }
        }
示例#31
0
 /// <summary>
 /// Create a new instance of a ProjectInfo.
 /// </summary>
 internal static ProjectInfo Create(
     ProjectId id,
     VersionStamp version,
     string name,
     string assemblyName,
     string language,
     string filePath,
     string outputFilePath,
     CompilationOptions compilationOptions,
     ParseOptions parseOptions,
     IEnumerable<DocumentInfo> documents,
     IEnumerable<ProjectReference> projectReferences,
     IEnumerable<MetadataReference> metadataReferences,
     IEnumerable<AnalyzerReference> analyzerReferences,
     IEnumerable<DocumentInfo> additionalDocuments,
     bool isSubmission,
     Type hostObjectType,
     bool hasAllInformation)
 {
     return new ProjectInfo(
         new ProjectAttributes(
             id,
             version,
             name,
             assemblyName,
             language,
             filePath,
             outputFilePath,
             isSubmission,
             hasAllInformation),
         compilationOptions,
         parseOptions,
         documents,
         projectReferences,
         metadataReferences,
         analyzerReferences,
         additionalDocuments,
         hostObjectType);
 }
        protected async Task TestActionCountAsync(
            string initialMarkup,
            int count,
            ParseOptions parseOptions = null, CompilationOptions compilationOptions = null)
        {
            using (var workspace = await CreateWorkspaceFromFileAsync(initialMarkup, parseOptions, compilationOptions))
            {
                var actions = await GetCodeActionsAsync(workspace, fixAllActionEquivalenceKey: null);

                Assert.Equal(count, actions.Count());
            }
        }
示例#33
0
        private ProjectInfo(
            ProjectId id,
            VersionStamp version,
            string name,
            string assemblyName,
            string language,
            string filePath,
            string outputFilePath,
            CompilationOptions compilationOptions,
            ParseOptions parseOptions,
            IEnumerable<DocumentInfo> documents,
            IEnumerable<ProjectReference> projectReferences,
            IEnumerable<MetadataReference> metadataReferences,
            IEnumerable<AnalyzerReference> analyzerReferences,
            bool isSubmission,
            Type hostObjectType)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            if (name == null)
            {
                throw new ArgumentNullException("displayName");
            }

            if (assemblyName == null)
            {
                throw new ArgumentNullException("assemblyName");
            }

            if (language == null)
            {
                throw new ArgumentNullException("language");
            }

            this.Id = id;
            this.Version = version;
            this.Name = name;
            this.AssemblyName = assemblyName;
            this.Language = language;
            this.FilePath = filePath;
            this.OutputFilePath = outputFilePath;
            this.CompilationOptions = compilationOptions;
            this.ParseOptions = parseOptions;
            this.Documents = documents.ToImmutableReadOnlyListOrEmpty();
            this.ProjectReferences = projectReferences.ToImmutableReadOnlyListOrEmpty();
            this.MetadataReferences = metadataReferences.ToImmutableReadOnlyListOrEmpty();
            this.AnalyzerReferences = analyzerReferences.ToImmutableReadOnlyListOrEmpty();
            this.IsSubmission = isSubmission;
            this.HostObjectType = hostObjectType;
        }
示例#34
0
        private ProjectInfo With(
            ProjectId id                                       = null,
            VersionStamp?version                               = default(VersionStamp?),
            string name                                        = null,
            string assemblyName                                = null,
            string language                                    = null,
            Optional <string> filePath                         = default(Optional <string>),
            Optional <string> outputPath                       = default(Optional <string>),
            CompilationOptions compilationOptions              = null,
            ParseOptions parseOptions                          = null,
            IEnumerable <DocumentInfo> documents               = null,
            IEnumerable <ProjectReference> projectReferences   = null,
            IEnumerable <MetadataReference> metadataReferences = null,
            Optional <bool> isSubmission                       = default(Optional <bool>),
            Optional <Type> hostObjectType                     = default(Optional <Type>))
        {
            var newId                 = id ?? this.Id;
            var newVersion            = version.HasValue ? version.Value : this.Version;
            var newName               = name ?? this.Name;
            var newAssemblyName       = assemblyName ?? this.AssemblyName;
            var newLanguage           = language ?? this.Language;
            var newFilepath           = filePath.HasValue ? filePath.Value : this.FilePath;
            var newOutputPath         = outputPath.HasValue ? outputPath.Value : this.OutputFilePath;
            var newCompilationOptions = compilationOptions ?? this.CompilationOptions;
            var newParseOptions       = parseOptions ?? this.ParseOptions;
            var newDocuments          = documents ?? this.Documents;
            var newProjectReferences  = projectReferences ?? this.ProjectReferences;
            var newMetadataReferences = metadataReferences ?? this.MetadataReferences;
            var newIsSubmission       = isSubmission.HasValue ? isSubmission.Value : this.IsSubmission;
            var newHostObjectType     = hostObjectType.HasValue ? hostObjectType.Value : this.HostObjectType;

            if (newId == this.Id &&
                newVersion == this.Version &&
                newName == this.Name &&
                newAssemblyName == this.AssemblyName &&
                newLanguage == this.Language &&
                newFilepath == this.FilePath &&
                newOutputPath == this.OutputFilePath &&
                newCompilationOptions == this.CompilationOptions &&
                newParseOptions == this.ParseOptions &&
                newDocuments == this.Documents &&
                newProjectReferences == this.ProjectReferences &&
                newMetadataReferences == this.MetadataReferences &&
                newIsSubmission == this.IsSubmission &&
                newHostObjectType == this.HostObjectType)
            {
                return(this);
            }

            return(new ProjectInfo(
                       newId,
                       newVersion,
                       newName,
                       newAssemblyName,
                       newLanguage,
                       newFilepath,
                       newOutputPath,
                       newCompilationOptions,
                       newParseOptions,
                       newDocuments,
                       newProjectReferences,
                       newMetadataReferences,
                       newIsSubmission,
                       newHostObjectType));
        }
 public static CompilationTranslationAction ProjectCompilationOptions(CompilationOptions options)
 {
     return new ProjectCompilationOptionsAction(options);
 }
 /// <summary>
 /// Produces the filtering action for the diagnostic based on the options passed in.
 /// </summary>
 /// <returns>
 /// A new <see cref="DiagnosticInfo"/> with new effective severity based on the options or null if the
 /// diagnostic has been suppressed.
 /// </returns>
 public abstract ReportDiagnostic GetDiagnosticReport(DiagnosticInfo diagnosticInfo, CompilationOptions options);