private bool TryClassify(IEmbeddedLanguageClassifier classifier, EmbeddedLanguageClassificationContext context)
            {
                var count = _result.Count;

                classifier.RegisterClassifications(context);
                return(_result.Count != count);
            }
Beispiel #2
0
        public void RegisterClassifications(EmbeddedLanguageClassificationContext context)
        {
            var token = context.SyntaxToken;

            if (!_supportedKinds.Contains(token.RawKind))
            {
                return;
            }

            var virtualChars = _info.VirtualCharService.TryConvertToVirtualChars(token);

            if (virtualChars.IsDefaultOrEmpty)
            {
                return;
            }

            // Can avoid any work if we got the same number of virtual characters back as characters in the string. In
            // that case, there are clearly no escaped characters.
            if (virtualChars.Length == token.Text.Length)
            {
                return;
            }

            foreach (var vc in virtualChars)
            {
                if (vc.Span.Length > 1)
                {
                    context.AddClassification(ClassificationTypeNames.StringEscapeCharacter, vc.Span);
                }
            }
        }
            private void ClassifyToken(SyntaxToken token)
            {
                if (token.Span.IntersectsWith(_textSpan) && _owner.SyntaxTokenKinds.Contains(token.RawKind))
                {
                    var context = new EmbeddedLanguageClassificationContext(
                        _project, _semanticModel, token, _options, _owner.Info.VirtualCharService, _result, _cancellationToken);

                    var classifiers = _owner.GetServices(_semanticModel, token, _cancellationToken);
                    foreach (var classifier in classifiers)
                    {
                        // If this classifier added values then need to check the other ones.
                        if (TryClassify(classifier.Value, context))
                        {
                            return;
                        }
                    }

                    // If not other classifier classified this, then give the fallback classifier a chance to classify basic language escapes.
                    TryClassify(_owner._fallbackClassifier, context);
                }
            }