Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 69b01ec

Browse files
sandyarmstrongmonojenkins
authored andcommitted
Revert "Implement Go To Definition for Razor"
This reverts commit d0ec479. It broke some normal usage of Go To Definition for C# files.
1 parent 087685f commit 69b01ec

File tree

3 files changed

+12
-69
lines changed

3 files changed

+12
-69
lines changed

main/src/addins/CSharpBinding/MonoDevelop.Ide.Completion.Presentation/MonoDevelopContainedDocument.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public class MonoDevelopContainedDocument : IMonoDevelopHostDocument
5454
public IMonoDevelopContainedLanguageHost ContainedLanguageHost { get; private set; }
5555
private readonly HostType _hostType;
5656

57-
public IProjectionBuffer TopBuffer => DataBuffer;
58-
5957
// _workspace will only be set once the Workspace is available
6058
private Workspace _workspace;
6159

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.RoslynServices/MonoDevelopDocumentNavigationService.cs

Lines changed: 12 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Composition;
3-
using System.Linq;
43
using System.Threading;
54
using System.Threading.Tasks;
65
using Microsoft.CodeAnalysis;
@@ -10,10 +9,7 @@
109
using Microsoft.CodeAnalysis.Options;
1110
using Microsoft.CodeAnalysis.Text;
1211
using Microsoft.VisualStudio.Text;
13-
using Microsoft.VisualStudio.Text.Projection;
1412
using MonoDevelop.Core;
15-
using MonoDevelop.Ide.Composition;
16-
using MonoDevelop.Ide.Editor.Projection;
1713
using MonoDevelop.Ide.TypeSystem;
1814

1915
namespace MonoDevelop.Ide.RoslynServices
@@ -23,14 +19,11 @@ internal sealed class VisualStudioDocumentNavigationServiceFactory : IWorkspaceS
2319
{
2420
private readonly IDocumentNavigationService _singleton;
2521

26-
[Import]
27-
public IBufferGraphFactoryService BufferGraphFactoryService { get; set; }
28-
2922
[ImportingConstructor]
3023
[Obsolete (MefConstruction.ImportingConstructorMessage, error: true)]
3124
private VisualStudioDocumentNavigationServiceFactory ()
3225
{
33-
_singleton = new MonoDevelopDocumentNavigationService (this);
26+
_singleton = new MonoDevelopDocumentNavigationService ();
3427
}
3528

3629
public IWorkspaceService CreateService (HostWorkspaceServices workspaceServices)
@@ -41,13 +34,6 @@ public IWorkspaceService CreateService (HostWorkspaceServices workspaceServices)
4134

4235
class MonoDevelopDocumentNavigationService : IDocumentNavigationService
4336
{
44-
private VisualStudioDocumentNavigationServiceFactory factory;
45-
46-
public MonoDevelopDocumentNavigationService (VisualStudioDocumentNavigationServiceFactory visualStudioDocumentNavigationServiceFactory)
47-
{
48-
this.factory = visualStudioDocumentNavigationServiceFactory;
49-
}
50-
5137
public bool CanNavigateToSpan (Workspace workspace, DocumentId documentId, TextSpan textSpan)
5238
{
5339
// Navigation should not change the context of linked files and Shared Projects.
@@ -113,7 +99,7 @@ public bool TryNavigateToSpan (Workspace workspace, DocumentId documentId, TextS
11399

114100
Runtime.AssertMainThread ();
115101

116-
var document = workspace.CurrentSolution.GetDocument (documentId);
102+
var document = OpenDocument (workspace, documentId, options);
117103
if (document == null) {
118104
return false;
119105
}
@@ -141,7 +127,7 @@ public bool TryNavigateToLineAndOffset (Workspace workspace, DocumentId document
141127

142128
Runtime.AssertMainThread ();
143129

144-
var document = workspace.CurrentSolution.GetDocument (documentId);
130+
var document = OpenDocument (workspace, documentId, options);
145131
if (document == null) {
146132
return false;
147133
}
@@ -163,7 +149,7 @@ public bool TryNavigateToPosition (Workspace workspace, DocumentId documentId, i
163149

164150
Runtime.AssertMainThread ();
165151

166-
var document = workspace.CurrentSolution.GetDocument (documentId);
152+
var document = OpenDocument (workspace, documentId, options);
167153
if (document == null) {
168154
return false;
169155
}
@@ -236,41 +222,13 @@ private static Document OpenDocument (Workspace workspace, DocumentId documentId
236222

237223
private bool NavigateTo (Document document, TextSpan span)
238224
{
239-
string filePath = document.FilePath;
240-
filePath = GetActualFilePathToOpen (filePath);
241225
var proj = (document.Project.Solution.Workspace as MonoDevelopWorkspace)?.GetMonoProject (document.Project);
242-
var task = IdeApp.Workbench.OpenDocument (new Gui.FileOpenInformation (filePath, proj) {
226+
var task = IdeApp.Workbench.OpenDocument (new Gui.FileOpenInformation (document.FilePath, proj) {
243227
Offset = span.Start
244228
});
245229
return true;
246230
}
247231

248-
/// <summary>
249-
/// Razor: Strip the .g.cs since we want to open the corresponding .cshtml or .razor document.
250-
///
251-
/// In Visual Studio for Windows the underlying C# buffer is added to the workspace with the
252-
/// .cshtml or .razor extension (without the .g.cs) part, so they don't have to worry about
253-
/// this. In our case we have an assumption somewhere that all C# documents in the workspace
254-
/// have the .cs extension, so we're adding the .g.cs part that we need to strip here.
255-
///
256-
/// This is not great to hardcode application-specific logic here, but we don't anticipate
257-
/// more scenarios where we want to open a different file than requested, so it doesn't
258-
/// warrant an extension point at this time.
259-
/// </summary>
260-
string GetActualFilePathToOpen (string filePath)
261-
{
262-
if (filePath == null) {
263-
return null;
264-
}
265-
266-
if (filePath.EndsWith (".cshtml.g.cs", StringComparison.OrdinalIgnoreCase) ||
267-
filePath.EndsWith (".razor.g.cs", StringComparison.OrdinalIgnoreCase)) {
268-
filePath = filePath.Substring (0, filePath.Length - ".g.cs".Length);
269-
}
270-
271-
return filePath;
272-
}
273-
274232
private bool IsSecondaryBuffer (Workspace workspace, Document document)
275233
{
276234
var containedDocument = MonoDevelopHostDocumentRegistration.FromDocument (document);
@@ -281,33 +239,23 @@ private bool IsSecondaryBuffer (Workspace workspace, Document document)
281239
return true;
282240
}
283241

284-
public bool TryMapSpanFromSecondaryBufferToPrimaryBuffer (TextSpan spanInSecondaryBuffer, Microsoft.CodeAnalysis.Workspace workspace, Document document, out TextSpan spanInPrimaryBuffer)
242+
public static bool TryMapSpanFromSecondaryBufferToPrimaryBuffer (TextSpan spanInSecondaryBuffer, Microsoft.CodeAnalysis.Workspace workspace, Document document, out TextSpan spanInPrimaryBuffer)
285243
{
286244
spanInPrimaryBuffer = default;
287245

288246
var containedDocument = MonoDevelopHostDocumentRegistration.FromDocument (document);
289247
if (containedDocument == null) {
290248
return false;
291249
}
250+
throw new NotImplementedException ();
251+
//var bufferCoordinator = containedDocument.BufferCoordinator;
292252

293-
var projectionBuffer = containedDocument.TopBuffer;
294-
295-
var bufferGraph = factory.BufferGraphFactoryService.CreateBufferGraph (projectionBuffer);
253+
//var primary = new VsTextSpan [1];
254+
//var hresult = bufferCoordinator.MapSecondaryToPrimarySpan (spanInSecondaryBuffer, primary);
296255

297-
if (document.TryGetText(out var sourceText) && sourceText.Container.TryGetTextBuffer() is ITextBuffer languageBuffer) {
298-
var secondarySnapshot = languageBuffer.CurrentSnapshot;
299-
var snapshotSpanInSecondaryBuffer = new SnapshotSpan (secondarySnapshot, new Span (spanInSecondaryBuffer.Start, spanInSecondaryBuffer.Length));
300-
var topBufferSnapshotSpan = bufferGraph.MapUpToSnapshot (
301-
snapshotSpanInSecondaryBuffer,
302-
SpanTrackingMode.EdgeExclusive,
303-
projectionBuffer.CurrentSnapshot).FirstOrDefault();
304-
if (topBufferSnapshotSpan != default) {
305-
spanInPrimaryBuffer = new TextSpan (topBufferSnapshotSpan.Start, topBufferSnapshotSpan.Length);
306-
return true;
307-
}
308-
}
256+
//spanInPrimaryBuffer = primary [0];
309257

310-
return false;
258+
//return ErrorHandler.Succeeded (hresult);
311259
}
312260

313261
private bool CanMapFromSecondaryBufferToPrimaryBuffer (Workspace workspace, Document document, TextSpan spanInSecondaryBuffer)

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/IMonoDevelopHostDocument.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Microsoft.CodeAnalysis;
77
using Microsoft.CodeAnalysis.Text;
88
using Microsoft.VisualStudio.Text;
9-
using Microsoft.VisualStudio.Text.Projection;
109

1110
namespace MonoDevelop.Ide.TypeSystem
1211
{
@@ -16,8 +15,6 @@ interface IMonoDevelopHostDocument
1615
/// Updates the text of the document.
1716
/// </summary>
1817
void UpdateText (SourceText newText);
19-
20-
IProjectionBuffer TopBuffer { get; }
2118
}
2219

2320
static class MonoDevelopHostDocumentRegistration

0 commit comments

Comments
 (0)