Skip to content

Commit 043e08f

Browse files
committed
reset
1 parent b718b4f commit 043e08f

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

.vscode/launch.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@
149149
"--ui=tdd",
150150
"--recursive",
151151
"--colors",
152-
//"--grep", "<suite name>",
152+
"--grep",
153+
"ProcessLogger suite",
153154
"--timeout=300000"
154155
],
155156
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
156157
"preLaunchTask": "Compile",
157-
"skipFiles": ["<node_internals>/**"]
158+
"skipFiles": ["<node_internals>/**"],
159+
"runtimeExecutable": "/Users/eleanorboyd/.nvm/versions/node/v22.17.0/bin/node"
158160
},
159161
{
160162
"name": "Unit Tests (fast, without VS Code and without react/monaco, *.unit.test.ts)",

src/client/common/process/logger.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export class ProcessLogger implements IProcessLogger {
2727
let command = args
2828
? [fileOrCommand, ...args].map((e) => e.trimQuotes().toCommandArgumentForPythonExt()).join(' ')
2929
: fileOrCommand;
30-
const info = [`> ${this.getDisplayCommands(command, false)}`];
30+
const info = [`> ${this.getDisplayCommands(command)}`];
3131
if (options?.cwd) {
3232
const cwd: string = typeof options?.cwd === 'string' ? options?.cwd : options?.cwd?.toString();
33-
info.push(`cwd: ${this.getDisplayCommands(cwd, true)}`);
33+
info.push(`cwd: ${this.getDisplayCommands(cwd)}`);
3434
}
3535
if (typeof options?.shell === 'string') {
3636
info.push(`shell: ${identifyShellFromShellPath(options?.shell)}`);
@@ -41,16 +41,16 @@ export class ProcessLogger implements IProcessLogger {
4141
});
4242
}
4343

44-
private getDisplayCommands(command: string, isCwd: boolean = false): string {
44+
/**
45+
* Formats command strings for display by replacing common paths with symbols.
46+
* - Replaces the workspace folder path with '.' if there's exactly one workspace folder
47+
* - Replaces the user's home directory path with '~'
48+
* @param command The command string to format
49+
* @returns The formatted command string with paths replaced by symbols
50+
*/
51+
private getDisplayCommands(command: string): string {
4552
if (this.workspaceService.workspaceFolders && this.workspaceService.workspaceFolders.length === 1) {
46-
const workspacePath = this.workspaceService.workspaceFolders[0].uri.fsPath;
47-
if (isCwd) {
48-
// For working directory paths, replace workspace path with '.'
49-
command = replaceMatchesWithCharacter(command, workspacePath, '.');
50-
} else if (command.includes(workspacePath)) {
51-
// For command paths, make them relative to workspace by replacing workspace path with './'
52-
command = command.replace(workspacePath, '.');
53-
}
53+
command = replaceMatchesWithCharacter(command, this.workspaceService.workspaceFolders[0].uri.fsPath, '.');
5454
}
5555
const home = getUserHomeDir();
5656
if (home) {

src/test/common/process/logger.unit.test.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ suite('ProcessLogger suite', () => {
111111
const options = { cwd: path.join('debug', 'path') };
112112
logger.logProcess(path.join('net', untildify('~'), 'test'), ['--foo', '--bar'], options);
113113

114-
sinon.assert.calledWithExactly(traceLogStub, `> ${path.join('.', 'net', '~', 'test')} --foo --bar`);
114+
sinon.assert.calledWithExactly(traceLogStub, `> ${path.join('net', '~', 'test')} --foo --bar`);
115115
sinon.assert.calledWithExactly(traceLogStub, `cwd: ${options.cwd}`);
116116
});
117117

@@ -125,7 +125,7 @@ suite('ProcessLogger suite', () => {
125125

126126
sinon.assert.calledWithExactly(
127127
traceLogStub,
128-
`> ${path.join('.', 'net', '~', 'test')} --foo ${path.join('~', 'boo')}`,
128+
`> ${path.join('net', '~', 'test')} --foo ${path.join('~', 'boo')}`,
129129
);
130130
sinon.assert.calledWithExactly(traceLogStub, `cwd: ${options.cwd}`);
131131
});
@@ -134,7 +134,7 @@ suite('ProcessLogger suite', () => {
134134
const options = { cwd: path.join('debug', 'path') };
135135
logger.logProcess(`"${path.join('net', untildify('~'), 'test')}" "--foo" "--bar"`, undefined, options);
136136

137-
sinon.assert.calledWithExactly(traceLogStub, `> "${path.join('.', 'net', '~', 'test')}" "--foo" "--bar"`);
137+
sinon.assert.calledWithExactly(traceLogStub, `> "${path.join('net', '~', 'test')}" "--foo" "--bar"`);
138138
sinon.assert.calledWithExactly(traceLogStub, `cwd: ${options.cwd}`);
139139
});
140140

@@ -146,39 +146,30 @@ suite('ProcessLogger suite', () => {
146146
sinon.assert.calledWithExactly(traceLogStub, `cwd: ${options.cwd}`);
147147
});
148148

149-
test('Logger only replaces the workspace path with . in the working directory', async () => {
149+
test('Logger replaces the path to workspace with . if exactly one workspace folder is opened', async () => {
150150
const options = { cwd: path.join('path', 'to', 'workspace', 'debug', 'path') };
151151
logger.logProcess(`"${path.join('path', 'to', 'workspace', 'test')}" "--foo" "--bar"`, undefined, options);
152152

153-
sinon.assert.calledWithExactly(
154-
traceLogStub,
155-
`> "${path.join('path', 'to', 'workspace', 'test')}" "--foo" "--bar"`,
156-
);
153+
sinon.assert.calledWithExactly(traceLogStub, `> ".${path.sep}test" "--foo" "--bar"`);
157154
sinon.assert.calledWithExactly(traceLogStub, `cwd: .${path.sep + path.join('debug', 'path')}`);
158155
});
159156

160-
test('On Windows, logger handles both forward and backward slashes in workspace paths for cwd', async function () {
157+
test('On Windows, logger replaces both backwards and forward slash version of path to workspace with . if exactly one workspace folder is opened', async function () {
161158
if (getOSType() !== OSType.Windows) {
162159
return this.skip();
163160
}
164161
let options = { cwd: path.join('path/to/workspace', 'debug', 'path') };
165162

166163
logger.logProcess(`"${path.join('path', 'to', 'workspace', 'test')}" "--foo" "--bar"`, undefined, options);
167164

168-
sinon.assert.calledWithExactly(
169-
traceLogStub,
170-
`> "${path.join('path', 'to', 'workspace', 'test')}" "--foo" "--bar"`,
171-
);
165+
sinon.assert.calledWithExactly(traceLogStub, `> ".${path.sep}test" "--foo" "--bar"`);
172166
sinon.assert.calledWithExactly(traceLogStub, `cwd: .${path.sep + path.join('debug', 'path')}`);
173167
traceLogStub.resetHistory();
174168

175169
options = { cwd: path.join('path\\to\\workspace', 'debug', 'path') };
176170
logger.logProcess(`"${path.join('path', 'to', 'workspace', 'test')}" "--foo" "--bar"`, undefined, options);
177171

178-
sinon.assert.calledWithExactly(
179-
traceLogStub,
180-
`> "${path.join('path', 'to', 'workspace', 'test')}" "--foo" "--bar"`,
181-
);
172+
sinon.assert.calledWithExactly(traceLogStub, `> ".${path.sep}test" "--foo" "--bar"`);
182173
sinon.assert.calledWithExactly(traceLogStub, `cwd: .${path.sep + path.join('debug', 'path')}`);
183174
});
184175

0 commit comments

Comments
 (0)