示例#1
0
 public DiagnosticReportingOptions(
     DiagnosticReportingMode onPathFailure,
     DiagnosticReportingMode onLoaderFailure)
 {
     OnPathFailure   = onPathFailure;
     OnLoaderFailure = onLoaderFailure;
 }
示例#2
0
        public void Report(
            DiagnosticReportingMode mode,
            string message,
            Func <string, Exception>?createException = null
            )
        {
            switch (mode)
            {
            case DiagnosticReportingMode.Throw:
                if (createException is not null)
                {
                    throw createException(message);
                }

                throw new InvalidOperationException(message);

            case DiagnosticReportingMode.Log:
                Report(new WorkspaceDiagnostic(WorkspaceDiagnosticKind.Failure, message));
                break;

            case DiagnosticReportingMode.Ignore:
                break;

            default:
                throw new ArgumentException(
                          string.Format(
                              WorkspaceMSBuildResources.Invalid_0_specified_1,
                              nameof(DiagnosticReportingMode),
                              nameof(mode)
                              ),
                          nameof(mode)
                          );
            }
        }
示例#3
0
        public bool TryGetAbsoluteProjectPath(
            string path,
            string baseDirectory,
            DiagnosticReportingMode reportingMode,
            [NotNullWhen(true)] out string?absolutePath
            )
        {
            try
            {
                absolutePath = GetAbsolutePath(path, baseDirectory);
            }
            catch (Exception)
            {
                _diagnosticReporter.Report(
                    reportingMode,
                    string.Format(WorkspacesResources.Invalid_project_file_path_colon_0, path)
                    );
                absolutePath = null;
                return(false);
            }

            if (!File.Exists(absolutePath))
            {
                _diagnosticReporter.Report(
                    reportingMode,
                    string.Format(WorkspacesResources.Project_file_not_found_colon_0, absolutePath),
                    msg => new FileNotFoundException(msg)
                    );
                return(false);
            }

            return(true);
        }
示例#4
0
        public bool TryGetLoaderFromProjectPath(string projectFilePath, DiagnosticReportingMode mode, out IProjectFileLoader loader)
        {
            using (_dataGuard.DisposableWait())
            {
                var extension = Path.GetExtension(projectFilePath);
                if (extension.Length > 0 && extension[0] == '.')
                {
                    extension = extension.Substring(1);
                }

                if (_extensionToLanguageMap.TryGetValue(extension, out var language))
                {
                    if (_workspaceServices.SupportedLanguages.Contains(language))
                    {
                        loader = _workspaceServices.GetLanguageServices(language).GetService <IProjectFileLoader>();
                    }
                    else
                    {
                        loader = null;
                        _diagnosticReporter.Report(mode, string.Format(WorkspacesResources.Cannot_open_project_0_because_the_language_1_is_not_supported, projectFilePath, language));
                        return(false);
                    }
                }
                else
                {
                    loader = ProjectFileLoader.GetLoaderForProjectFileExtension(_workspaceServices, extension);

                    if (loader == null)
                    {
                        _diagnosticReporter.Report(mode, string.Format(WorkspacesResources.Cannot_open_project_0_because_the_file_extension_1_is_not_associated_with_a_language, projectFilePath, Path.GetExtension(projectFilePath)));
                        return(false);
                    }
                }

                // since we have both C# and VB loaders in this same library, it no longer indicates whether we have full language support available.
                if (loader != null)
                {
                    language = loader.Language;

                    // check for command line parser existing... if not then error.
                    var commandLineParser = _workspaceServices
                                            .GetLanguageServices(language)
                                            .GetService <ICommandLineParserService>();

                    if (commandLineParser == null)
                    {
                        loader = null;
                        _diagnosticReporter.Report(mode, string.Format(WorkspacesResources.Cannot_open_project_0_because_the_language_1_is_not_supported, projectFilePath, language));
                        return(false);
                    }
                }

                return(loader != null);
            }
        }
        public bool TryGetLoaderFromProjectPath(string?projectFilePath, DiagnosticReportingMode mode, [NotNullWhen(true)] out IProjectFileLoader?loader)
        {
            using (_dataGuard.DisposableWait())
            {
                var extension = Path.GetExtension(projectFilePath);
                if (extension is null)
                {
                    loader = null;
                    _diagnosticReporter.Report(mode, $"Project file path was 'null'");
                    return(false);
                }

                if (extension.Length > 0 && extension[0] == '.')
                {
                    extension = extension[1..];
示例#6
0
        public void Report(DiagnosticReportingMode mode, string message, Func <string, Exception> createException = null)
        {
            switch (mode)
            {
            case DiagnosticReportingMode.Throw:
                if (createException != null)
                {
                    throw createException(message);
                }

                throw new InvalidOperationException(message);

            case DiagnosticReportingMode.Log:
                Report(new WorkspaceDiagnostic(WorkspaceDiagnosticKind.Failure, message));
                break;

            case DiagnosticReportingMode.Ignore:
                break;

            default:
                throw new ArgumentException($"Invalid {nameof(DiagnosticReportingMode)} specified: {mode}", nameof(mode));
            }
        }