11using System ;
22using System . Composition ;
3- using System . Linq ;
43using System . Threading ;
54using System . Threading . Tasks ;
65using Microsoft . CodeAnalysis ;
109using Microsoft . CodeAnalysis . Options ;
1110using Microsoft . CodeAnalysis . Text ;
1211using Microsoft . VisualStudio . Text ;
13- using Microsoft . VisualStudio . Text . Projection ;
1412using MonoDevelop . Core ;
15- using MonoDevelop . Ide . Composition ;
16- using MonoDevelop . Ide . Editor . Projection ;
1713using MonoDevelop . Ide . TypeSystem ;
1814
1915namespace 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 )
0 commit comments