private static async Task <(ImmutableHashSet <string> remoteRootPaths, ImmutableHashSet <string> externalPaths)> GetLocalPathsOfRemoteRootsAsync(CollaborationSession session) { var roots = await session.ListRootsAsync(CancellationToken.None).ConfigureAwait(false); var localPathsOfRemoteRoots = roots.Select(root => session.ConvertSharedUriToLocalPath(root)).ToImmutableArray(); var remoteRootPaths = ImmutableHashSet.CreateBuilder <string>(); var externalPaths = ImmutableHashSet.CreateBuilder <string>(); foreach (var localRoot in localPathsOfRemoteRoots) { // The local root is something like tmp\\xxx\\<workspace name> // The external root should be tmp\\xxx\\~external, so replace the workspace name with ~external. #pragma warning disable CS8602 // Dereference of a possibly null reference. (Can localRoot be null here?) var splitRoot = localRoot.TrimEnd('\\').Split('\\'); #pragma warning restore CS8602 // Dereference of a possibly null reference. splitRoot[splitRoot.Length - 1] = "~external"; var externalPath = string.Join("\\", splitRoot) + "\\"; remoteRootPaths.Add(localRoot); externalPaths.Add(externalPath); } return(remoteRootPaths.ToImmutable(), externalPaths.ToImmutable()); }
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); }
public async Task <bool> HasCapabilityAsync(Uri pathOfFileInProject, string capability, CancellationToken cancellationToken) { if (capability is null) { throw new ArgumentNullException(nameof(capability)); } if (pathOfFileInProject is null) { throw new ArgumentNullException(nameof(pathOfFileInProject)); } await _joinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var hostPathOfFileInProject = _session.ConvertSharedUriToLocalPath(pathOfFileInProject); var vsUIShellOpenDocument = ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (vsUIShellOpenDocument == null) { return(false); } var hr = vsUIShellOpenDocument.IsDocumentInAProject(hostPathOfFileInProject, out var hierarchy, out _, out _, out _); if (!ErrorHandler.Succeeded(hr) || hierarchy == null) { return(false); } try { var isCapabilityMatch = hierarchy.IsCapabilityMatch(capability); return(isCapabilityMatch); } catch (NotSupportedException) { // IsCapabilityMatch throws a NotSupportedException if it can't create a // BooleanSymbolExpressionEvaluator COM object } catch (ObjectDisposedException) { // IsCapabilityMatch throws an ObjectDisposedException if the underlying // hierarchy has been disposed (Bug 253462) } return(false); }
public async Task SetSession(CollaborationSession session) { _session = session; var roots = await session.ListRootsAsync(CancellationToken.None).ConfigureAwait(false); _remoteRootPath = session.ConvertSharedUriToLocalPath(roots[0]); _remoteRootPath = _remoteRootPath.Substring(0, _remoteRootPath.Length - 1); var lastSlash = _remoteRootPath.LastIndexOf('\\'); _externalPath = _remoteRootPath.Substring(0, lastSlash + 1); _externalPath += "~external"; IsRemoteSession = true; session.RemoteServicesChanged += (object sender, RemoteServicesChangedEventArgs e) => { _remoteDiagnosticListTable.UpdateWorkspaceDiagnosticsPresent(_session.RemoteServiceNames.Contains("workspaceDiagnostics")); }; }
private string ResolveGuestPath(Uri filePath) { return(_sessionContext.ConvertSharedUriToLocalPath(filePath)); }