1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
//
// GotoDeclarationHandler.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using MonoDevelop.Core;
using MonoDevelop.Ide.Gui;
using MonoDevelop.Components.Commands;
using MonoDevelop.Refactoring;
using MonoDevelop.Ide;
using Microsoft.CodeAnalysis;
using System.Collections.Immutable;
using System.Threading.Tasks;
using MonoDevelop.Ide.Editor;
using System.Threading;
using System;
using Microsoft.CodeAnalysis.CSharp;
using ICSharpCode.NRefactory6.CSharp.Features.GotoDefinition;
using Mono.Posix;
using MonoDevelop.Ide.TypeSystem;
using System.Collections.Generic;
namespace MonoDevelop.CSharp.Refactoring
{
class GotoDeclarationHandler : CommandHandler
{
static GotoDeclarationHandler ()
{
GoToDefinitionService.TryNavigateToSymbol = delegate(ISymbol symbol, Microsoft.CodeAnalysis.Project project, bool usePreviewTab) {
IdeApp.ProjectOperations.JumpToDeclaration (symbol, TypeSystemService.GetMonoProject (project));
return true;
};
GoToDefinitionService.TryNavigateToSpan = delegate(Workspace workspace, DocumentId documentId, Microsoft.CodeAnalysis.Text.TextSpan textSpan, bool usePreviewTab) {
var project = workspace.CurrentSolution.GetProject (documentId.ProjectId);
if (project == null)
return false;
IdeApp.Workbench.OpenDocument (new FileOpenInformation (project.GetDocument (documentId).FilePath, TypeSystemService.GetMonoProject (project)) {
Offset = textSpan.Start
});
return true;
};
GoToDefinitionService.DisplayMultiple = delegate(IEnumerable<Tuple<Solution, ISymbol, Location>> list) {
using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true)) {
foreach (var part in list)
monitor.ReportResult (GetJumpTypePartSearchResult (part.Item2, part.Item3));
}
};
}
static MonoDevelop.Ide.FindInFiles.SearchResult GetJumpTypePartSearchResult (Microsoft.CodeAnalysis.ISymbol part, Microsoft.CodeAnalysis.Location location)
{
var provider = new MonoDevelop.Ide.FindInFiles.FileProvider (location.SourceTree.FilePath);
var doc = TextEditorFactory.CreateNewDocument ();
doc.Text = provider.ReadString ();
int position = location.SourceSpan.Start;
while (position + part.Name.Length < doc.Length) {
if (doc.GetTextAt (position, part.Name.Length) == part.Name)
break;
position++;
}
return new MonoDevelop.Ide.FindInFiles.SearchResult (provider, position, part.Name.Length);
}
protected override void Run (object data)
{
var doc = IdeApp.Workbench.ActiveDocument;
if (doc == null || doc.FileName == FilePath.Null)
return;
Run (doc);
}
public static void Run (MonoDevelop.Ide.Gui.Document doc)
{
GoToDefinitionService.TryGoToDefinition (doc.AnalysisDocument, doc.Editor.CaretOffset, default(CancellationToken));
}
public static void JumpToDeclaration (MonoDevelop.Ide.Gui.Document doc, RefactoringSymbolInfo info)
{
if (info.Symbol != null)
IdeApp.ProjectOperations.JumpToDeclaration (info.Symbol, doc.Project);
if (info.CandidateSymbols.Length > 0)
IdeApp.ProjectOperations.JumpToDeclaration (info.CandidateSymbols[0], doc.Project);
}
}
}
|