Skip to content

Commit

Permalink
Merge pull request dotnet#39448 from daytonellwanger/dev/dayton/NoRoot
Browse files Browse the repository at this point in the history
Live Share - Support Empty Workspace
  • Loading branch information
dibarbet authored Oct 29, 2019
2 parents 1df6922 + 206906b commit 916e492
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ 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";
if (roots.Length > 0)
{
_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) =>
{
Expand Down Expand Up @@ -175,8 +178,9 @@ public void NotifyOnDocumentOpened(string moniker, ITextBuffer textBuffer, IVsHi

private bool IsExternalLocalUri(string localPath)
{
return localPath.StartsWith(_externalPath) &&
localPath.Length > (_externalPath.Length + 1);
return _externalPath == null
? false
: localPath.StartsWith(_externalPath) && localPath.Length > (_externalPath.Length + 1);
}

public Document GetOrAddDocument(string filePath)
Expand All @@ -192,10 +196,15 @@ public Document GetOrAddDocument(string filePath)
return null;
}

if (_remoteRootPath == null)
{
return null;
}

// If the document is within the joined folder or it's a registered external file,
// add it to the workspace, otherwise bail out.
if (!filePath.StartsWith(_remoteRootPath) &&
!IsExternalLocalUri(filePath))
!IsExternalLocalUri(filePath))
{
return null;
}
Expand Down

0 comments on commit 916e492

Please sign in to comment.