public async Task <Uri> GetProjectPathAsync(Uri documentFilePath, CancellationToken cancellationToken) { if (documentFilePath == null) { throw new ArgumentNullException(nameof(documentFilePath)); } _foregroundDispatcher.AssertBackgroundThread(); await _joinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); if (_openDocumentShell == null) { _openDocumentShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; } var hostDocumentFilePath = _session.ConvertSharedUriToLocalPath(documentFilePath); var hr = _openDocumentShell.IsDocumentInAProject(hostDocumentFilePath, out var hierarchy, out _, out _, out _); if (ErrorHandler.Succeeded(hr) && hierarchy != null) { ErrorHandler.ThrowOnFailure(((IVsProject)hierarchy).GetMkDocument((uint)VSConstants.VSITEMID.Root, out var path), VSConstants.E_NOTIMPL); return(_session.ConvertLocalPathToSharedUri(path)); } return(null); }
private ProjectSnapshotHandleProxy ConvertToProxy(ProjectSnapshot project) { var projectWorkspaceState = new ProjectWorkspaceState(project.TagHelpers); var projectFilePath = _session.ConvertLocalPathToSharedUri(project.FilePath); var projectHandleProxy = new ProjectSnapshotHandleProxy(projectFilePath, project.Configuration, project.RootNamespace, projectWorkspaceState); return(projectHandleProxy); }
/// <inheritdoc /> public override void OpenDocument(DocumentId documentId, bool activate = true) { var doc = CurrentSolution.GetDocument(documentId); if (doc != null) { var svc = _serviceProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; Report.IfNotPresent(svc); if (svc == null) { return; } _threadingContext.JoinableTaskFactory.Run(async() => { await _session.DownloadFileAsync(_session.ConvertLocalPathToSharedUri(doc.FilePath), CancellationToken.None).ConfigureAwait(true); }); Guid logicalView = Guid.Empty; if (ErrorHandler.Succeeded(svc.OpenDocumentViaProject(doc.FilePath, ref logicalView, out var sp, out IVsUIHierarchy hier, out uint itemid, out IVsWindowFrame frame)) && frame != null) { if (activate) { frame.Show(); } else { frame.ShowNoActivate(); } if (_runningDocumentTableEventTracker.IsFileOpen(doc.FilePath) && _runningDocumentTableEventTracker.TryGetBufferFromMoniker(doc.FilePath, out var buffer)) { var hierarchy = _runningDocumentTableEventTracker.GetDocumentHierarchy(doc.FilePath); NotifyOnDocumentOpened(doc.FilePath, buffer, hierarchy); } } } }