Ejemplo n.º 1
0
        public LocationPreviewItem(VsProjectAnalyzer analyzer, FilePreviewItem parent, AnalysisLocation locationInfo, VariableType type) {
            _lineNo = locationInfo.Line;
            _columnNo = locationInfo.Column;            
            _parent = parent;
            var analysis = analyzer.GetAnalysisEntryFromPath(locationInfo.FilePath);
            _type = type;
            if (analysis != null) {
                string text = analysis.GetLine(locationInfo.Line);
                string trimmed = text.TrimStart(_whitespace);
                _text = trimmed;
                _span = new Span(_columnNo - (text.Length - trimmed.Length) - 1, parent.Engine.OriginalName.Length);
                if (String.Compare(_text, _span.Start, parent.Engine.OriginalName, 0, parent.Engine.OriginalName.Length) != 0) {
                    // we are renaming a name mangled name (or we have a bug where the names aren't lining up).
                    Debug.Assert(_text.Substring(_span.Start, _span.Length + 1 + parent.Engine.PrivatePrefix.Length) == "_" + parent.Engine.PrivatePrefix + parent.Engine.OriginalName);


                    if (parent.Engine.Request.Name.StartsWith("__")) {
                        // if we're renaming to a private prefix name then we just rename the non-prefixed portion
                        _span = new Span(_span.Start + 1 + parent.Engine.PrivatePrefix.Length, _span.Length);
                        _columnNo += 1 + parent.Engine.PrivatePrefix.Length;
                    } else {
                        // otherwise we renmae the prefixed and non-prefixed portion
                        _span = new Span(_span.Start, _span.Length + 1 + parent.Engine.PrivatePrefix.Length);
                    }
                }
            } else {
                _text = String.Empty;
            }
        }
Ejemplo n.º 2
0
        private static bool GetSpanWithPrefix(string text, string origName, AnalysisLocation loc, string prefix, string newName, out int start, out int length)
        {
            if (string.IsNullOrEmpty(prefix))
            {
                throw new ArgumentNullException(nameof(prefix));
            }
            if (string.IsNullOrEmpty(newName))
            {
                throw new ArgumentNullException(nameof(prefix));
            }

            if (!GetSpan(text, prefix + origName, loc, out start, out length))
            {
                start  = -1;
                length = -1;
                return(false);
            }

            if (newName.StartsWith("__") && newName.Length > 2)
            {
                // renaming from private name to private name, so just rename the non-prefixed portion
                start  += prefix.Length;
                length -= prefix.Length;
            }

            return(true);
        }
Ejemplo n.º 3
0
        private static bool GetSpan(string text, string origName, AnalysisLocation loc, out int start, out int length)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException(nameof(origName));
            }

            start  = loc.Column - 1;
            length = origName.Length;
            if (start < 0 || length <= 0)
            {
                Debug.Fail("Invalid span for '{0}': [{1}..{2})".FormatInvariant(origName, start, start + length));
                return(false);
            }

            var cmp = CultureInfo.InvariantCulture.CompareInfo;

            try {
                if (cmp.Compare(text, start, length, origName, 0, origName.Length) == 0)
                {
                    // Name matches, so return the span
                    return(true);
                }
            } catch (ArgumentOutOfRangeException ex) {
                Debug.Fail(ex.ToUnhandledExceptionMessage(typeof(LocationPreviewItem)));
            }

            start  = -1;
            length = -1;
            return(false);
        }
Ejemplo n.º 4
0
 public SimpleLocationInfo(VsProjectAnalyzer analyzer, IServiceProvider serviceProvider, string searchText, AnalysisLocation locInfo, StandardGlyphGroup glyphType) {
     _serviceProvider = serviceProvider;
     _locationInfo = locInfo;
     _glyphType = glyphType;
     _pathText = GetSearchDisplayText();
     AnalysisEntry entry = analyzer.GetAnalysisEntryFromPath(_locationInfo.FilePath);
     if (entry != null) {
         _lineText = entry.GetLine(_locationInfo.Line);
     } else {
         _lineText = "";
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Moves the caret to the specified location, staying in the current text view 
        /// if possible.
        /// 
        /// https://pytools.codeplex.com/workitem/1649
        /// </summary>
        private void GotoLocation(AnalysisLocation location) {
            Debug.Assert(location != null);
            Debug.Assert(location.Line > 0);
            Debug.Assert(location.Column > 0);

            if (PathUtils.IsSamePath(location.FilePath, _textView.GetFilePath())) {
                var viewAdapter = _vsTextView;
                viewAdapter.SetCaretPos(location.Line - 1, location.Column - 1);
                viewAdapter.CenterLines(location.Line - 1, 1);
            } else {
                location.GotoSource(_serviceProvider);
            }
        }
Ejemplo n.º 6
0
        private IDocumentPeekResult CreateResult(AnalysisLocation location)
        {
            var fileName = PathUtils.GetFileOrDirectoryName(location.FilePath);

            var displayInfo = new PeekResultDisplayInfo2(
                label: string.Format("{0} - ({1}, {2})", fileName, location.Line, location.Column),
                labelTooltip: location.FilePath,
                title: fileName,
                titleTooltip: location.FilePath,
                startIndexOfTokenInLabel: 0,
                lengthOfTokenInLabel: 0
                );

            int startLine   = location.Line - 1;
            int startColumn = location.Column - 1;
            int endLine     = startLine;
            int endColumn   = startColumn;

            if (location.DefinitionStartLine.HasValue)
            {
                startLine = location.DefinitionStartLine.Value - 1;
            }
            if (location.DefinitionStartColumn.HasValue)
            {
                startColumn = location.DefinitionStartColumn.Value - 1;
            }
            if (location.DefinitionEndLine.HasValue)
            {
                endLine = location.DefinitionEndLine.Value - 1;
            }
            if (location.DefinitionEndColumn.HasValue)
            {
                endColumn = location.DefinitionEndColumn.Value - 1;
            }

            return(_peekResultFactory.Create(
                       displayInfo,
                       default(ImageMoniker),
                       location.FilePath,
                       startLine,
                       startColumn,
                       endLine,
                       endColumn,
                       location.Line - 1,
                       location.Column - 1,
                       location.Line - 1,
                       location.Column - 1,
                       isReadOnly: false,
                       editorDestination: new Guid(PythonConstants.EditorFactoryGuid)
                       ));
        }
Ejemplo n.º 7
0
            public async Task CheckDefinitionLocation(int pos, int length, AnalysisLocation expected)
            {
                var entry = (AnalysisEntry)_view.GetAnalysisEntry();

                entry.Analyzer.WaitForCompleteAnalysis(_ => true);

                var trackingSpan = _view.CurrentSnapshot.CreateTrackingSpan(pos, length, SpanTrackingMode.EdgeInclusive);
                var snapshotSpan = trackingSpan.GetSpan(_view.CurrentSnapshot);
                var result       = await NavigableSymbolSource.GetDefinitionLocationAsync(entry, _view.View.TextView, snapshotSpan);

                if (expected != null)
                {
                    Assert.IsNotNull(result);
                    Assert.AreEqual(expected.Line, result.Line);
                    Assert.AreEqual(expected.Column, result.Column);
                    Assert.AreEqual(expected.FilePath, Path.GetFileName(result.FilePath));
                }
                else
                {
                    Assert.IsNull(result);
                }
            }
Ejemplo n.º 8
0
        public LocationPreviewItem(VsProjectAnalyzer analyzer, FilePreviewItem parent, AnalysisLocation locationInfo, VariableType type)
        {
            _lineNo   = locationInfo.Line;
            _columnNo = locationInfo.Column;
            _parent   = parent;
            var analysis = analyzer.GetAnalysisEntryFromPath(locationInfo.FilePath);

            _type = type;
            if (analysis != null)
            {
                string text    = analysis.GetLine(locationInfo.Line) ?? "";
                string trimmed = text.TrimStart(_whitespace);
                _text = trimmed;
                _span = new Span(_columnNo - (text.Length - trimmed.Length) - 1, parent.Engine.OriginalName.Length);
                if (String.Compare(_text, _span.Start, parent.Engine.OriginalName, 0, parent.Engine.OriginalName.Length) != 0)
                {
                    // we are renaming a name mangled name (or we have a bug where the names aren't lining up).
                    Debug.Assert(_text.Substring(_span.Start, _span.Length + 1 + parent.Engine.PrivatePrefix.Length) == "_" + parent.Engine.PrivatePrefix + parent.Engine.OriginalName);


                    if (parent.Engine.Request.Name.StartsWith("__"))
                    {
                        // if we're renaming to a private prefix name then we just rename the non-prefixed portion
                        _span      = new Span(_span.Start + 1 + parent.Engine.PrivatePrefix.Length, _span.Length);
                        _columnNo += 1 + parent.Engine.PrivatePrefix.Length;
                    }
                    else
                    {
                        // otherwise we renmae the prefixed and non-prefixed portion
                        _span = new Span(_span.Start, _span.Length + 1 + parent.Engine.PrivatePrefix.Length);
                    }
                }
            }
            else
            {
                _text = String.Empty;
            }
        }
Ejemplo n.º 9
0
 public AnalysisVariable(VariableType type, AnalysisLocation location) {
     _loc = location;
     _type = type;
 }
Ejemplo n.º 10
0
 public NavigableSymbol(IServiceProvider serviceProvider, AnalysisLocation location, SnapshotSpan span)
 {
     _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     Location         = location ?? throw new ArgumentNullException(nameof(location));
     SymbolSpan       = span;
 }
Ejemplo n.º 11
0
        public LocationPreviewItem(VsProjectAnalyzer analyzer, FilePreviewItem parent, AnalysisLocation locationInfo, VariableType type)
        {
            Debug.Assert(locationInfo.Column >= 1, "Invalid location info (Column)");
            Debug.Assert(locationInfo.Line >= 1, "Invalid location info (Line)");
            _parent = parent;
            Type    = type;
            _text   = string.Empty;

            var origName = _parent?.Engine?.OriginalName;

            if (string.IsNullOrEmpty(origName))
            {
                return;
            }

            var analysis = analyzer.GetAnalysisEntryFromPath(locationInfo.FilePath);

            if (analysis == null)
            {
                return;
            }

            var text = analysis.GetLine(locationInfo.Line);

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            int start, length;

            if (!GetSpan(text, origName, locationInfo, out start, out length))
            {
                // Name does not match exactly, so we should be renaming a prefixed name
                var prefix = parent.Engine.PrivatePrefix;
                if (string.IsNullOrEmpty(prefix))
                {
                    // No prefix available, so fail
                    Debug.Fail("Failed to find '{0}' in '{1}' because we had no private prefix".FormatInvariant(origName, text));
                    return;
                }

                var newName = parent.Engine.Request.Name;
                if (string.IsNullOrEmpty(newName))
                {
                    // No incoming name
                    Debug.Fail("No incoming name");
                    return;
                }

                if (!GetSpanWithPrefix(text, origName, locationInfo, "_" + prefix, newName, out start, out length))
                {
                    // Not renaming a prefixed name
                    Debug.Fail("Failed to find '{0}' in '{1}'".FormatInvariant(origName, text));
                    return;
                }
            }

            if (start < 0 || length <= 0)
            {
                Debug.Fail("Expected valid span");
                return;
            }

            _text  = text.TrimStart(_whitespace);
            Line   = locationInfo.Line;
            Column = start + 1;
            _span  = new Span(start - (text.Length - _text.Length), length);
        }