private bool ShouldTriggerIdentifierCompletionSession(out bool commitByDefault) { commitByDefault = true; if (_bufferParser == null || !_provider.PythonService.AdvancedOptions.AutoListIdentifiers || !_provider.PythonService.AdvancedOptions.AutoListMembers) { return(false); } SnapshotPoint?caretPoint = _textView.BufferGraph.MapDownToFirstMatch( _textView.Caret.Position.BufferPosition, PointTrackingMode.Positive, EditorExtensions.IsPythonContent, PositionAffinity.Predecessor ); if (!caretPoint.HasValue) { return(false); } var snapshot = caretPoint.Value.Snapshot; var statement = new ReverseExpressionParser( snapshot, snapshot.TextBuffer, snapshot.CreateTrackingSpan(caretPoint.Value.Position, 0, SpanTrackingMode.EdgeNegative) ).GetStatementRange(); if (!statement.HasValue || caretPoint.Value <= statement.Value.Start) { return(false); } var text = new SnapshotSpan(statement.Value.Start, caretPoint.Value).GetText(); if (string.IsNullOrEmpty(text)) { return(false); } var languageVersion = _bufferParser._parser.InterpreterFactory.Configuration.Version.ToLanguageVersion(); PythonAst ast; using (var parser = Parser.CreateParser(new StringReader(text), languageVersion, new ParserOptions())) { ast = parser.ParseSingleStatement(); } var walker = new ExpressionCompletionWalker(caretPoint.Value.Position - statement.Value.Start.Position); ast.Walk(walker); commitByDefault = walker.CommitByDefault; return(walker.CanComplete); }
private bool ShouldTriggerIdentifierCompletionSession(out bool commitByDefault) { commitByDefault = true; if (_bufferParser == null || !_provider.PythonService.AdvancedOptions.AutoListIdentifiers || !_provider.PythonService.AdvancedOptions.AutoListMembers) { return false; } SnapshotPoint? caretPoint = _textView.BufferGraph.MapDownToFirstMatch( _textView.Caret.Position.BufferPosition, PointTrackingMode.Positive, EditorExtensions.IsPythonContent, PositionAffinity.Predecessor ); if (!caretPoint.HasValue) { return false; } var snapshot = caretPoint.Value.Snapshot; var statement = new ReverseExpressionParser( snapshot, snapshot.TextBuffer, snapshot.CreateTrackingSpan(caretPoint.Value.Position, 0, SpanTrackingMode.EdgeNegative) ).GetStatementRange(); if (!statement.HasValue || caretPoint.Value <= statement.Value.Start) { return false; } var text = new SnapshotSpan(statement.Value.Start, caretPoint.Value).GetText(); if (string.IsNullOrEmpty(text)) { return false; } var languageVersion = _bufferParser._parser.InterpreterFactory.Configuration.Version.ToLanguageVersion(); PythonAst ast; using (var parser = Parser.CreateParser(new StringReader(text), languageVersion, new ParserOptions())) { ast = parser.ParseSingleStatement(); } var walker = new ExpressionCompletionWalker(caretPoint.Value.Position - statement.Value.Start.Position); ast.Walk(walker); commitByDefault = walker.CommitByDefault; return walker.CanComplete; }
private bool ShouldTriggerIdentifierCompletionSession(out bool commitByDefault) { commitByDefault = true; if (!_provider.PythonService.AdvancedOptions.AutoListIdentifiers || !_provider.PythonService.AdvancedOptions.AutoListMembers) { return false; } var caretPoint = _textView.GetPythonCaret(); if (!caretPoint.HasValue) { return false; } var snapshot = caretPoint.Value.Snapshot; var statement = new ReverseExpressionParser( snapshot, snapshot.TextBuffer, snapshot.CreateTrackingSpan(caretPoint.Value.Position, 0, SpanTrackingMode.EdgeNegative) ).GetStatementRange(); if (!statement.HasValue || caretPoint.Value <= statement.Value.Start) { return false; } var text = new SnapshotSpan(statement.Value.Start, caretPoint.Value).GetText(); if (string.IsNullOrEmpty(text)) { return false; } var analysis = _textView.GetAnalysisEntry(snapshot.TextBuffer, _serviceProvider); if (analysis == null) { return false; } var languageVersion = analysis.Analyzer.InterpreterFactory.Configuration.Version.ToLanguageVersion(); PythonAst ast; using (var parser = Parser.CreateParser(new StringReader(text), languageVersion, new ParserOptions { Verbatim = true })) { ast = parser.ParseSingleStatement(); } var walker = new ExpressionCompletionWalker(caretPoint.Value.Position - statement.Value.Start.Position); ast.Walk(walker); commitByDefault = walker.CommitByDefault; return walker.CanComplete; }