public LocationPreviewItem(FilePreviewItem parent, LocationInfo locationInfo, VariableType type) { _lineNo = locationInfo.Line; _columnNo = locationInfo.Column; _parent = parent; string text = locationInfo.ProjectEntry.GetLine(locationInfo.Line); string trimmed = text.TrimStart(_whitespace); _text = trimmed; _type = type; _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); } } }
private List<FilePreviewItem> CreatePreviewItems() { Dictionary<string, FilePreviewItem> files = new Dictionary<string, FilePreviewItem>(); Dictionary<FilePreviewItem, HashSet<AnalysisLocation>> allItems = new Dictionary<FilePreviewItem, HashSet<AnalysisLocation>>(); foreach (var variable in _variables) { switch (variable.Type) { case VariableType.Definition: case VariableType.Reference: string file = variable.Location.FilePath; FilePreviewItem fileItem; HashSet<AnalysisLocation> curLocations; if (!files.TryGetValue(file, out fileItem)) { files[file] = fileItem = new FilePreviewItem(this, file); allItems[fileItem] = curLocations = new HashSet<AnalysisLocation>(AnalysisLocation.FullComparer); } else { curLocations = allItems[fileItem]; } if (!curLocations.Contains(variable.Location)) { fileItem.Items.Add(new LocationPreviewItem(_analyzer, fileItem, variable.Location, variable.Type)); curLocations.Add(variable.Location); } break; } } List<FilePreviewItem> fileItems = new List<FilePreviewItem>(files.Values); foreach (var fileItem in fileItems) { fileItem.Items.Sort(LocationComparer); } fileItems.Sort(FileComparer); return fileItems; }
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; } }
private LocationPreviewItem(FilePreviewItem parent, string text, int line, int column, Span span) { _parent = parent; _text = text; Line = line; Column = column; _span = span; }
private List <FilePreviewItem> CreatePreviewItems() { Dictionary <string, FilePreviewItem> files = new Dictionary <string, FilePreviewItem>(); Dictionary <FilePreviewItem, HashSet <LocationInfo> > allItems = new Dictionary <FilePreviewItem, HashSet <LocationInfo> >(); foreach (var variable in _variables) { if (string.IsNullOrEmpty(variable.Location?.FilePath)) { continue; } switch (variable.Type) { case VariableType.Definition: case VariableType.Reference: string file = variable.Location.FilePath; FilePreviewItem fileItem; HashSet <LocationInfo> curLocations; if (!files.TryGetValue(file, out fileItem)) { files[file] = fileItem = new FilePreviewItem(this, file); allItems[fileItem] = curLocations = new HashSet <LocationInfo>(LocationInfo.FullComparer); } else { curLocations = allItems[fileItem]; } if (!curLocations.Contains(variable.Location)) { try { var item = LocationPreviewItem.Create(_analyzer, fileItem, variable.Location, variable.Type); if (item != null && item.Length > 0) { fileItem.Items.Add(item); curLocations.Add(variable.Location); } } catch (Exception ex) when(!ex.IsCriticalException()) { ex.ReportUnhandledException(_serviceProvider, GetType()); } } break; } } List <FilePreviewItem> fileItems = new List <FilePreviewItem>(files.Values); foreach (var fileItem in fileItems) { fileItem.Items.Sort(LocationComparer); } fileItems.Sort(FileComparer); return(fileItems); }
private List <FilePreviewItem> CreatePreviewItems() { Dictionary <string, FilePreviewItem> files = new Dictionary <string, FilePreviewItem>(); Dictionary <FilePreviewItem, HashSet <LocationInfo> > allItems = new Dictionary <FilePreviewItem, HashSet <LocationInfo> >(); foreach (var variable in _variables) { switch (variable.Type) { case VariableType.Definition: case VariableType.Reference: string file = variable.Location.FilePath; FilePreviewItem fileItem; HashSet <LocationInfo> curLocations; if (!files.TryGetValue(file, out fileItem)) { files[file] = fileItem = new FilePreviewItem(this, file); allItems[fileItem] = curLocations = new HashSet <LocationInfo>(LocationInfo.FullComparer); } else { curLocations = allItems[fileItem]; } if (!curLocations.Contains(variable.Location)) { fileItem.Items.Add(new LocationPreviewItem(fileItem, variable.Location, variable.Type)); curLocations.Add(variable.Location); } break; } } List <FilePreviewItem> fileItems = new List <FilePreviewItem>(files.Values); foreach (var fileItem in fileItems) { fileItem.Items.Sort(LocationComparer); } fileItems.Sort(FileComparer); return(fileItems); }
public static LocationPreviewItem Create(VsProjectAnalyzer analyzer, FilePreviewItem parent, LocationInfo locationInfo, VariableType type) { Debug.Assert(locationInfo.StartColumn >= 1, "Invalid location info (Column)"); Debug.Assert(locationInfo.StartLine >= 1, "Invalid location info (Line)"); var origName = parent?.Engine?.OriginalName; if (string.IsNullOrEmpty(origName)) { return(null); } var analysis = analyzer.GetAnalysisEntryFromUri(locationInfo.DocumentUri) ?? analyzer.GetAnalysisEntryFromPath(locationInfo.FilePath); if (analysis == null) { return(null); } var text = analysis.GetLine(locationInfo.StartLine); if (string.IsNullOrEmpty(text)) { return(null); } int start, length; if (!GetSpan(text, origName, locationInfo, out start, out length)) { // Name does not match exactly, so we might be renaming a prefixed name var prefix = parent.Engine.PrivatePrefix; if (string.IsNullOrEmpty(prefix)) { // No prefix available, so don't rename this return(null); } var newName = parent.Engine.Request.Name; if (string.IsNullOrEmpty(newName)) { // No incoming name Debug.Fail("No incoming name"); return(null); } if (!GetSpanWithPrefix(text, origName, locationInfo, prefix, newName, out start, out length)) { // Not renaming a prefixed name return(null); } } if (start < 0 || length <= 0) { Debug.Fail("Expected valid span"); return(null); } var trimText = text.TrimStart(_whitespace); return(new LocationPreviewItem( parent, trimText, locationInfo.StartLine, start + 1, new Span(start - (text.Length - trimText.Length), length) )); }
private static int FileComparer(FilePreviewItem left, FilePreviewItem right) { return(String.Compare(left.Filename, right.Filename, StringComparison.OrdinalIgnoreCase)); }
public LocationPreviewItem(VsProjectAnalyzer analyzer, FilePreviewItem parent, LocationInfo locationInfo, VariableType type) { Debug.Assert(locationInfo.StartColumn >= 1, "Invalid location info (Column)"); Debug.Assert(locationInfo.StartLine >= 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.GetAnalysisEntryFromUri(locationInfo.DocumentUri) ?? analyzer.GetAnalysisEntryFromPath(locationInfo.FilePath); if (analysis == null) { return; } var text = analysis.GetLine(locationInfo.StartLine); 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.StartLine; Column = start + 1; _span = new Span(start - (text.Length - _text.Length), length); }
private static int FileComparer(FilePreviewItem left, FilePreviewItem right) { return String.Compare(left.Filename, right.Filename, StringComparison.OrdinalIgnoreCase); }