当前位置: 首页>>代码示例>>C#>>正文


C# Document.GetTextVersionAsync方法代码示例

本文整理汇总了C#中Document.GetTextVersionAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Document.GetTextVersionAsync方法的具体用法?C# Document.GetTextVersionAsync怎么用?C# Document.GetTextVersionAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.GetTextVersionAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AnalyzeSyntaxAsync

        public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
        {
            // it has an assumption that this will not be called concurrently for same document.
            // in fact, in current design, it won't be even called concurrently for different documents.
            // but, can be called concurrently for different documents in future if we choose to.
            Contract.ThrowIfFalse(document.IsFromPrimaryBranch());

            var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);

            if (!documentOptions.GetOption(InternalFeatureOnOffOptions.TodoComments))
            {
                return;
            }

            // use tree version so that things like compiler option changes are considered
            var textVersion = await document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
            var syntaxVersion = await document.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false);

            var existingData = await _state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);
            if (existingData != null)
            {
                // check whether we can use the data as it is (can happen when re-using persisted data from previous VS session)
                if (CheckVersions(document, textVersion, syntaxVersion, existingData))
                {
                    Contract.Requires(_workspace == document.Project.Solution.Workspace);
                    RaiseTaskListUpdated(_workspace, document.Project.Solution, document.Id, existingData.Items);
                    return;
                }
            }

            var service = document.GetLanguageService<ITodoCommentService>();
            if (service == null)
            {
                return;
            }

            var tokens = await _todoCommentTokens.GetTokensAsync(document, cancellationToken).ConfigureAwait(false);
            var comments = await service.GetTodoCommentsAsync(document, tokens, cancellationToken).ConfigureAwait(false);
            var items = await CreateItemsAsync(document, comments, cancellationToken).ConfigureAwait(false);

            var data = new Data(textVersion, syntaxVersion, items);
            await _state.PersistAsync(document, data, cancellationToken).ConfigureAwait(false);

            // * NOTE * cancellation can't throw after this point.
            if (existingData == null || existingData.Items.Length > 0 || data.Items.Length > 0)
            {
                Contract.Requires(_workspace == document.Project.Solution.Workspace);
                RaiseTaskListUpdated(_workspace, document.Project.Solution, document.Id, data.Items);
            }
        }
开发者ID:orthoxerox,项目名称:roslyn,代码行数:50,代码来源:AbstractTodoCommentIncrementalAnalyzer.cs

示例2: AnalyzeDocumentAsync

        private async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, ImmutableHashSet<string> diagnosticIds, bool skipClosedFileChecks, CancellationToken cancellationToken)
        {
            try
            {
                if (!skipClosedFileChecks && !CheckOption(document.Project.Solution.Workspace, document.Project.Language, document.IsOpen()))
                {
                    return;
                }

                var textVersion = await document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
                var projectVersion = await document.Project.GetDependentVersionAsync(cancellationToken).ConfigureAwait(false);
                var dataVersion = await document.Project.GetDependentSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

                var versions = new VersionArgument(textVersion, dataVersion, projectVersion);
                if (bodyOpt == null)
                {
                    await AnalyzeDocumentAsync(document, versions, diagnosticIds, skipClosedFileChecks, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    // only open file can go this route
                    await AnalyzeBodyDocumentAsync(document, bodyOpt, versions, cancellationToken).ConfigureAwait(false);
                }
            }
            catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:29,代码来源:DiagnosticIncrementalAnalyzer.cs

示例3: AnalyzeSyntaxAsync

        private async Task AnalyzeSyntaxAsync(Document document, ImmutableHashSet<string> diagnosticIds, bool skipClosedFileChecks, CancellationToken cancellationToken)
        {
            try
            {
                if (!skipClosedFileChecks && !CheckOption(document.Project.Solution.Workspace, document.Project.Language, document.IsOpen()))
                {
                    return;
                }

                var textVersion = await document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
                var dataVersion = await document.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false);
                var versions = new VersionArgument(textVersion, dataVersion);

                var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
                var fullSpan = root == null ? null : (TextSpan?)root.FullSpan;

                var userDiagnosticDriver = new DiagnosticAnalyzerDriver(document, fullSpan, root, this, cancellationToken);
                var openedDocument = document.IsOpen();

                foreach (var stateSet in _stateManager.GetOrUpdateStateSets(document.Project))
                {
                    if (SkipRunningAnalyzer(document.Project.CompilationOptions, userDiagnosticDriver, openedDocument, skipClosedFileChecks, stateSet))
                    {
                        await ClearExistingDiagnostics(document, stateSet, StateType.Syntax, cancellationToken).ConfigureAwait(false);
                        continue;
                    }

                    if (ShouldRunAnalyzerForStateType(stateSet.Analyzer, StateType.Syntax, diagnosticIds))
                    {
                        var data = await _executor.GetSyntaxAnalysisDataAsync(userDiagnosticDriver, stateSet, versions).ConfigureAwait(false);
                        if (data.FromCache)
                        {
                            RaiseDiagnosticsUpdated(StateType.Syntax, document.Id, stateSet, new SolutionArgument(document), data.Items);
                            continue;
                        }

                        var state = stateSet.GetState(StateType.Syntax);
                        await state.PersistAsync(document, data.ToPersistData(), cancellationToken).ConfigureAwait(false);

                        RaiseDocumentDiagnosticsUpdatedIfNeeded(StateType.Syntax, document, stateSet, data.OldItems, data.Items);
                    }
                }
            }
            catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:48,代码来源:DiagnosticIncrementalAnalyzer.cs

示例4: GetDiagnosticsAsync

            public async Task<IEnumerable<DiagnosticData>> GetDiagnosticsAsync(Document document, TextSpan range, CancellationToken cancellationToken)
            {
                try
                {
                    var textVersion = await document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
                    var syntaxVersion = await document.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false);
                    var semanticVersion = await document.Project.GetDependentSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

                    var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

                    var result = true;
                    using (var diagnostics = SharedPools.Default<List<DiagnosticData>>().GetPooledObject())
                    {
                        result &= await TryGetLatestDiagnosticsAsync(
                                StateType.Syntax, document, range, root, diagnostics.Object, true,
                            (t, d) => t.Equals(textVersion) && d.Equals(syntaxVersion),
                            GetSyntaxDiagnosticsAsync, cancellationToken).ConfigureAwait(false);

                        result &= await TryGetLatestDiagnosticsAsync(
                                StateType.Document, document, range, root, diagnostics.Object, true,
                            (t, d) => t.Equals(textVersion) && d.Equals(semanticVersion),
                            GetSemanticDiagnosticsAsync, cancellationToken).ConfigureAwait(false);

                        // must be always up-to-date
                        Debug.Assert(result);
                        if (diagnostics.Object.Count > 0)
                        {
                            return diagnostics.Object.ToImmutableArray();
                        }

                        return SpecializedCollections.EmptyEnumerable<DiagnosticData>();
                    }
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:38,代码来源:DiagnosticAnalyzerService.IncrementalAnalyzer.cs

示例5: TryGetDiagnosticAsync

            public async Task<bool> TryGetDiagnosticAsync(Document document, TextSpan range, List<DiagnosticData> diagnostics, CancellationToken cancellationToken)
            {
                try
                {
                    var textVersion = await document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
                    var syntaxVersion = await document.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false);
                    var semanticVersion = await document.Project.GetDependentSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

                    var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

                    var result = true;
                    result &= await TryGetLatestDiagnosticsAsync(
                        StateType.Syntax, document, range, root, diagnostics, false,
                        (t, d) => t.Equals(textVersion) && d.Equals(syntaxVersion),
                        GetSyntaxDiagnosticsAsync, cancellationToken).ConfigureAwait(false);

                    result &= await TryGetLatestDiagnosticsAsync(
                        StateType.Document, document, range, root, diagnostics, false,
                        (t, d) => t.Equals(textVersion) && d.Equals(semanticVersion),
                        GetSemanticDiagnosticsAsync, cancellationToken).ConfigureAwait(false);

                    return result;
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:28,代码来源:DiagnosticAnalyzerService.IncrementalAnalyzer.cs

示例6: AnalyzeSyntaxAsync

            private async Task AnalyzeSyntaxAsync(Document document, ImmutableHashSet<string> diagnosticIds, bool skipClosedFileChecks, CancellationToken cancellationToken)
            {
                try
                {
                    if (!skipClosedFileChecks && !CheckOption(document.Project.Solution.Workspace, document.Project.Language, document.IsOpen()))
                    {
                        return;
                    }

                    var textVersion = await document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
                    var dataVersion = await document.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false);
                    var versions = new VersionArgument(textVersion, dataVersion);

                    var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
                    var fullSpan = root == null ? null : (TextSpan?)root.FullSpan;

                    var userDiagnosticDriver = new DiagnosticAnalyzerDriver(document, fullSpan, root, _diagnosticLogAggregator, cancellationToken);
                    var options = document.Project.CompilationOptions;
                    var openedDocument = document.IsOpen();

                    foreach (var providerAndId in await _analyzersAndState.GetAllProviderAndIdsAsync(document.Project, cancellationToken).ConfigureAwait(false))
                    {
                        var provider = providerAndId.Key;
                        var providerId = providerAndId.Value;

                        if (IsAnalyzerSuppressed(provider, options, userDiagnosticDriver))
                        {
                            await HandleSuppressedAnalyzerAsync(document, StateType.Syntax, providerId, provider, cancellationToken).ConfigureAwait(false);
                        }
                        else if (ShouldRunProviderForStateType(StateType.Syntax, provider, userDiagnosticDriver, diagnosticIds) &&
                            (skipClosedFileChecks || ShouldRunProviderForClosedFile(openedDocument, provider)))
                        {
                            var data = await _executor.GetSyntaxAnalysisDataAsync(provider, providerId, versions, userDiagnosticDriver).ConfigureAwait(false);
                            if (data.FromCache)
                            {
                                RaiseDiagnosticsUpdated(StateType.Syntax, document.Id, providerId, new SolutionArgument(document), data.Items);
                                continue;
                            }

                            var state = _analyzersAndState.GetOrCreateDiagnosticState(StateType.Syntax, providerId, provider, document.Project.Id, document.Project.Language);
                            await state.PersistAsync(document, data.ToPersistData(), cancellationToken).ConfigureAwait(false);

                            RaiseDiagnosticsUpdatedIfNeeded(StateType.Syntax, document, providerId, data.OldItems, data.Items);
                        }
                    }
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:51,代码来源:DiagnosticAnalyzerService.IncrementalAnalyzer.cs


注:本文中的Document.GetTextVersionAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。