Пример #1
0
        public async Task <BraceMatchingResult?> FindBracesAsync(
            Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken)
        {
            if (!options.HighlightRelatedJsonComponentsUnderCursor)
            {
                return(null);
            }

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

            var token = root.FindToken(position);

            var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var detector = JsonLanguageDetector.GetOrCreate(semanticModel.Compilation, _info);

            // We do support brace matching in strings that look very likely to be json, even if we aren't 100% certain
            // if it truly is json.
            var tree = detector.TryParseString(token, semanticModel, includeProbableStrings: true, cancellationToken);

            if (tree == null)
            {
                return(null);
            }

            return(GetMatchingBraces(tree, position));
        }
Пример #2
0
        public BraceMatchingResult?FindBraces(
            Project project,
            SemanticModel semanticModel,
            SyntaxToken token,
            int position,
            BraceMatchingOptions options,
            CancellationToken cancellationToken)
        {
            if (!options.HighlightingOptions.HighlightRelatedJsonComponentsUnderCursor)
            {
                return(null);
            }

            var info     = project.GetRequiredLanguageService <IEmbeddedLanguagesProvider>().EmbeddedLanguageInfo;
            var detector = JsonLanguageDetector.GetOrCreate(semanticModel.Compilation, info);

            // We do support brace matching in strings that look very likely to be json, even if we aren't 100% certain
            // if it truly is json.
            var tree = detector.TryParseString(token, semanticModel, includeProbableStrings: true, cancellationToken);

            if (tree == null)
            {
                return(null);
            }

            return(GetMatchingBraces(tree, position));
        }