Ejemplo n.º 1
0
        public override void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets) {
            var doc = HtmlEditorDocument.FromTextBuffer(_buffer);
            if (doc == null) {
                return;
            }
            doc.HtmlEditorTree.EnsureTreeReady();

            var primarySnapshot = doc.PrimaryView.TextSnapshot;
            var nullableTriggerPoint = session.GetTriggerPoint(primarySnapshot);
            if (!nullableTriggerPoint.HasValue) {
                return;
            }
            var triggerPoint = nullableTriggerPoint.Value;

            var artifacts = doc.HtmlEditorTree.ArtifactCollection;
            var index = artifacts.GetItemContaining(triggerPoint.Position);
            if (index < 0) {
                return;
            }

            var artifact = artifacts[index] as TemplateArtifact;
            if (artifact == null) {
                return;
            }

            var artifactText = doc.HtmlEditorTree.ParseTree.Text.GetText(artifact.InnerRange);
            artifact.Parse(artifactText);

            ITrackingSpan applicableSpan;
            var completionSet = GetCompletionSet(session.GetOptions(_analyzer._serviceProvider), _analyzer, artifact.TokenKind, artifactText, artifact.InnerRange.Start, triggerPoint, out applicableSpan);
            completionSets.Add(completionSet);
        }
Ejemplo n.º 2
0
        internal CompletionAnalysis GetCompletions(ICompletionSession session, ITextView view, ITextSnapshot snapshot, ITrackingPoint point)
        {
            if (IsSpaceCompletion(snapshot, point) && session.IsCompleteWordMode())
            {
                // Cannot complete a word immediately after a space
                session.ClearCompleteWordMode();
            }

            var bi    = EditorServices.GetBufferInfo(snapshot.TextBuffer);
            var entry = bi?.AnalysisEntry;

            if (entry == null)
            {
                return(CompletionAnalysis.EmptyCompletionContext);
            }

            var options = session.GetOptions(Site);

            if (ReverseExpressionParser.IsInGrouping(snapshot, bi.GetTokensInReverseFromPoint(point.GetPoint(snapshot))))
            {
                options = options.Clone();
                options.IncludeStatementKeywords = false;
            }

            return(new CompletionAnalysis(
                       EditorServices,
                       session,
                       view,
                       snapshot,
                       point,
                       options
                       ));
        }
Ejemplo n.º 3
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            _completionSession = session;
            var textBuffer = _textBuffer;

            if (_provider._PublicFunctionProvider != null)
            {
                _provider._PublicFunctionProvider.SetFilename(textBuffer.GetFilePath());
            }
            if (_provider._DatabaseInfoProvider != null)
            {
                _provider._DatabaseInfoProvider.SetFilename(textBuffer.GetFilePath());
            }

            var span         = session.GetApplicableSpan(textBuffer);
            var triggerPoint = session.GetTriggerPoint(textBuffer);
            var options      = session.GetOptions();
            var provider     = textBuffer.CurrentSnapshot.GetCompletions(span, triggerPoint, options, _provider._PublicFunctionProvider, _provider._DatabaseInfoProvider, _provider._ProgramFileProvider);

            provider.GlyphService = _provider._glyphService;
            var completions = provider.GetCompletions(_provider._glyphService);

            if (completions == null || completions.Completions.Count == 0)
            {
                return;
            }
            completionSets.Add(completions);
        }
Ejemplo n.º 4
0
        public override void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets) {
            var nullableTriggerPoint = session.GetTriggerPoint(_buffer.CurrentSnapshot);
            if (!nullableTriggerPoint.HasValue) {
                return;
            }

            var triggerPoint = nullableTriggerPoint.Value;
            TemplateProjectionBuffer projBuffer;
            if (!_buffer.Properties.TryGetProperty<TemplateProjectionBuffer>(typeof(TemplateProjectionBuffer), out projBuffer)) {
                return;
            }

            int templateStart;
            TemplateTokenKind kind;
            var templateText = projBuffer.GetTemplateText(triggerPoint, out kind, out templateStart);
            if (templateText == null) {
                return;
            }

            if (kind == TemplateTokenKind.Block || kind == TemplateTokenKind.Variable) {
                ITrackingSpan applicableSpan;
                var completionSet = GetCompletionSet(
                    session.GetOptions(),
                    _analyzer,
                    kind,
                    templateText,
                    templateStart,
                    triggerPoint,
                    out applicableSpan);
                completionSets.Add(completionSet);
            }
        }
Ejemplo n.º 5
0
        public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets) {
            var textBuffer = _textBuffer;
            var span = session.GetApplicableSpan(textBuffer);
            var triggerPoint = session.GetTriggerPoint(textBuffer);
            var options = session.GetOptions(_provider._serviceProvider);
            var provider = textBuffer.CurrentSnapshot.GetCompletions(_provider._serviceProvider, span, triggerPoint, options);

            var completions = provider.GetCompletions(_provider._glyphService);
           
            if (completions != null && completions.Completions.Count > 0) {
                completionSets.Add(completions);
            }
        }
Ejemplo n.º 6
0
        public override void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            var doc = TemplateClassifier.HtmlEditorDocumentFromTextBuffer(_buffer);

            if (doc == null)
            {
                return;
            }
            var tree = doc.HtmlEditorTree;

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

            var primarySnapshot      = tree.TextSnapshot;
            var nullableTriggerPoint = session.GetTriggerPoint(primarySnapshot);

            if (!nullableTriggerPoint.HasValue)
            {
                return;
            }
            var triggerPoint = nullableTriggerPoint.Value;

            var artifacts = doc.HtmlEditorTree.ArtifactCollection;
            var index     = artifacts.GetItemContaining(triggerPoint.Position);

            if (index < 0)
            {
                return;
            }

            var artifact = artifacts[index] as TemplateArtifact;

            if (artifact == null)
            {
                return;
            }

            var artifactText = doc.HtmlEditorTree.ParseTree.Text.GetText(artifact.InnerRange);

            artifact.Parse(artifactText);

            ITrackingSpan applicableSpan;
            var           completionSet = GetCompletionSet(session.GetOptions(_serviceProvider), _analyzer, artifact.TokenKind, artifactText, artifact.InnerRange.Start, triggerPoint, out applicableSpan);

            completionSets.Add(completionSet);
        }
Ejemplo n.º 7
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            var textBuffer   = _textBuffer;
            var span         = session.GetApplicableSpan(textBuffer);
            var triggerPoint = session.GetTriggerPoint(textBuffer);
            var options      = session.GetOptions(_provider._serviceProvider);
            var provider     = textBuffer.CurrentSnapshot.GetCompletions(_provider._serviceProvider, span, triggerPoint, options);

            var completions = provider.GetCompletions(_provider._glyphService);

            if (completions != null && completions.Completions.Count > 0)
            {
                completionSets.Add(completions);
            }
        }
Ejemplo n.º 8
0
        public override void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            var nullableTriggerPoint = session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (!nullableTriggerPoint.HasValue)
            {
                return;
            }

            var triggerPoint = nullableTriggerPoint.Value;
            TemplateProjectionBuffer projBuffer;

            if (!_buffer.Properties.TryGetProperty <TemplateProjectionBuffer>(typeof(TemplateProjectionBuffer), out projBuffer))
            {
                return;
            }

            int templateStart;
            TemplateTokenKind kind;
            var templateText = projBuffer.GetTemplateText(triggerPoint, out kind, out templateStart);

            if (templateText == null)
            {
                return;
            }

            if (kind == TemplateTokenKind.Block || kind == TemplateTokenKind.Variable)
            {
                ITrackingSpan applicableSpan;
                var           completionSet = GetCompletionSet(
                    session.GetOptions(),
                    _analyzer,
                    kind,
                    templateText,
                    templateStart,
                    triggerPoint,
                    out applicableSpan);
                completionSets.Add(completionSet);
            }
        }
Ejemplo n.º 9
0
        public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
        {
            var textBuffer = _textBuffer;
            var span = session.GetApplicableSpan(textBuffer);
            var triggerPoint = session.GetTriggerPoint(textBuffer);
            var options = session.GetOptions();
            var provider = textBuffer.CurrentSnapshot.GetCompletions(span, triggerPoint, options);

            var completions = provider.GetCompletions(_provider._glyphService);

            if (completions == null || completions.Completions.Count == 0) {
                if (JToolsPackage.Instance != null &&
                    !session.TextView.GetAnalyzer().InterpreterFactory.IsAnalysisCurrent()) {
                    // no completions, inform the user via the status bar that the analysis is not yet complete.
                    var statusBar = (IVsStatusbar)CommonPackage.GetGlobalService(typeof(SVsStatusbar));
                    statusBar.SetText(Resources.WarningAnalysisNotCurrent);
                }
                return;
            }

            completionSets.Add(completions);
        }
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            TemplateProjectionBuffer projBuffer;

            if (_textBuffer.Properties.TryGetProperty <TemplateProjectionBuffer>(typeof(TemplateProjectionBuffer), out projBuffer))
            {
                var completions = new List <DynamicallyVisibleCompletion>();
                foreach (var tag in _htmlTags)
                {
                    completions.Add(new DynamicallyVisibleCompletion(
                                        tag,
                                        tag,
                                        "",
                                        _completionSourceProvider._glyphService.GetGlyph(StandardGlyphGroup.GlyphXmlItem, StandardGlyphItem.GlyphItemPublic),
                                        "")
                                    );
                }
                foreach (var tag in _htmlTags)
                {
                    completions.Add(new DynamicallyVisibleCompletion(
                                        "/" + tag,
                                        "/" + tag,
                                        "",
                                        _completionSourceProvider._glyphService.GetGlyph(StandardGlyphGroup.GlyphXmlItem, StandardGlyphItem.GlyphItemPublic),
                                        "")
                                    );
                }

                //
                var triggerPoint = session.GetTriggerPoint(_textBuffer);
                var point        = triggerPoint.GetPoint(_textBuffer.CurrentSnapshot);

                var match = projBuffer.BufferGraph.MapUpToFirstMatch(
                    point,
                    PointTrackingMode.Positive,
                    x => x.TextBuffer != _textBuffer,
                    PositionAffinity.Predecessor
                    );

                if (match == null ||
                    !match.Value.Snapshot.TextBuffer.ContentType.IsOfType(TemplateContentType.ContentTypeName))
                {
                    var line     = point.GetContainingLine();
                    var text     = line.GetText();
                    int position = point.Position;
                    for (int i = position - line.Start.Position - 1; i >= 0 && i < text.Length; --i, --position)
                    {
                        char c = text[i];
                        if (!char.IsLetterOrDigit(c) && c != '!')
                        {
                            break;
                        }
                    }

                    var span = _textBuffer.CurrentSnapshot.CreateTrackingSpan(position, point.Position - position, SpanTrackingMode.EdgeInclusive);

                    completionSets.Add(new FuzzyCompletionSet("PythonDjangoTemplateHtml", "HTML", span, completions, session.GetOptions(), CompletionComparer.UnderscoresLast));
                }
            }
        }
Ejemplo n.º 11
0
        public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets) {
            TemplateProjectionBuffer projBuffer;
            if (_textBuffer.Properties.TryGetProperty<TemplateProjectionBuffer>(typeof(TemplateProjectionBuffer), out projBuffer)) {
                var completions = new List<DynamicallyVisibleCompletion>();
                foreach (var tag in _htmlTags) {
                    completions.Add(new DynamicallyVisibleCompletion(
                        tag,
                        tag,
                        "",
                        _completionSourceProvider._glyphService.GetGlyph(StandardGlyphGroup.GlyphXmlItem, StandardGlyphItem.GlyphItemPublic),
                        "")
                    );
                }
                foreach (var tag in _htmlTags) {
                    completions.Add(new DynamicallyVisibleCompletion(
                        "/" + tag,
                        "/" + tag,
                        "",
                        _completionSourceProvider._glyphService.GetGlyph(StandardGlyphGroup.GlyphXmlItem, StandardGlyphItem.GlyphItemPublic),
                        "")
                    );
                }

                //
                var triggerPoint = session.GetTriggerPoint(_textBuffer);
                var point = triggerPoint.GetPoint(_textBuffer.CurrentSnapshot);

                var match = projBuffer.BufferGraph.MapUpToFirstMatch(
                    point,
                    PointTrackingMode.Positive,
                    x => x.TextBuffer != _textBuffer,
                    PositionAffinity.Predecessor
                );
                
                if (match == null ||
                    !match.Value.Snapshot.TextBuffer.ContentType.IsOfType(TemplateContentType.ContentTypeName)) {

                    var line = point.GetContainingLine();
                    var text = line.GetText();
                    int position = point.Position;
                    for (int i = position - line.Start.Position - 1; i >= 0 && i < text.Length; --i, --position) {
                        char c = text[i];
                        if (!char.IsLetterOrDigit(c) && c != '!') {
                            break;
                        }
                    }

                    var span = _textBuffer.CurrentSnapshot.CreateTrackingSpan(position, point.Position - position, SpanTrackingMode.EdgeInclusive);

                    completionSets.Add(new FuzzyCompletionSet("PythonDjangoTemplateHtml", "HTML", span, completions, session.GetOptions(), CompletionComparer.UnderscoresLast));
                }
            }
        }