Skip to content

Commit 86a9c3d

Browse files
authored
feat(vscode): remove unnecessary logger code (#685)
1 parent 8fd0c06 commit 86a9c3d

File tree

7 files changed

+20
-108
lines changed

7 files changed

+20
-108
lines changed

packages/vscode/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ The extension activates automatically when your workspace contains Rstest config
1515

1616
## Configuration
1717

18-
| Setting | Type | Default | Description |
19-
| ---------------------------- | -------- | -------------------------------- | ------------------------------------------------------------------------------- |
20-
| `rstest.testFileGlobPattern` | string[] | `["**/*.test.*", "**/*.spec.*"]` | Glob pattern(s) used to discover test files in the workspace. |
21-
| `rstest.logLevel` | string | `default` | Controls Output channel verbosity; set to `debug` for extra diagnostic logging. |
18+
| Setting | Type | Default | Description |
19+
| ---------------------------- | -------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20+
| `rstest.testFileGlobPattern` | string[] | `["**/*.test.*", "**/*.spec.*"]` | Glob pattern(s) used to discover test files in the workspace. |
21+
| `rstest.rstestPackagePath` | string | `undefined` | The path to a `package.json` file of a Rstest executable (it's usually inside `node_modules`) in case the extension cannot find it. It will be used to resolve Rstest API paths. This should be used as a last resort fix. Supports `${workspaceFolder}` placeholder. |
2222

2323
## How it works
2424

packages/vscode/package.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@
3939
"**/*.spec.*"
4040
]
4141
},
42-
"rstest.logLevel": {
43-
"markdownDescription": "Controls how much diagnostic output the Rstest extension emits to the Output view.",
44-
"scope": "window",
45-
"type": "string",
46-
"enum": [
47-
"default",
48-
"debug"
49-
],
50-
"default": "default"
51-
},
5242
"rstest.rstestPackagePath": {
5343
"markdownDescription": "The path to a `package.json` file of a Rstest executable (it's usually inside `node_modules`) in case the extension cannot find it. It will be used to resolve Rstest API paths. This should be used as a last resort fix. Supports `${workspaceFolder}` placeholder.",
5444
"scope": "resource",

packages/vscode/src/config.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
import vscode from 'vscode';
22

3-
export type LogLevel = 'default' | 'debug';
4-
53
// Centralized configuration types for the extension.
64
// Add new keys here to extend configuration in a type-safe way.
75
export type ExtensionConfig = {
86
// Glob patterns that determine which files are considered tests.
97
// Must be an array of strings.
108
testFileGlobPattern: string[];
11-
// Controls verbosity of extension logging routed to the Output channel.
12-
logLevel: LogLevel;
139
// The path to a package.json file of a Rstest executable.
1410
// Used as a last resort if the extension cannot auto-detect @rstest/core.
1511
rstestPackagePath?: string;
1612
};
1713

1814
export const defaultConfig: ExtensionConfig = {
1915
testFileGlobPattern: ['**/*.test.*', '**/*.spec.*'],
20-
logLevel: 'default',
2116
};
2217

2318
// Type-safe getter for a single config value with priority:
@@ -42,11 +37,6 @@ export function getConfigValue<K extends keyof ExtensionConfig>(
4237
return (isStringArray(v) ? v : defaultConfig[key]) as ExtensionConfig[K];
4338
}
4439

45-
if (key === 'logLevel') {
46-
const v = value as unknown;
47-
return (isLogLevel(v) ? v : defaultConfig[key]) as ExtensionConfig[K];
48-
}
49-
5040
if (key === 'rstestPackagePath') {
5141
const v = value as unknown;
5242
return (
@@ -61,15 +51,10 @@ function isStringArray(v: unknown): v is string[] {
6151
return Array.isArray(v) && v.every((x) => typeof x === 'string');
6252
}
6353

64-
function isLogLevel(v: unknown): v is LogLevel {
65-
return v === 'default' || v === 'debug';
66-
}
67-
6854
// Convenience to get a full, normalized config object at the given scope.
6955
export function getConfig(folder?: vscode.WorkspaceFolder): ExtensionConfig {
7056
return {
7157
testFileGlobPattern: getConfigValue('testFileGlobPattern', folder),
72-
logLevel: getConfigValue('logLevel', folder),
7358
rstestPackagePath: getConfigValue('rstestPackagePath', folder),
7459
} satisfies ExtensionConfig;
7560
}

packages/vscode/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Rstest {
3535
constructor(context: vscode.ExtensionContext) {
3636
this.context = context;
3737
this.ctrl = vscode.tests.createTestController('rstest', 'Rstest');
38-
context.subscriptions.push(this.ctrl, logger);
38+
context.subscriptions.push(this.ctrl);
3939

4040
this.fileChangedEmitter = new vscode.EventEmitter<vscode.Uri>();
4141
this.watchingTests = new Map<

packages/vscode/src/logger.ts

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,39 @@
1-
import { inspect } from 'node:util';
1+
import { formatWithOptions } from 'node:util';
22
import vscode from 'vscode';
3-
import { getConfigValue, type LogLevel } from './config';
43

54
function formatValues(values: unknown[]): string {
6-
return values
7-
.map((value) =>
8-
typeof value === 'string'
9-
? value
10-
: inspect(value, { depth: 4, colors: false }),
11-
)
12-
.join(' ');
5+
return formatWithOptions({ depth: 4 }, ...values);
136
}
147

158
export class Logger implements vscode.Disposable {
16-
private readonly channel: vscode.OutputChannel;
17-
private readonly disposables: vscode.Disposable[] = [];
18-
private level: LogLevel;
9+
readonly #channel: vscode.LogOutputChannel;
1910

2011
constructor(private readonly name = 'Rstest') {
21-
this.channel = vscode.window.createOutputChannel(this.name);
22-
this.level = this.readLevel();
23-
this.disposables.push(
24-
vscode.workspace.onDidChangeConfiguration((event) => {
25-
if (event.affectsConfiguration('rstest.logLevel')) {
26-
this.level = this.readLevel();
27-
}
28-
}),
29-
);
12+
this.#channel = vscode.window.createOutputChannel(this.name, { log: true });
3013
}
3114

32-
public debug(...values: unknown[]) {
33-
if (this.level !== 'debug') {
34-
return;
35-
}
15+
public trace(...values: unknown[]) {
16+
this.#channel.trace(formatValues(values));
17+
}
3618

37-
this.write('DEBUG', values);
19+
public debug(...values: unknown[]) {
20+
this.#channel.debug(formatValues(values));
3821
}
3922

4023
public info(...values: unknown[]) {
41-
this.write('INFO', values);
24+
this.#channel.info(formatValues(values));
4225
}
4326

4427
public warn(...values: unknown[]) {
45-
this.write('WARN', values);
28+
this.#channel.warn(formatValues(values));
4629
}
4730

4831
public error(...values: unknown[]) {
49-
this.write('ERROR', values);
32+
this.#channel.error(formatValues(values));
5033
}
5134

5235
public dispose() {
53-
this.disposables.forEach((disposable) => {
54-
disposable.dispose();
55-
});
56-
this.channel.dispose();
57-
}
58-
59-
private readLevel(): LogLevel {
60-
return getConfigValue('logLevel');
61-
}
62-
63-
private write(tag: string, values: unknown[]) {
64-
const timestamp = new Date().toISOString();
65-
const message = formatValues(values);
66-
this.channel.appendLine(`[${timestamp}] [${tag}] ${message}`);
36+
this.#channel.dispose();
6737
}
6838
}
6939

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"rstest.logLevel": "default"
3-
}
1+
{}

packages/vscode/tests/suite/config.test.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as assert from 'node:assert';
22
import * as fs from 'node:fs';
33
import * as path from 'node:path';
44
import * as vscode from 'vscode';
5-
import { delay, waitForConfigValue } from './helpers';
5+
import { delay } from './helpers';
66

77
suite('Configuration Integration', () => {
88
function clearController(ctrl: vscode.TestController) {
@@ -125,35 +125,4 @@ suite('Configuration Integration', () => {
125125
}
126126
}
127127
});
128-
129-
test('respects rstest.logLevel', async () => {
130-
const config = vscode.workspace.getConfiguration('rstest');
131-
const prev = config.get('logLevel');
132-
133-
try {
134-
await config.update(
135-
'logLevel',
136-
'debug',
137-
vscode.ConfigurationTarget.Workspace,
138-
);
139-
await delay(500);
140-
141-
let logLevel = config.get('logLevel');
142-
143-
logLevel = await waitForConfigValue({
144-
initialValue: logLevel,
145-
read: () => vscode.workspace.getConfiguration('rstest').get('logLevel'),
146-
expected: 'debug',
147-
});
148-
149-
assert.strictEqual(logLevel, 'debug');
150-
} finally {
151-
await config.update(
152-
'logLevel',
153-
(prev as any) ?? undefined,
154-
vscode.ConfigurationTarget.Workspace,
155-
);
156-
await delay(100);
157-
}
158-
});
159128
});

0 commit comments

Comments
 (0)