Skip to content

WIP: Support multi-root workspace #1992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/PowerShellEditorServices/Extensions/FileContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public sealed class FileContext
/// <summary>
/// Gets the workspace-relative path of the file.
/// </summary>
public string WorkspacePath => editorOperations.GetWorkspaceRelativePath(
scriptFile.FilePath);
public string WorkspacePath => editorOperations.GetWorkspaceRelativePath(scriptFile);

#endregion

Expand Down
3 changes: 1 addition & 2 deletions src/PowerShellEditorServices/Extensions/IEditorOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ internal interface IEditorOperations
/// <summary>
/// Resolves the given file path relative to the current workspace path.
/// </summary>
/// <param name="filePath">The file path to be resolved.</param>
/// <returns>The resolved file path.</returns>
string GetWorkspaceRelativePath(string filePath);
string GetWorkspaceRelativePath(ScriptFile scriptFile);

/// <summary>
/// Causes a new untitled file to be created in the editor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public async Task SaveFileAsync(string currentPath, string newSavePath)
// workspace it's in.
public string GetWorkspacePath() => _workspaceService.InitialWorkingDirectory;

public string GetWorkspaceRelativePath(string filePath) => _workspaceService.GetRelativePath(filePath);
public string GetWorkspaceRelativePath(ScriptFile scriptFile) => _workspaceService.GetRelativePath(scriptFile);

public async Task ShowInformationMessageAsync(string message)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,23 @@ public void CloseFile(ScriptFile scriptFile)
/// <summary>
/// Gets the workspace-relative path of the given file path.
/// </summary>
/// <param name="filePath">The original full file path.</param>
/// <returns>A relative file path</returns>
public string GetRelativePath(string filePath)
public string GetRelativePath(ScriptFile scriptFile)
{
string resolvedPath = filePath;
string resolvedPath = scriptFile.FilePath;

if (!IsPathInMemory(filePath) && !string.IsNullOrEmpty(InitialWorkingDirectory))
if (!scriptFile.IsInMemory)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think IsPathInMemory can go away because it's only used in two tests now, and IsInMemory is used everywhere else. Not sure why we had two ways to go about that.

{
Uri workspaceUri = new(InitialWorkingDirectory);
Uri fileUri = new(filePath);

resolvedPath = workspaceUri.MakeRelativeUri(fileUri).ToString();
Uri fileUri = scriptFile.DocumentUri.ToUri();
foreach (WorkspaceFolder workspaceFolder in WorkspaceFolders)
{
Uri workspaceUri = workspaceFolder.Uri.ToUri();
if (workspaceUri.IsBaseOf(fileUri))
{
resolvedPath = workspaceUri.MakeRelativeUri(fileUri).ToString();
break;
}
Comment on lines +320 to +324
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this works 😅

}

// Convert the directory separators if necessary
if (Path.DirectorySeparatorChar == '\\')
Expand Down