Skip to content
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

workspace: normalize paths of workspace roots #7598

Merged
merged 1 commit into from
Apr 24, 2020

Conversation

corneliusludmann
Copy link
Contributor

What it does

This is my proposal to fix #7597 .

If you have configured a workspace folder like

"path": "../../workspace"

you get a Terminal for URI /workspace/theia/../../workspace instead of /workspace. This commit fixes this by using a normalized path in the terminal cwd selector.

An alternative would be to fix the roots in the workspace service directly so that it benefits everywhere.

How to test

see #7597

Review checklist

Reminder for reviewers

@akosyakov akosyakov added multi-root issues related to multi-root support terminal issues related to the terminal labels Apr 17, 2020
@vince-fugnitto
Copy link
Member

@corneliusludmann thank you, I hadn't thought of the use case when I initially authored the changes. Would the suggestion you had of updating the WorkspaceService be better which would likely fix other similar issues?

@akosyakov
Copy link
Member

@vince-fugnitto Do you mean that we normalize all root URIs in WorkspaceService? It sounds even better.

@akosyakov akosyakov added the workspace issues related to the workspace label Apr 17, 2020
@vince-fugnitto
Copy link
Member

@vince-fugnitto Do you mean that we normalize all root URIs in WorkspaceService? It sounds even better.

Yes exactly, it is what @corneliusludmann mentioned in his pull-request description:

An alternative would be to fix the roots in the workspace service directly so that it benefits everywhere.

@akosyakov
Copy link
Member

@corneliusludmann Can you do alternative solution? It sounds great.

@corneliusludmann
Copy link
Contributor Author

Sure. I'll do this.

@corneliusludmann
Copy link
Contributor Author

I'm not sure which is the best place to put this. The call chain is:

Is normalizing the path in toFileStat() too aggressive? I think it fits very well in this method. However, it is called from 4 other places in workspace-service.ts. I think, they all benefit form this change but if you afraid of side effects I would add this to toValidRoot() instead. WDYT @akosyakov?

/**
* returns a FileStat if the argument URI points to a file or directory. Otherwise, `undefined`.
*/
protected async toFileStat(uri: URI | string | undefined): Promise<FileStat | undefined> {
if (!uri) {
return undefined;
}
let uriStr = uri.toString();
try {
if (uriStr.endsWith('/')) {
uriStr = uriStr.slice(0, -1);
}
const fileStat = await this.fileSystem.getFileStat(uriStr);
if (!fileStat) {
return undefined;
}
return fileStat;
} catch (error) {
return undefined;
}
}

@akosyakov
Copy link
Member

It seems to be fine. @vince-fugnitto Could you verify it please?

@vince-fugnitto
Copy link
Member

It seems to be fine. @vince-fugnitto Could you verify it please?

Sure, I'll test it!
@corneliusludmann would you mind adding tests to the workspace-service to verify if we now correctly handle normalizing? If not I can definitely do so :)

@corneliusludmann do you mind updating the workspace-service tests for toFileStat to verify if we are correctly normalizing uris?

This avoids having workspace roots like /workspace/../../workspace when having relative paths in the workspace roots configuration.

Fixes eclipse-theia#7597

Signed-off-by: Cornelius A. Ludmann <cornelius.ludmann@typefox.io>
@corneliusludmann
Copy link
Contributor Author

@vince-fugnitto I updated the PR with a test. I hope that's of some use. Feel free to modify or to propose changes.

@vince-fugnitto vince-fugnitto changed the title Use normalized URI in Terminal CWD selector workspace: normalize paths of workspace roots Apr 23, 2020
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

I tested the changes (terminal in multi-root) and it works correctly!
Thank you for taking care of the pull-request and also including a test case :)

@akosyakov akosyakov merged commit 669ad8b into eclipse-theia:master Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multi-root issues related to multi-root support terminal issues related to the terminal workspace issues related to the workspace
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[multi-root] Relative paths in multi-root setting are not resolved when opening a Terminal
3 participants