internal CompletionAnalysis(IServiceProvider serviceProvider, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { _view = view; _span = span; _serviceProvider = serviceProvider; _textBuffer = textBuffer; _options = (options == null) ? new CompletionOptions() : options.Clone(); }
internal CompletionAnalysis(IServiceProvider serviceProvider, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { _view = view; _span = span; _serviceProvider = serviceProvider; _textBuffer = textBuffer; _options = (options == null) ? new CompletionOptions() : options.Clone(); }
internal CompletionAnalysis(PythonEditorServices services, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { _session = session; _view = view; _span = span; _services = services; _textBuffer = textBuffer; _options = (options == null) ? new CompletionOptions() : options.Clone(); }
/// <param name="kind">The type of template tag we are processing</param> /// <param name="templateText">The text of the template tag which we are offering a completion in</param> /// <param name="templateStart">The offset in the buffer where the template starts</param> /// <param name="triggerPoint">The point in the buffer where the completion was triggered</param> internal CompletionSet GetCompletionSet(CompletionOptions options, DjangoAnalyzer analyzer, TemplateTokenKind kind, string templateText, int templateStart, SnapshotPoint triggerPoint, out ITrackingSpan applicableSpan) { int position = triggerPoint.Position - templateStart; IEnumerable<CompletionInfo> tags; IDjangoCompletionContext context; applicableSpan = GetWordSpan(templateText, templateStart, triggerPoint); switch (kind) { case TemplateTokenKind.Block: var block = DjangoBlock.Parse(templateText); if (block != null) { if (position <= block.ParseInfo.Start + block.ParseInfo.Command.Length) { // we are completing before the command // TODO: Return a new set of tags? Do nothing? Do this based upon ctrl-space? tags = FilterBlocks(CompletionInfo.ToCompletionInfo(analyzer._tags, StandardGlyphGroup.GlyphKeyword), triggerPoint); } else { // we are in the arguments, let the block handle the completions context = new ProjectBlockCompletionContext(analyzer, _buffer); tags = block.GetCompletions(context, position); } } else { // no tag entered yet, provide the known list of tags. tags = FilterBlocks(CompletionInfo.ToCompletionInfo(analyzer._tags, StandardGlyphGroup.GlyphKeyword), triggerPoint); } break; case TemplateTokenKind.Variable: var variable = DjangoVariable.Parse(templateText); context = new ProjectBlockCompletionContext(analyzer, _buffer); if (variable != null) { tags = variable.GetCompletions(context, position); } else { // show variable names tags = CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupVariable); } break; default: throw new InvalidOperationException(); } var completions = tags .OrderBy(tag => tag.DisplayText, StringComparer.OrdinalIgnoreCase) .Select(tag => new DynamicallyVisibleCompletion( tag.DisplayText, tag.InsertionText, StripDocumentation(tag.Documentation), _glyphService.GetGlyph(tag.Glyph, StandardGlyphItem.GlyphItemPublic), "tag")); return new FuzzyCompletionSet( "PythonDjangoTags", "Django Tags", applicableSpan, completions, options, CompletionComparer.UnderscoresLast); }
internal CompletionAnalysis(PythonEditorServices services, ICompletionSession session, ITextView view, ITextSnapshot snapshot, ITrackingPoint point, CompletionOptions options) { _session = session; _view = view; _services = services; _snapshot = snapshot; _textBuffer = snapshot?.TextBuffer; _point = point; _options = options == null ? new CompletionOptions() : options.Clone(); }
public static CompletionOptions GetOptions(this ICompletionSession session, IServiceProvider serviceProvider) { var pyService = serviceProvider.GetPythonToolsService(); var options = new CompletionOptions { ConvertTabsToSpaces = session.TextView.Options.IsConvertTabsToSpacesEnabled(), IndentSize = session.TextView.Options.GetIndentSize(), TabSize = session.TextView.Options.GetTabSize() }; options.IntersectMembers = pyService.AdvancedOptions.IntersectMembers; options.HideAdvancedMembers = pyService.LangPrefs.HideAdvancedMembers; options.FilterCompletions = pyService.AdvancedOptions.FilterCompletions; options.SearchMode = pyService.AdvancedOptions.SearchMode; return options; }
public static CompletionOptions GetOptions(this ICompletionSession session, IServiceProvider serviceProvider) { var pyService = serviceProvider.GetPythonToolsService(); var options = new CompletionOptions { ConvertTabsToSpaces = session.TextView.Options.IsConvertTabsToSpacesEnabled(), IndentSize = session.TextView.Options.GetIndentSize(), TabSize = session.TextView.Options.GetTabSize(), IntersectMembers = pyService.AdvancedOptions.IntersectMembers, HideAdvancedMembers = pyService.LangPrefs.HideAdvancedMembers, FilterCompletions = pyService.AdvancedOptions.FilterCompletions, }; return(options); }
public static CompletionAnalysis Make(IList<ClassificationSpan> tokens, IServiceProvider serviceProvider, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { Debug.Assert(tokens[0].Span.GetText() == "import" || tokens[0].Span.GetText() == "from"); if (tokens.Count >= 2) { var ns = new List<string>(); bool expectDot = false, skipToComma = false; foreach (var tok in tokens.SkipWhile(tok => !tok.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier))) { if (skipToComma) { if (tok.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Comma)) { expectDot = false; skipToComma = false; ns.Clear(); } } else if (expectDot) { if (tok.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Dot)) { expectDot = false; } else if (tok.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Comma)) { expectDot = false; ns.Clear(); } else { skipToComma = true; } } else { if (tok.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier)) { ns.Add(tok.Span.GetText()); expectDot = true; } else { skipToComma = true; } } } if (skipToComma) { return EmptyCompletionContext; } if (expectDot) { return new AsKeywordCompletionAnalysis(serviceProvider, session, view, span, textBuffer, options); } return new ImportCompletionAnalysis(ns.ToArray(), serviceProvider, session, view, span, textBuffer, options); } return new ImportCompletionAnalysis(new string[0], serviceProvider, session, view, span, textBuffer, options); }
/// <summary> /// Initializes a new instance with the specified properties. /// </summary> /// <param name="moniker">The unique, non-localized identifier for the /// completion set.</param> /// <param name="displayName">The localized name of the completion set. /// </param> /// <param name="applicableTo">The tracking span to which the /// completions apply.</param> /// <param name="completions">The list of completions.</param> /// <param name="options">The options to use for filtering and /// selecting items.</param> /// <param name="comparer">The comparer to use to order the provided /// completions.</param> /// <param name="matchInsertionText">If true, matches user input against /// the insertion text; otherwise, uses the display text.</param> public FuzzyCompletionSet( string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable <DynamicallyVisibleCompletion> completions, CompletionOptions options, IComparer <Completion> comparer, bool matchInsertionText = false ) : base(moniker, displayName, applicableTo, null, null) { _matchInsertionText = matchInsertionText; _completions = new BulkObservableCollection <Completion>(); _completions.AddRange(completions .Where(c => c != null && !string.IsNullOrWhiteSpace(c.DisplayText)) .OrderBy(c => c, comparer) ); _comparer = new FuzzyStringMatcher(options.SearchMode); _shouldFilter = options.FilterCompletions; _shouldHideAdvanced = options.HideAdvancedMembers && !_completions.All(IsAdvanced); if (!_completions.Any()) { _completions = null; } if (_completions != null && _shouldFilter | _shouldHideAdvanced) { _filteredCompletions = new FilteredObservableCollection <Completion>(_completions); foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>()) { c.Visible = !_shouldHideAdvanced || !IsAdvanced(c); } _filteredCompletions.Filter(IsVisible); } CommitByDefault = DefaultCommitByDefault; }
public static CompletionAnalysis Make(IList <ClassificationSpan> tokens, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { Debug.Assert(tokens[0].Span.GetText() == "from"); var ns = new List <string>(); bool nsComplete = false; bool seenImport = false; bool seenName = false; bool seenAs = false; bool seenAlias = false; bool includeStar = true; foreach (var token in tokens.Skip(1)) { if (token == null || token.Span.End > span.GetEndPoint(textBuffer.CurrentSnapshot).Position) { break; } if (!seenImport) { if (token.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier)) { ns.Add(token.Span.GetText()); nsComplete = true; } else if (token.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Dot)) { nsComplete = false; } seenImport = IsKeyword(token, "import"); } else if (token.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Comma)) { seenName = false; seenAs = false; seenAlias = false; includeStar = false; } else if (token.Span.GetText() == "*") { // Nothing comes after a star return(EmptyCompletionContext); } else if (IsKeyword(token, "as")) { seenAs = true; } else if (token.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier)) { if (seenAlias) { return(EmptyCompletionContext); } else if (seenAs) { seenAlias = true; } else if (seenName) { return(EmptyCompletionContext); } else { seenName = true; } } else { includeStar = false; } } if (!seenImport) { if (nsComplete) { return(new ImportKeywordCompletionAnalysis(span, textBuffer, options)); } else { return(ImportCompletionAnalysis.Make(tokens, span, textBuffer, options)); } } if (!nsComplete || seenAlias || seenAs) { return(EmptyCompletionContext); } if (seenName) { return(new AsKeywordCompletionAnalysis(span, textBuffer, options)); } return(new FromImportCompletionAnalysis(ns.ToArray(), includeStar, span, textBuffer, options)); }
/// <summary> /// Initializes a new instance with the specified properties. /// </summary> /// <param name="moniker">The unique, non-localized identifier for the /// completion set.</param> /// <param name="displayName">The localized name of the completion set. /// </param> /// <param name="applicableTo">The tracking span to which the /// completions apply.</param> /// <param name="completions">The list of completions.</param> /// <param name="options">The options to use for filtering and /// selecting items.</param> /// <param name="comparer">The comparer to use to order the provided /// completions.</param> /// <param name="matchInsertionText">If true, matches user input against /// the insertion text; otherwise, uses the display text.</param> public FuzzyCompletionSet( string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable<DynamicallyVisibleCompletion> completions, CompletionOptions options, IComparer<Completion> comparer, bool matchInsertionText = false ) : base(moniker, displayName, applicableTo, null, null) { _matchInsertionText = matchInsertionText; _completions = new BulkObservableCollection<Completion>(); _completions.AddRange(completions .Where(c => c != null && !string.IsNullOrWhiteSpace(c.DisplayText)) .OrderBy(c => c, comparer) ); _comparer = new FuzzyStringMatcher(options.SearchMode); _shouldFilter = options.FilterCompletions; _shouldHideAdvanced = options.HideAdvancedMembers && !_completions.All(IsAdvanced); if (!_completions.Any()) { _completions = null; } if (_completions != null && _shouldFilter | _shouldHideAdvanced) { _filteredCompletions = new FilteredObservableCollection<Completion>(_completions); foreach (var c in _completions.Cast<DynamicallyVisibleCompletion>()) { c.Visible = !_shouldHideAdvanced || !IsAdvanced(c); } _filteredCompletions.Filter(IsVisible); } CommitByDefault = DefaultCommitByDefault; }
private ImportCompletionAnalysis(string[] ns, IServiceProvider serviceProvider, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(serviceProvider, session, view, span, textBuffer, options) { _namespace = ns; }
internal NormalCompletionAnalysis(PythonEditorServices services, ICompletionSession session, ITextView view, ITextSnapshot snapshot, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(services, session, view, span, textBuffer, options) { _snapshot = snapshot; }
internal ExceptionCompletionAnalysis(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(span, textBuffer, options) { }
internal DecoratorCompletionAnalysis(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(span, textBuffer, options) { }
private ImportCompletionAnalysis(string[] ns, IServiceProvider serviceProvider, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(serviceProvider, session, view, span, textBuffer, options) { _namespace = ns; }
internal OverrideCompletionAnalysis(IServiceProvider serviceProvider, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(serviceProvider, session, view, span, textBuffer, options) { }
internal NormalCompletionAnalysis(VsProjectAnalyzer analyzer, ICompletionSession session, ITextView view, ITextSnapshot snapshot, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options, IServiceProvider serviceProvider) : base(analyzer._serviceProvider, session, view, span, textBuffer, options) { _snapshot = snapshot; _analyzer = analyzer; _serviceProvider = serviceProvider; }
internal CompletionAnalysis(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { _span = span; _textBuffer = textBuffer; _options = (options == null) ? new CompletionOptions() : options.Clone(); }
private ImportCompletionAnalysis(string[] ns, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(span, textBuffer, options) { _namespace = ns; }
/// <summary> /// Gets a CompletionAnalysis providing a list of possible members the user can dot through. /// </summary> public static CompletionAnalysis GetCompletions(this ITextSnapshot snapshot, IServiceProvider serviceProvider, ITrackingSpan span, ITrackingPoint point, CompletionOptions options) { return VsProjectAnalyzer.GetCompletions(serviceProvider, snapshot, span, point, options); }
public static CompletionAnalysis GetCompletions(this ITextSnapshot snapshot, ITrackingSpan span, ITrackingPoint point, CompletionOptions options) { #pragma warning disable 0618 return VsProjectAnalyzer.GetCompletions(PythonToolsPackage.Instance, snapshot, span, point, options); #pragma warning restore 0618 }
public ImportKeywordCompletionAnalysis(IServiceProvider serviceProvider, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer buffer, CompletionOptions options) : base(serviceProvider, session, view, span, buffer, options) { }
/// <summary> /// Gets a CompletionAnalysis providing a list of possible members the user can dot through. /// </summary> public static CompletionAnalysis GetCompletions(this ITextSnapshot snapshot, IServiceProvider serviceProvider, ITrackingSpan span, ITrackingPoint point, CompletionOptions options) { return(VsProjectAnalyzer.GetCompletions(serviceProvider, snapshot, span, point, options)); }
internal ExceptionCompletionAnalysis(IServiceProvider serviceProvider, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(serviceProvider, view, span, textBuffer, options) { }
internal StringLiteralCompletionList(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(span, textBuffer, options) { }
private ImportCompletionAnalysis(string[] ns, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(span, textBuffer, options) { _namespace = ns; }
public ImportKeywordCompletionAnalysis(ITrackingSpan span, ITextBuffer buffer, CompletionOptions options) : base(span, buffer, options) { }
internal ExceptionCompletionAnalysis(IServiceProvider serviceProvider, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(serviceProvider, session, view, span, textBuffer, options) { }
private FromImportCompletionAnalysis(string[] ns, bool includeStar, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(span, textBuffer, options) { _namespace = ns; _includeStar = includeStar; }
internal StringLiteralCompletionList(PythonEditorServices services, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(services, session, view, span, textBuffer, options) { }
internal StringLiteralCompletionList(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(span, textBuffer, options) { }
public AsKeywordCompletionAnalysis(IServiceProvider serviceProvider, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer buffer, CompletionOptions options) : base(serviceProvider, session, view, span, buffer, options) { }
public ImportKeywordCompletionAnalysis(ITrackingSpan span, ITextBuffer buffer, CompletionOptions options) : base(span, buffer, options) { }
public static CompletionAnalysis Make(IList<ClassificationSpan> tokens, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { Debug.Assert(tokens[0].Span.GetText() == "from"); var ns = new List<string>(); bool nsComplete = false; bool seenImport = false; bool seenName = false; bool seenAs = false; bool seenAlias = false; bool includeStar = true; foreach (var token in tokens.Skip(1)) { if (token == null || token.Span.End > span.GetEndPoint(textBuffer.CurrentSnapshot).Position) { break; } if (!seenImport) { if (token.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier)) { ns.Add(token.Span.GetText()); nsComplete = true; } else if (token.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Dot)) { nsComplete = false; } seenImport = IsKeyword(token, "import"); } else if (token.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Comma)) { seenName = false; seenAs = false; seenAlias = false; includeStar = false; } else if (token.Span.GetText() == "*") { // Nothing comes after a star return EmptyCompletionContext; } else if (IsKeyword(token, "as")) { seenAs = true; } else if (token.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier)) { if (seenAlias) { return EmptyCompletionContext; } else if (seenAs) { seenAlias = true; } else if (seenName) { return EmptyCompletionContext; } else { seenName = true; } } else { includeStar = false; } } if (!seenImport) { if (nsComplete) { return new ImportKeywordCompletionAnalysis(span, textBuffer, options); } else { return ImportCompletionAnalysis.Make(tokens, span, textBuffer, options); } } if (!nsComplete || seenAlias || seenAs) { return EmptyCompletionContext; } if (seenName) { return new AsKeywordCompletionAnalysis(span, textBuffer, options); } return new FromImportCompletionAnalysis(ns.ToArray(), includeStar, span, textBuffer, options); }
public static CompletionAnalysis Make(PythonEditorServices services, IList <ClassificationSpan> tokens, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { Debug.Assert(tokens[0].Span.GetText() == "import" || tokens[0].Span.GetText() == "from"); if (tokens.Count >= 2) { var ns = new List <string>(); bool expectDot = false, skipToComma = false; foreach (var tok in tokens.SkipWhile(tok => !tok.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier))) { if (skipToComma) { if (tok.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Comma)) { expectDot = false; skipToComma = false; ns.Clear(); } } else if (expectDot) { if (tok.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Dot)) { expectDot = false; } else if (tok.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Comma)) { expectDot = false; ns.Clear(); } else { skipToComma = true; } } else { if (tok.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier)) { ns.Add(tok.Span.GetText()); expectDot = true; } else { skipToComma = true; } } } if (skipToComma) { return(EmptyCompletionContext); } if (expectDot) { return(new AsKeywordCompletionAnalysis(services, session, view, span, textBuffer, options)); } return(new ImportCompletionAnalysis(services, ns.ToArray(), session, view, span, textBuffer, options)); } return(new ImportCompletionAnalysis(services, new string[0], session, view, span, textBuffer, options)); }
internal OverrideCompletionAnalysis(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(span, textBuffer, options) { }
internal CompletionAnalysis(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { _span = span; _textBuffer = textBuffer; _options = (options == null) ? new CompletionOptions() : options.Clone(); }
internal OverrideCompletionAnalysis(IServiceProvider serviceProvider, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(serviceProvider, view, span, textBuffer, options) { }
internal StringLiteralCompletionList(IServiceProvider serviceProvider, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(serviceProvider, session, view, span, textBuffer, options) { }
private FromImportCompletionAnalysis(string[] ns, bool includeStar, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(span, textBuffer, options) { _namespace = ns; _includeStar = includeStar; }
private static CompletionAnalysis GetNormalCompletionContext(IServiceProvider serviceProvider, ITextSnapshot snapshot, ITrackingSpan applicableSpan, ITrackingPoint point, CompletionOptions options) { var span = applicableSpan.GetSpan(snapshot); if (IsSpaceCompletion(snapshot, point) && !IntellisenseController.ForceCompletions) { return CompletionAnalysis.EmptyCompletionContext; } var parser = new ReverseExpressionParser(snapshot, snapshot.TextBuffer, applicableSpan); if (parser.IsInGrouping()) { options = options.Clone(); options.IncludeStatementKeywords = false; } return new NormalCompletionAnalysis( snapshot.TextBuffer.GetAnalyzer(serviceProvider), snapshot, applicableSpan, snapshot.TextBuffer, options, serviceProvider ); }
internal DecoratorCompletionAnalysis(PythonEditorServices services, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(services, session, view, span, textBuffer, options) { }
public static CompletionAnalysis GetCompletions(this ITextSnapshot snapshot, ITrackingSpan span, ITrackingPoint point, CompletionOptions options) { #pragma warning disable 0618 return(VsProjectAnalyzer.GetCompletions(PythonToolsPackage.Instance, snapshot, span, point, options)); #pragma warning restore 0618 }
internal NormalCompletionAnalysis(VsProjectAnalyzer analyzer, ITextSnapshot snapshot, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options, IServiceProvider serviceProvider) : base(span, textBuffer, options) { _snapshot = snapshot; _analyzer = analyzer; _serviceProvider = serviceProvider; }
public ImportKeywordCompletionAnalysis(PythonEditorServices services, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer buffer, CompletionOptions options) : base(services, session, view, span, buffer, options) { }
private static CompletionAnalysis TrySpecialCompletions(IServiceProvider serviceProvider, ITextSnapshot snapshot, ITrackingSpan span, ITrackingPoint point, CompletionOptions options) { var snapSpan = span.GetSpan(snapshot); var buffer = snapshot.TextBuffer; var classifier = buffer.GetPythonClassifier(); if (classifier == null) { return null; } var parser = new ReverseExpressionParser(snapshot, buffer, span); var statementRange = parser.GetStatementRange(); if (!statementRange.HasValue) { statementRange = snapSpan.Start.GetContainingLine().Extent; } if (snapSpan.Start < statementRange.Value.Start) { return null; } var tokens = classifier.GetClassificationSpans(new SnapshotSpan(statementRange.Value.Start, snapSpan.Start)); if (tokens.Count > 0) { // Check for context-sensitive intellisense var lastClass = tokens[tokens.Count - 1]; if (lastClass.ClassificationType == classifier.Provider.Comment) { // No completions in comments return CompletionAnalysis.EmptyCompletionContext; } else if (lastClass.ClassificationType == classifier.Provider.StringLiteral) { // String completion if (lastClass.Span.Start.GetContainingLine().LineNumber == lastClass.Span.End.GetContainingLine().LineNumber) { return new StringLiteralCompletionList(span, buffer, options); } else { // multi-line string, no string completions. return CompletionAnalysis.EmptyCompletionContext; } } else if (lastClass.ClassificationType == classifier.Provider.Operator && lastClass.Span.GetText() == "@") { if (tokens.Count == 1) { return new DecoratorCompletionAnalysis(span, buffer, options); } // TODO: Handle completions automatically popping up // after '@' when it is used as a binary operator. } else if (CompletionAnalysis.IsKeyword(lastClass, "def")) { return new OverrideCompletionAnalysis(span, buffer, options); } // Import completions var first = tokens[0]; if (CompletionAnalysis.IsKeyword(first, "import")) { return ImportCompletionAnalysis.Make(tokens, span, buffer, options); } else if (CompletionAnalysis.IsKeyword(first, "from")) { return FromImportCompletionAnalysis.Make(tokens, span, buffer, options); } else if (CompletionAnalysis.IsKeyword(first, "raise") || CompletionAnalysis.IsKeyword(first, "except")) { if (tokens.Count == 1 || lastClass.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Comma) || (lastClass.IsOpenGrouping() && tokens.Count < 3)) { return new ExceptionCompletionAnalysis(span, buffer, options); } } return null; } else if ((tokens = classifier.GetClassificationSpans(snapSpan.Start.GetContainingLine().ExtentIncludingLineBreak)).Count > 0 && tokens[0].ClassificationType == classifier.Provider.StringLiteral) { // multi-line string, no string completions. return CompletionAnalysis.EmptyCompletionContext; } else if (snapshot.IsReplBufferWithCommand()) { return CompletionAnalysis.EmptyCompletionContext; } return null; }
private FromImportCompletionAnalysis(PythonEditorServices services, string[] ns, bool includeStar, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(services, session, view, span, textBuffer, options) { _namespace = ns; _includeStar = includeStar; }
/// <summary> /// Gets a CompletionList providing a list of possible members the user can dot through. /// </summary> internal static CompletionAnalysis GetCompletions(IServiceProvider serviceProvider, ITextSnapshot snapshot, ITrackingSpan span, ITrackingPoint point, CompletionOptions options) { return TrySpecialCompletions(serviceProvider, snapshot, span, point, options) ?? GetNormalCompletionContext(serviceProvider, snapshot, span, point, options); }
internal StringLiteralCompletionList(IServiceProvider serviceProvider, ICompletionSession session, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) : base(serviceProvider, session, view, span, textBuffer, options) { }