Skip to content

Commit

Permalink
remote paths - deprecate resolvedUserHome
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jun 22, 2020
1 parent 7f132c9 commit d437711
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
26 changes: 13 additions & 13 deletions src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class SessionTreeItem extends BaseTreeItem {
return 999;
}

addPath(source: Source): void {
async addPath(source: Source): Promise<void> {

let folder: IWorkspaceFolder | null;
let url: string;
Expand Down Expand Up @@ -347,9 +347,8 @@ class SessionTreeItem extends BaseTreeItem {
} else {
// on unix try to tildify absolute paths
path = normalize(path);
const userHome = this._pathService.resolvedUserHome;
if (userHome && !isWindows) {
path = tildify(path, userHome.fsPath);
if (!isWindows) {
path = tildify(path, (await this._pathService.userHome).fsPath);
}
}
}
Expand Down Expand Up @@ -518,27 +517,28 @@ export class LoadedScriptsView extends ViewPane {
}
};

const addSourcePathsToSession = (session: IDebugSession) => {
const addSourcePathsToSession = async (session: IDebugSession) => {
const sessionNode = root.add(session);
return session.getLoadedSources().then(paths => {
paths.forEach(path => sessionNode.addPath(path));
scheduleRefreshOnVisible();
});
const paths = await session.getLoadedSources();
for (const path of paths) {
await sessionNode.addPath(path);
}
scheduleRefreshOnVisible();
};

const registerSessionListeners = (session: IDebugSession) => {
this._register(session.onDidChangeName(() => {
this._register(session.onDidChangeName(async () => {
// Re-add session, this will trigger proper sorting and id recalculation.
root.remove(session.getId());
addSourcePathsToSession(session);
await addSourcePathsToSession(session);
}));
this._register(session.onDidLoadedSource(event => {
this._register(session.onDidLoadedSource(async event => {
let sessionRoot: SessionTreeItem;
switch (event.reason) {
case 'new':
case 'changed':
sessionRoot = root.add(session);
sessionRoot.addPath(event.source);
await sessionRoot.addPath(event.source);
scheduleRefreshOnVisible();
if (event.reason === 'changed') {
DebugContentProvider.refreshDebugContent(event.source.uri);
Expand Down
29 changes: 19 additions & 10 deletions src/vs/workbench/services/path/common/pathService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export interface IPathService {
readonly userHome: Promise<URI>;

/**
* Access to `userHome` in a sync fashion. This may be `undefined`
* as long as the remote environment was not resolved.
* @deprecated use `userHome` instead.
*/
readonly resolvedUserHome: URI | undefined;
}
Expand All @@ -55,22 +54,31 @@ export abstract class AbstractPathService implements IPathService {

declare readonly _serviceBrand: undefined;

private remoteOS: Promise<OperatingSystem>;
private resolveOS: Promise<OperatingSystem>;

private resolveUserHome: Promise<URI>;
private maybeUnresolvedUserHome: URI | undefined;

constructor(
fallbackUserHome: URI,
localUserHome: URI,
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService
) {
this.remoteOS = this.remoteAgentService.getEnvironment().then(env => env?.os || OS);

this.resolveUserHome = this.remoteAgentService.getEnvironment().then(env => {
const userHome = this.maybeUnresolvedUserHome = env?.userHome || fallbackUserHome;
// OS
this.resolveOS = (async () => {
const env = await this.remoteAgentService.getEnvironment();

return env?.os || OS;
})();

// User Home
this.resolveUserHome = (async () => {
const env = await this.remoteAgentService.getEnvironment();
const userHome = this.maybeUnresolvedUserHome = env?.userHome || localUserHome;


return userHome;
});
})();
}

get userHome(): Promise<URI> {
Expand All @@ -82,7 +90,7 @@ export abstract class AbstractPathService implements IPathService {
}

get path(): Promise<IPath> {
return this.remoteOS.then(os => {
return this.resolveOS.then(os => {
return os === OperatingSystem.Windows ?
win32 :
posix;
Expand All @@ -95,7 +103,8 @@ export abstract class AbstractPathService implements IPathService {
// normalize to fwd-slashes on windows,
// on other systems bwd-slashes are valid
// filename character, eg /f\oo/ba\r.txt
if ((await this.remoteOS) === OperatingSystem.Windows) {
const os = await this.resolveOS;
if (os === OperatingSystem.Windows) {
_path = _path.replace(/\\/g, '/');
}

Expand Down

0 comments on commit d437711

Please sign in to comment.