Browse Source

Add 'Search for issues' dialog

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
bb950e3ddf
  1. 9
      README.txt
  2. 6
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin
  3. 11
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj
  4. 5
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueManager.cs
  5. 133
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SearchForIssuesCommand.cs
  6. 38
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SearchForIssuesDialog.xaml
  7. 128
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SearchForIssuesDialog.xaml.cs
  8. 22
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs
  9. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs
  10. 1
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs
  11. 7
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/DocumentHighlighter.cs
  12. 13
      src/Main/Base/Project/Editor/Search/SearchResultMatch.cs
  13. 4
      src/Main/Base/Project/Src/Services/RefactoringService/Reference.cs

9
README.txt

@ -20,13 +20,14 @@ How To Compile
SharpDevelop can be compiled using the supplied .bat files, or in SharpDevelop itself. SharpDevelop can be compiled using the supplied .bat files, or in SharpDevelop itself.
System Requirements (running SharpDevelop) System Requirements (running SharpDevelop)
- Windows 7 or higher. - Windows Vista or higher.
- .NET 4.5 Full (Extended, the "Client" portion is not sufficient) - .NET 4.5
- Visual C++ 2008 SP1 Runtime (http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&displaylang=en) - Visual C++ 2008 SP1 Runtime (http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&displaylang=en)
Extended Requirements (building SharpDevelop) Extended Requirements (building SharpDevelop)
- .NET 3.5 SP1 - .NET 3.5 SP1
- Windows SDK 7.1 - .NET 4.5 SDK (part of Windows SDK 8.0)
- Windows SDK 7.1 (?? not sure if this still is necessary...)
- Windows SDK 7.0 (optional; C++ compiler needed for profiler) - Windows SDK 7.0 (optional; C++ compiler needed for profiler)
- Windows PowerShell - Windows PowerShell
@ -69,4 +70,4 @@ SharpDevelop Contributors:
Siegfried Pammer Siegfried Pammer
Peter Forstmeier (SharpDevelop Reports) Peter Forstmeier (SharpDevelop Reports)
(for a full list see http://wiki.sharpdevelop.net/Contributors.ashx) (for a full list see https://github.com/icsharpcode/SharpDevelop/wiki/Contributors)

6
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin

@ -144,6 +144,12 @@
</OptionPanel> </OptionPanel>
</Path> </Path>
<Path path = "/SharpDevelop/Workbench/MainMenu/Search">
<MenuItem id = "SearchForIssues"
label="Search For Issues..."
class="CSharpBinding.Refactoring.SearchForIssuesCommand"/>
</Path>
<Path path = "/SharpDevelop/ViewContent/TextEditor/C#/IssueProviders"> <Path path = "/SharpDevelop/ViewContent/TextEditor/C#/IssueProviders">
<Class id = "ConditionalToNullCoalescing" <Class id = "ConditionalToNullCoalescing"
class = "ICSharpCode.NRefactory.CSharp.Refactoring.ConditionalToNullCoalescingIssue" /> class = "ICSharpCode.NRefactory.CSharp.Refactoring.ConditionalToNullCoalescingIssue" />

11
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj

@ -81,6 +81,11 @@
<Compile Include="Src\Refactoring\IssueOptionsViewModel.cs" /> <Compile Include="Src\Refactoring\IssueOptionsViewModel.cs" />
<Compile Include="Src\Refactoring\SDRedundantUsingIssue.cs" /> <Compile Include="Src\Refactoring\SDRedundantUsingIssue.cs" />
<Compile Include="Src\Refactoring\SDScript.cs" /> <Compile Include="Src\Refactoring\SDScript.cs" />
<Compile Include="Src\Refactoring\SearchForIssuesCommand.cs" />
<Compile Include="Src\Refactoring\SearchForIssuesDialog.xaml.cs">
<DependentUpon>SearchForIssuesDialog.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<EmbeddedResource Include="Resources\MyNamespaceSupportForCSharp.cs" /> <EmbeddedResource Include="Resources\MyNamespaceSupportForCSharp.cs" />
<Compile Include="Src\CodeManipulation.cs" /> <Compile Include="Src\CodeManipulation.cs" />
<Compile Include="Src\Completion\CompletionData.cs" /> <Compile Include="Src\Completion\CompletionData.cs" />
@ -132,6 +137,11 @@
<Name>ICSharpCode.NRefactory</Name> <Name>ICSharpCode.NRefactory</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\..\Libraries\SharpTreeView\ICSharpCode.TreeView\ICSharpCode.TreeView.csproj">
<Project>{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}</Project>
<Name>ICSharpCode.TreeView</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> <ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> <Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name> <Name>ICSharpCode.SharpDevelop</Name>
@ -165,6 +175,7 @@
<ItemGroup> <ItemGroup>
<Page Include="Src\Refactoring\IssueOptions.xaml" /> <Page Include="Src\Refactoring\IssueOptions.xaml" />
<Page Include="Src\OptionPanels\BuildOptions.xaml" /> <Page Include="Src\OptionPanels\BuildOptions.xaml" />
<Page Include="Src\Refactoring\SearchForIssuesDialog.xaml" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project> </Project>

5
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueManager.cs

@ -38,7 +38,6 @@ namespace CSharpBinding.Refactoring
internal class IssueProvider internal class IssueProvider
{ {
readonly ICodeIssueProvider provider;
public readonly Type ProviderType; public readonly Type ProviderType;
public readonly IssueDescriptionAttribute Attribute; public readonly IssueDescriptionAttribute Attribute;
@ -46,7 +45,6 @@ namespace CSharpBinding.Refactoring
{ {
if (provider == null) if (provider == null)
throw new ArgumentNullException("provider"); throw new ArgumentNullException("provider");
this.provider = provider;
this.ProviderType = provider.GetType(); this.ProviderType = provider.GetType();
var attributes = ProviderType.GetCustomAttributes(typeof(IssueDescriptionAttribute), true); var attributes = ProviderType.GetCustomAttributes(typeof(IssueDescriptionAttribute), true);
@ -67,6 +65,9 @@ namespace CSharpBinding.Refactoring
public IEnumerable<CodeIssue> GetIssues(BaseRefactoringContext context) public IEnumerable<CodeIssue> GetIssues(BaseRefactoringContext context)
{ {
// use a separate instance for every call, this is necessary
// for thread-safety
var provider = (ICodeIssueProvider)Activator.CreateInstance(ProviderType);
return provider.GetIssues(context); return provider.GetIssues(context);
} }
} }

133
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SearchForIssuesCommand.cs

@ -0,0 +1,133 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CSharpBinding.Parser;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor.Search;
using ICSharpCode.SharpDevelop.Project;
namespace CSharpBinding.Refactoring
{
public class SearchForIssuesCommand : SimpleCommand
{
public override void Execute(object parameter)
{
SearchForIssuesDialog dlg = new SearchForIssuesDialog();
dlg.Owner = SD.Workbench.MainWindow;
if (dlg.ShowDialog() == true) {
var providers = dlg.SelectedProviders.ToList();
var fileNames = GetFilesToSearch(dlg.Target).ToList();
var monitor = SD.StatusBar.CreateProgressMonitor();
var observable = ReactiveExtensions.CreateObservable<SearchedFile>(
(m, c) => SearchForIssuesAsync(fileNames, providers, c, m),
monitor);
SearchResultsPad.Instance.ShowSearchResults("Issue Search", observable);
}
}
IEnumerable<FileName> GetFilesToSearch(SearchForIssuesTarget target)
{
SD.MainThread.VerifyAccess();
switch (target) {
case SearchForIssuesTarget.CurrentDocument:
if (SD.Workbench.ActiveViewContent != null) {
FileName fileName = SD.Workbench.ActiveViewContent.PrimaryFileName;
if (fileName != null)
return new[] { fileName };
}
break;
case SearchForIssuesTarget.WholeProject:
return GetFilesFromProject(ProjectService.CurrentProject);
case SearchForIssuesTarget.WholeSolution:
if (ProjectService.OpenSolution != null) {
return ProjectService.OpenSolution.Projects.SelectMany(GetFilesFromProject).Distinct();
}
break;
default:
throw new Exception("Invalid value for SearchForIssuesTarget");
}
return Enumerable.Empty<FileName>();
}
IEnumerable<FileName> GetFilesFromProject(IProject project)
{
if (project == null)
return Enumerable.Empty<FileName>();
return from item in project.GetItemsOfType(ItemType.Compile)
where item.FileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)
select FileName.Create(item.FileName);
}
Task SearchForIssuesAsync(List<FileName> fileNames, IEnumerable<IssueManager.IssueProvider> providers, Action<SearchedFile> callback, IProgressMonitor monitor)
{
return Task.Run(() => SearchForIssues(fileNames, providers, callback, monitor));
}
void SearchForIssues(List<FileName> fileNames, IEnumerable<IssueManager.IssueProvider> providers, Action<SearchedFile> callback, IProgressMonitor monitor)
{
ParseableFileContentFinder contentFinder = new ParseableFileContentFinder();
int filesProcessed = 0;
Parallel.ForEach(
fileNames,
delegate (FileName fileName) {
var fileContent = contentFinder.Create(fileName);
var resultForFile = SearchForIssues(fileName, fileContent, providers, monitor.CancellationToken);
if (resultForFile != null) {
callback(resultForFile);
}
monitor.Progress = (double)Interlocked.Increment(ref filesProcessed) / fileNames.Count;
});
}
SearchedFile SearchForIssues(FileName fileName, ITextSource fileContent, IEnumerable<IssueManager.IssueProvider> providers, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var parseInfo = SD.ParserService.Parse(fileName, fileContent, cancellationToken: cancellationToken) as CSharpFullParseInformation;
if (parseInfo == null)
return null;
var compilation = SD.ParserService.GetCompilationForFile(fileName);
var resolver = parseInfo.GetResolver(compilation);
var context = new SDRefactoringContext(fileContent, resolver, new TextLocation(0, 0), 0, 0, cancellationToken);
ReadOnlyDocument document = null;
IHighlighter highlighter = null;
var results = new List<SearchResultMatch>();
foreach (var provider in providers) {
cancellationToken.ThrowIfCancellationRequested();
foreach (var issue in provider.GetIssues(context)) {
if (document == null) {
document = new ReadOnlyDocument(fileContent, fileName);
highlighter = SD.EditorControlService.CreateHighlighter(document);
}
results.Add(SearchResultMatch.Create(document, issue.Start, issue.End, highlighter));
}
}
if (results.Count > 0)
return new SearchedFile(fileName, results);
else
return null;
}
}
public enum SearchForIssuesTarget
{
[Description("${res:Dialog.NewProject.SearchReplace.LookIn.CurrentDocument}")]
CurrentDocument,
//[Description("${res:Dialog.NewProject.SearchReplace.LookIn.AllOpenDocuments}")]
//AllOpenFiles,
[Description("${res:Dialog.NewProject.SearchReplace.LookIn.WholeProject}")]
WholeProject,
[Description("${res:Dialog.NewProject.SearchReplace.LookIn.WholeSolution}")]
WholeSolution
}
}

38
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SearchForIssuesDialog.xaml

@ -0,0 +1,38 @@
<Window x:Class="CSharpBinding.Refactoring.SearchForIssuesDialog"
x:ClassModifier="internal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tv="http://icsharpcode.net/sharpdevelop/treeview"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"
xmlns:local="clr-namespace:CSharpBinding.Refactoring"
Style="{x:Static core:GlobalStyles.DialogWindowStyle}"
WindowStartupLocation="CenterOwner"
MinHeight="250" MinWidth="200"
Height="450" Width="400" Title="Search For Issues">
<Grid Margin="6">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<Label Content="Search In:" />
<widgets:RadioButtonGroup Name="searchInRBG" Margin="0,6,0,0" gui:EnumBinding.EnumType="local:SearchForIssuesTarget" />
</StackPanel>
<Label Content="Issues:" Grid.Row="1" HorizontalAlignment="Left" />
<tv:SharpTreeView Name="treeView" Grid.Row="2" Margin="4,0,4,4" />
<CheckBox Name="fixCheckBox" Grid.Row="3" Margin="8,0,0,0" Checked="FixCheckBox_Checked" Unchecked="FixCheckBox_Unchecked"
HorizontalAlignment="Left" Content="Automatically fix issues if possible" />
<StackPanel Grid.Row="4" Margin="4" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Content="Search" Style="{x:Static core:GlobalStyles.ButtonStyle}" Name="searchButton" IsDefault="True" Click="searchButton_Click" Margin="0,0,5,0" />
<Button Content="{core:Localize Global.CloseButtonText}" Style="{x:Static core:GlobalStyles.ButtonStyle}" IsCancel="True" />
</StackPanel>
</Grid>
</Window>

128
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SearchForIssuesDialog.xaml.cs

@ -0,0 +1,128 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.TreeView;
namespace CSharpBinding.Refactoring
{
/// <summary>
/// Interaction logic for SearchForIssues.xaml
/// </summary>
internal partial class SearchForIssuesDialog : Window
{
public SearchForIssuesDialog()
{
InitializeComponent();
FixCheckBox_Unchecked(null, null);
treeView.Root = new RootTreeNode(IssueManager.IssueProviders);
}
public SearchForIssuesTarget Target {
get {
return (SearchForIssuesTarget)searchInRBG.SelectedValue;
}
}
public IEnumerable<IssueManager.IssueProvider> SelectedProviders {
get {
return treeView.Root.Descendants().OfType<IssueTreeNode>()
.Where(n => n.IsChecked == true).Select(n => n.Provider);
}
}
public bool FixIssues {
get {
return fixCheckBox.IsChecked == true;
}
}
void searchButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}
void FixCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
searchButton.Content = "Search";
}
void FixCheckBox_Checked(object sender, RoutedEventArgs e)
{
searchButton.Content = "Search and Fix";
}
sealed class RootTreeNode : SharpTreeNode
{
internal RootTreeNode(IEnumerable<IssueManager.IssueProvider> providers)
{
this.Children.AddRange(providers.GroupBy(p => p.Attribute.Category, (key, g) => new CategoryTreeNode(key, g)));
this.IsChecked = false;
this.IsExpanded = true;
}
public override object Text {
get { return "C# Issues"; }
}
public override bool IsCheckable {
get { return true; }
}
}
sealed class CategoryTreeNode : SharpTreeNode
{
readonly string categoryName;
internal CategoryTreeNode(string categoryName, IEnumerable<IssueManager.IssueProvider> providers)
{
this.categoryName = categoryName;
this.Children.AddRange(providers.Select(p => new IssueTreeNode(p)));
this.IsExpanded = true;
}
public override object Text {
get { return categoryName; }
}
public override bool IsCheckable {
get { return true; }
}
}
sealed class IssueTreeNode : SharpTreeNode
{
internal readonly IssueManager.IssueProvider Provider;
readonly IssueDescriptionAttribute attribute;
internal IssueTreeNode(IssueManager.IssueProvider provider)
{
this.Provider = provider;
this.attribute = provider.Attribute;
}
public override bool IsCheckable {
get { return true; }
}
public override object Text {
get { return attribute.Title; }
}
public override object ToolTip {
get { return attribute.Description; }
}
}
}
}

22
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs

@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -10,6 +11,7 @@ using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory.Editor; using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
@ -34,14 +36,22 @@ namespace ICSharpCode.AvalonEdit.AddIn
public IHighlighter CreateHighlighter(IDocument document) public IHighlighter CreateHighlighter(IDocument document)
{ {
Debug.Assert(document.FileName != null, "FileName not set in " + document.GetType().FullName); if (document.FileName == null)
return null;
var def = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(document.FileName)); var def = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(document.FileName));
var doc = document as TextDocument; if (def == null)
if (def == null || doc == null)
return null; return null;
var baseHighlighter = new DocumentHighlighter(doc, def); List<IHighlighter> highlighters = new List<IHighlighter>();
var additionalHighlighters = AddInTree.BuildItems<IHighlighter>(HighlighterDoozer.AddInPath, doc, false); var textDocument = document as TextDocument;
var multiHighlighter = new MultiHighlighter(document, new[] { baseHighlighter }.Concat(additionalHighlighters).ToArray()); var readOnlyDocument = document as ReadOnlyDocument;
if (textDocument != null) {
highlighters.Add(new DocumentHighlighter(textDocument, def));
} else if (readOnlyDocument != null) {
highlighters.Add(new DocumentHighlighter(readOnlyDocument, def));
}
// add additional highlighters
highlighters.AddRange(SD.AddInTree.BuildItems<IHighlighter>(HighlighterDoozer.AddInPath, document, false));
var multiHighlighter = new MultiHighlighter(document, highlighters.ToArray());
return new CustomizableHighlightingColorizer.CustomizingHighlighter( return new CustomizableHighlightingColorizer.CustomizingHighlighter(
document, CustomizedHighlightingColor.FetchCustomizations(def.Name), document, CustomizedHighlightingColor.FetchCustomizations(def.Name),
def, multiHighlighter); def, multiHighlighter);

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs

@ -289,12 +289,12 @@ namespace ICSharpCode.AvalonEdit.AddIn
public void BeginHighlighting() public void BeginHighlighting()
{ {
baseHighlighter.BeginHighlighting();
} }
public void EndHighlighting() public void EndHighlighting()
{ {
baseHighlighter.EndHighlighting();
} }
} }

1
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs

@ -210,7 +210,6 @@ namespace SearchAndReplace
ThrowIfCancellationRequested(); ThrowIfCancellationRequested();
if (document == null) { if (document == null) {
document = new ReadOnlyDocument(source, fileName); document = new ReadOnlyDocument(source, fileName);
var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName));
highlighter = SD.EditorControlService.CreateHighlighter(document); highlighter = SD.EditorControlService.CreateHighlighter(document);
} }
var start = document.GetLocation(result.Offset); var start = document.GetLocation(result.Offset);

7
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/DocumentHighlighter.cs

@ -496,10 +496,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
#endregion #endregion
public HighlightingColor DefaultTextColor { public HighlightingColor DefaultTextColor {
get { get { return null; }
return new HighlightingColor() {
};
}
} }
public void BeginHighlighting() public void BeginHighlighting()
@ -514,7 +511,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
public HighlightingColor GetNamedColor(string name) public HighlightingColor GetNamedColor(string name)
{ {
throw new NotSupportedException(); return definition.GetNamedColor(name);
} }
} }
} }

13
src/Main/Base/Project/Editor/Search/SearchResultMatch.cs

@ -10,6 +10,7 @@ using System.Windows.Media;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Editor.Search namespace ICSharpCode.SharpDevelop.Editor.Search
@ -72,6 +73,18 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
this.defaultTextColor = defaultTextColor; this.defaultTextColor = defaultTextColor;
} }
public static SearchResultMatch Create(IDocument document, TextLocation startLocation, TextLocation endLocation, IHighlighter highlighter)
{
int startOffset = document.GetOffset(startLocation);
int endOffset = document.GetOffset(endLocation);
var inlineBuilder = SearchResultsPad.CreateInlineBuilder(startLocation, endLocation, document, highlighter);
var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
return new SearchResultMatch(FileName.Create(document.FileName),
startLocation, endLocation,
startOffset, endOffset - startOffset,
inlineBuilder, defaultTextColor);
}
/// <summary> /// <summary>
/// Gets a special text to display, or null to display the line's content. /// Gets a special text to display, or null to display the line's content.
/// </summary> /// </summary>

4
src/Main/Base/Project/Src/Services/RefactoringService/Reference.cs

@ -15,6 +15,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// </summary> /// </summary>
public class Reference : SearchResultMatch public class Reference : SearchResultMatch
{ {
// TODO: this looks like a memory usage problem
// SearchResultMatch is kept alive for a long time (list of previous searches),
// but ResolveResult keeps the whole compilation alive
// We might have to split Reference/SearchResultMatch into separate instances
ResolveResult resolveResult; ResolveResult resolveResult;
public Reference(DomRegion region, ResolveResult resolveResult, int offset, int length, HighlightedInlineBuilder builder, HighlightingColor defaultTextColor) public Reference(DomRegion region, ResolveResult resolveResult, int offset, int length, HighlightedInlineBuilder builder, HighlightingColor defaultTextColor)

Loading…
Cancel
Save