public bool TryGetAnalyzer(ITextView textView, out ProjectAnalyzer analyzer, out string filename) { if (textView == null) { throw new ArgumentNullException(nameof(textView)); } // The analyzer usually comes from the main buffer. if (TryGetAnalyzer(textView.TextBuffer, out analyzer, out filename)) { return(true); } if (textView != null) { // If we have a difference viewer we'll match the LHS w/ the RHS var viewer = _diffService?.TryGetViewerForTextView(textView); if (viewer != null) { if (TryGetAnalyzer(viewer.DifferenceBuffer.RightBuffer, out analyzer, out filename)) { return(true); } if (TryGetAnalyzer(viewer.DifferenceBuffer.LeftBuffer, out analyzer, out filename)) { return(true); } } } analyzer = null; filename = null; return(false); }
/// <summary> /// Tries to get the analyzer and filename of the specified text buffer. /// </summary> /// <returns>True if an analyzer and filename are found.</returns> /// <exception cref="ArgumentNullException"><paramref name="textBuffer"/> is null.</exception> public bool TryGetAnalyzer(ITextBuffer textBuffer, out ProjectAnalyzer analyzer, out string filename) { if (textBuffer == null) { throw new ArgumentNullException(nameof(textBuffer)); } // If we have set an analyzer explicitly, return that analyzer = null; if (textBuffer.Properties.TryGetProperty(typeof(VsProjectAnalyzer), out analyzer)) { filename = textBuffer.GetFilePath(); return(analyzer != null); } // If we have a REPL evaluator we'll use its analyzer IPythonInteractiveIntellisense evaluator; if ((evaluator = textBuffer.GetInteractiveWindow()?.Evaluator as IPythonInteractiveIntellisense) != null) { analyzer = evaluator.Analyzer; filename = evaluator.AnalysisFilename; return(analyzer != null); } // If we find an associated project, use its analyzer // This should only happen while racing with text view creation var path = textBuffer.GetFilePath(); if (path != null) { var rdt = (IVsRunningDocumentTable4)_site.GetService(typeof(SVsRunningDocumentTable)); try { var cookie = rdt?.GetDocumentCookie(path) ?? VSConstants.VSCOOKIE_NIL; if (cookie != VSConstants.VSCOOKIE_NIL) { IVsHierarchy hierarchy; uint itemid; rdt.GetDocumentHierarchyItem(cookie, out hierarchy, out itemid); if (hierarchy != null) { var pyProject = hierarchy.GetProject()?.GetPythonProject(); if (pyProject != null) { analyzer = pyProject.GetAnalyzer(); Debug.WriteLineIf(analyzer != null, "Found an analyzer that wasn't in the property bag"); filename = path; return(true); } } } } catch (ArgumentException) { } } analyzer = null; filename = null; return(false); }
public void SwitchAnalyzers(ProjectAnalyzer oldAnalyzer) { lock (_openFiles) { foreach (var bufferParser in oldAnalyzer._openFiles.Keys) { ReAnalyzeTextBuffers(bufferParser); } } }
public bool TryGetAnalyzer(ITextBuffer textBuffer, out ProjectAnalyzer analyzer, out string filename) { if (textBuffer == null) { throw new ArgumentNullException(nameof(textBuffer)); } // If we have an analyzer in Properties, we will use that // NOTE: This should only be used for tests. if (textBuffer.Properties.TryGetProperty(VsProjectAnalyzer._testAnalyzer, out analyzer)) { if (!textBuffer.Properties.TryGetProperty(VsProjectAnalyzer._testFilename, out filename)) { filename = textBuffer.GetFilePath(); } return(true); } // If we have a REPL evaluator we'll use its analyzer IPythonInteractiveIntellisense evaluator; if ((evaluator = textBuffer.GetInteractiveWindow()?.Evaluator as IPythonInteractiveIntellisense) != null) { analyzer = evaluator.Analyzer; filename = evaluator.AnalysisFilename; return(analyzer != null); } AnalysisEntry entry; if (TryGetAnalysisEntry(textBuffer, out entry)) { analyzer = entry.Analyzer; filename = entry.Path; return(true); } // If we find an associated project, use its analyzer // This should only happen while racing with text view creation var path = textBuffer.GetFilePath(); if (path != null) { analyzer = _services.Site.GetProjectFromFile(path)?.GetAnalyzer(); if (analyzer != null) { Debug.WriteLine("Found an analyzer on " + path + " that wasn't in the property bag"); filename = path; return(true); } } analyzer = null; filename = null; return(false); }
public bool TryGetAnalyzer(ITextBuffer textBuffer, out ProjectAnalyzer analyzer, out string filename) { // If we have an analyzer in Properties, we will use that // NOTE: This should only be used for tests. if (textBuffer.Properties.TryGetProperty(VsProjectAnalyzer._testAnalyzer, out analyzer)) { if (!textBuffer.Properties.TryGetProperty(VsProjectAnalyzer._testFilename, out filename)) { filename = textBuffer.GetFilePath(); } return(true); } // Fastest check is for an existing analysis entry var bufferInfo = PythonTextBufferInfo.TryGetForBuffer(textBuffer); if (bufferInfo?.AnalysisEntry != null) { analyzer = bufferInfo.AnalysisEntry.Analyzer; filename = bufferInfo.Filename; return(true); } // If we have a REPL evaluator we'll use its analyzer IPythonInteractiveIntellisense evaluator; if ((evaluator = textBuffer.GetInteractiveWindow()?.Evaluator as IPythonInteractiveIntellisense) != null) { analyzer = evaluator.Analyzer; filename = evaluator.AnalysisFilename; return(true); } // If we find an associated project, use its analyzer // This should only happen while racing with text view creation var path = PythonTextBufferInfo.TryGetForBuffer(textBuffer)?.Filename ?? textBuffer.GetFilePath(); if (path != null) { analyzer = _services.Site.GetProjectFromFile(path)?.GetAnalyzer(); if (analyzer != null) { // Don't check whether the analyzer knows about us yet, // since this request is probably finding out which analyzer // to add the file to. filename = path; return(true); } } analyzer = null; filename = null; return(false); }
public bool TryGetAnalyzer(ITextView textView, out ProjectAnalyzer analyzer, out string filename) { if (textView == null) { throw new ArgumentNullException(nameof(textView)); } // Try to get the analyzer from the main text buffer if (TryGetAnalyzer(textView.TextBuffer, out analyzer, out filename)) { return(true); } return(false); }
private const int ReparseDelay = 1000; // delay in MS before we re-parse a buffer w/ non-line changes. public BufferParser(IProjectEntry initialProjectEntry, ProjectAnalyzer parser, IList <ITextBuffer> buffers) { _parser = parser; _timer = new Timer(ReparseWorker, null, Timeout.Infinite, Timeout.Infinite); _buffers = buffers; _currentProjEntry = initialProjectEntry; if (PythonToolsPackage.Instance != null) { _indentationInconsistencySeverity = PythonToolsPackage.Instance.OptionsPage.IndentationInconsistencySeverity; PythonToolsPackage.Instance.OptionsPage.IndentationInconsistencyChanged += OptionsPage_IndentationInconsistencyChanged; } foreach (var buffer in buffers) { InitBuffer(buffer); } }
/// <summary> /// Creates a new parse queue which will parse using the provided parser. /// </summary> /// <param name="parser"></param> public ParseQueue(ProjectAnalyzer parser) { _parser = parser; }
/// <summary> /// Gets a CompletionAnalysis providing a list of possible members the user can dot through. /// </summary> public static CompletionAnalysis GetCompletions(this ITextSnapshot snapshot, ITrackingSpan span, bool intersectMembers = true, bool hideAdvancedMembers = false) { return(ProjectAnalyzer.GetCompletions(snapshot, span, intersectMembers, hideAdvancedMembers)); }
/// <summary> /// Gets a list of signatuers available for the expression at the provided location in the snapshot. /// </summary> public static SignatureAnalysis GetSignatures(this ITextSnapshot snapshot, ITrackingSpan span) { return(ProjectAnalyzer.GetSignatures(snapshot, span)); }
/// <summary> /// Gets a ExpressionAnalysis for the expression at the provided span. If the span is in /// part of an identifier then the expression is extended to complete the identifier. /// </summary> public static ExpressionAnalysis AnalyzeExpression(this ITextSnapshot snapshot, ITrackingSpan span, bool forCompletion = true) { return(ProjectAnalyzer.AnalyzeExpression(snapshot, span, forCompletion)); }