Skip to content

Commit ed7310a

Browse files
committed
Apply formatting
1 parent 0dc70d0 commit ed7310a

File tree

6 files changed

+158
-99
lines changed

6 files changed

+158
-99
lines changed

lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ async function getDAPArguments(
164164
* @returns The formatted date.
165165
*/
166166
function formatDate(date: Date): string {
167-
const year = date.getFullYear().toString().padStart(4, "0");
168-
const month = (date.getMonth() + 1).toString().padStart(2, "0");
169-
const day = date.getDate().toString().padStart(2, "0");
170-
const hour = date.getHours().toString().padStart(2, "0");
171-
const minute = date.getMinutes().toString().padStart(2, "0");
172-
const seconds = date.getSeconds().toString().padStart(2, "0");
173-
return `${year}${month}${day}T${hour}${minute}${seconds}`;
167+
const year = date.getFullYear().toString().padStart(4, "0");
168+
const month = (date.getMonth() + 1).toString().padStart(2, "0");
169+
const day = date.getDate().toString().padStart(2, "0");
170+
const hour = date.getHours().toString().padStart(2, "0");
171+
const minute = date.getMinutes().toString().padStart(2, "0");
172+
const seconds = date.getSeconds().toString().padStart(2, "0");
173+
return `${year}${month}${day}T${hour}${minute}${seconds}`;
174174
}
175175

176176
/**
@@ -190,13 +190,19 @@ export async function createDebugAdapterExecutable(
190190
workspaceFolder: vscode.WorkspaceFolder | undefined,
191191
configuration: vscode.DebugConfiguration,
192192
): Promise<vscode.DebugAdapterExecutable> {
193-
const config = vscode.workspace.workspaceFile ? vscode.workspace.getConfiguration("lldb-dap") : vscode.workspace.getConfiguration("lldb-dap", workspaceFolder);
193+
const config = vscode.workspace.workspaceFile
194+
? vscode.workspace.getConfiguration("lldb-dap")
195+
: vscode.workspace.getConfiguration("lldb-dap", workspaceFolder);
194196
const log_path = config.get<string>("log-path");
195197
let env: { [key: string]: string } = {};
196198
if (log_path) {
197199
env["LLDBDAP_LOG"] = log_path;
198-
} else if (vscode.workspace.getConfiguration("lldb-dap").get("verboseLogging", false)) {
199-
env["LLDBDAP_LOG"] = logFilePath(`lldb-dap-session-${formatDate(new Date())}.log`);
200+
} else if (
201+
vscode.workspace.getConfiguration("lldb-dap").get("verboseLogging", false)
202+
) {
203+
env["LLDBDAP_LOG"] = logFilePath(
204+
`lldb-dap-session-${formatDate(new Date())}.log`,
205+
);
200206
}
201207
const configEnvironment =
202208
config.get<{ [key: string]: string }>("environment") || {};
@@ -226,14 +232,20 @@ export async function createDebugAdapterExecutable(
226232
export class LLDBDapDescriptorFactory
227233
implements vscode.DebugAdapterDescriptorFactory
228234
{
229-
constructor(private readonly logger: Logger, private logFilePath: LogFilePathProvider) {}
235+
constructor(
236+
private readonly logger: Logger,
237+
private logFilePath: LogFilePathProvider,
238+
) {}
230239

231240
async createDebugAdapterDescriptor(
232241
session: vscode.DebugSession,
233242
executable: vscode.DebugAdapterExecutable | undefined,
234243
): Promise<vscode.DebugAdapterDescriptor | undefined> {
235244
this.logger.info(`Creating debug adapter for session "${session.name}"`);
236-
this.logger.debug(`Session "${session.name}" debug configuration:\n` + JSON.stringify(session.configuration, undefined, 2));
245+
this.logger.debug(
246+
`Session "${session.name}" debug configuration:\n` +
247+
JSON.stringify(session.configuration, undefined, 2),
248+
);
237249
if (executable) {
238250
const error = new Error(
239251
"Setting the debug adapter executable in the package.json is not supported.",
@@ -244,7 +256,9 @@ export class LLDBDapDescriptorFactory
244256

245257
// Use a server connection if the debugAdapterPort is provided
246258
if (session.configuration.debugAdapterPort) {
247-
this.logger.info(`Spawning debug adapter server on port ${session.configuration.debugAdapterPort}`);
259+
this.logger.info(
260+
`Spawning debug adapter server on port ${session.configuration.debugAdapterPort}`,
261+
);
248262
return new vscode.DebugAdapterServer(
249263
session.configuration.debugAdapterPort,
250264
session.configuration.debugAdapterHostname,

lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,24 @@ const configurations: Record<string, DefaultConfig> = {
7272
export class LLDBDapConfigurationProvider
7373
implements vscode.DebugConfigurationProvider
7474
{
75-
constructor(private readonly server: LLDBDapServer, private readonly logger: Logger, private readonly logFilePath: LogFilePathProvider) {}
75+
constructor(
76+
private readonly server: LLDBDapServer,
77+
private readonly logger: Logger,
78+
private readonly logFilePath: LogFilePathProvider,
79+
) {}
7680

7781
async resolveDebugConfiguration(
7882
folder: vscode.WorkspaceFolder | undefined,
7983
debugConfiguration: vscode.DebugConfiguration,
8084
token?: vscode.CancellationToken,
8185
): Promise<vscode.DebugConfiguration> {
82-
this.logger.info(`Resolving debug configuration for "${debugConfiguration.name}"`);
83-
this.logger.debug("Initial debug configuration:\n" + JSON.stringify(debugConfiguration, undefined, 2));
86+
this.logger.info(
87+
`Resolving debug configuration for "${debugConfiguration.name}"`,
88+
);
89+
this.logger.debug(
90+
"Initial debug configuration:\n" +
91+
JSON.stringify(debugConfiguration, undefined, 2),
92+
);
8493
let config = vscode.workspace.getConfiguration("lldb-dap");
8594
for (const [key, cfg] of Object.entries(configurations)) {
8695
if (Reflect.has(debugConfiguration, key)) {
@@ -189,7 +198,10 @@ export class LLDBDapConfigurationProvider
189198
}
190199
}
191200

192-
this.logger.debug("Resolved debug configuration:\n" + JSON.stringify(debugConfiguration, undefined, 2));
201+
this.logger.debug(
202+
"Resolved debug configuration:\n" +
203+
JSON.stringify(debugConfiguration, undefined, 2),
204+
);
193205

194206
return debugConfiguration;
195207
} catch (error) {

lldb/tools/lldb-dap/src-ts/debug-session-tracker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class DebugSessionTracker
6969
return {
7070
onError: (error) => !stopping && this.logger.error(error), // Can throw benign read errors when shutting down
7171
onDidSendMessage: (message) => this.onDidSendMessage(session, message),
72-
onWillStopSession: () => stopping = true,
72+
onWillStopSession: () => (stopping = true),
7373
onExit: () => this.onExit(session),
7474
};
7575
}
@@ -144,7 +144,9 @@ export class DebugSessionTracker
144144
// The vscode.DebugAdapterTracker#onExit event is sometimes called with
145145
// exitCode = undefined but the exit event from LLDB-DAP always has the "exitCode"
146146
const { exitCode } = message.body;
147-
this.logger.info(`Session "${session.name}" exited with code ${exitCode}`);
147+
this.logger.info(
148+
`Session "${session.name}" exited with code ${exitCode}`,
149+
);
148150
}
149151
}
150152
}

lldb/tools/lldb-dap/src-ts/extension.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import { LLDBDAPLogger, LogFilePathProvider } from "./logger";
1818
* using it as as library should use this class as the main entry point.
1919
*/
2020
export class LLDBDapExtension extends DisposableContext {
21-
constructor(logger: LLDBDAPLogger, logFilePath: LogFilePathProvider, outputChannel: vscode.OutputChannel) {
21+
constructor(
22+
logger: LLDBDAPLogger,
23+
logFilePath: LogFilePathProvider,
24+
outputChannel: vscode.OutputChannel,
25+
) {
2226
super();
2327

2428
const lldbDapServer = new LLDBDapServer();
@@ -61,9 +65,15 @@ export class LLDBDapExtension extends DisposableContext {
6165
export async function activate(context: vscode.ExtensionContext) {
6266
await vscode.workspace.fs.createDirectory(context.logUri);
6367
const outputChannel = vscode.window.createOutputChannel("LLDB-DAP");
64-
const logFilePath: LogFilePathProvider = (name) => path.join(context.logUri.fsPath, name);
65-
const logger = new LLDBDAPLogger(logFilePath("lldb-dap-extension.log"), outputChannel);
68+
const logFilePath: LogFilePathProvider = (name) =>
69+
path.join(context.logUri.fsPath, name);
70+
const logger = new LLDBDAPLogger(
71+
logFilePath("lldb-dap-extension.log"),
72+
outputChannel,
73+
);
6674
logger.info("LLDB-Dap extension activating...");
67-
context.subscriptions.push(new LLDBDapExtension(logger, logFilePath, outputChannel));
75+
context.subscriptions.push(
76+
new LLDBDapExtension(logger, logFilePath, outputChannel),
77+
);
6878
logger.info("LLDB-Dap extension activated");
6979
}

lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class LLDBDapServer implements vscode.Disposable {
2626
args: string[],
2727
options?: child_process.SpawnOptionsWithoutStdio,
2828
): Promise<{ host: string; port: number } | undefined> {
29-
const dapArgs = [...args, "--connection", "listen://localhost:0" ];
29+
const dapArgs = [...args, "--connection", "listen://localhost:0"];
3030
if (!(await this.shouldContinueStartup(dapPath, dapArgs))) {
3131
return undefined;
3232
}

lldb/tools/lldb-dap/src-ts/logger.ts

Lines changed: 96 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,98 +6,119 @@ import * as TransportType from "winston-transport";
66
const Transport: typeof TransportType = require("winston-transport");
77

88
class OutputChannelTransport extends Transport {
9-
constructor(private readonly ouptutChannel: vscode.OutputChannel) {
10-
super();
11-
}
9+
constructor(private readonly ouptutChannel: vscode.OutputChannel) {
10+
super();
11+
}
1212

13-
public log(info: any, next: () => void): void {
14-
this.ouptutChannel.appendLine(info[Symbol.for('message')]);
15-
next();
16-
}
13+
public log(info: any, next: () => void): void {
14+
this.ouptutChannel.appendLine(info[Symbol.for("message")]);
15+
next();
16+
}
1717
}
1818

1919
export type LogFilePathProvider = (name: string) => string;
2020

2121
export interface Logger {
22-
debug(message: string, ...args: any[]): void
23-
error(error: string | Error, ...args: any[]): void
24-
info(message: string, ...args: any[]): void
25-
warn(message: string, ...args: any[]): void
22+
debug(message: string, ...args: any[]): void;
23+
error(error: string | Error, ...args: any[]): void;
24+
info(message: string, ...args: any[]): void;
25+
warn(message: string, ...args: any[]): void;
2626
}
2727

2828
export class LLDBDAPLogger implements vscode.Disposable {
29-
private disposables: vscode.Disposable[] = [];
30-
private logger: winston.Logger;
29+
private disposables: vscode.Disposable[] = [];
30+
private logger: winston.Logger;
3131

32-
constructor(public readonly logFilePath: string, ouptutChannel: vscode.OutputChannel) {
33-
const ouptutChannelTransport = new OutputChannelTransport(ouptutChannel);
34-
ouptutChannelTransport.level = this.outputChannelLevel();
35-
this.logger = winston.createLogger({
36-
transports: [
37-
new winston.transports.File({ filename: logFilePath, level: "debug" }), // File logging at the 'debug' level
38-
ouptutChannelTransport
39-
],
40-
format: winston.format.combine(
41-
winston.format.errors({ stack: true }),
42-
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }), // This is the format of `vscode.LogOutputChannel`
43-
winston.format.printf(msg => `${msg.timestamp} [${msg.level}] ${msg.message} ${msg.stack ? msg.stack : ''}`),
44-
),
45-
});
46-
if (process.env.NODE_ENV !== 'production') {
47-
this.logger.add(new winston.transports.Console({
48-
level: "error"
49-
}));
50-
}
51-
this.disposables.push(
52-
{
53-
dispose: () => this.logger.close()
54-
},
55-
vscode.workspace.onDidChangeConfiguration(e => {
56-
if (e.affectsConfiguration("lldb-dap.verboseLogging")) {
57-
ouptutChannelTransport.level = this.outputChannelLevel();
58-
}
59-
})
60-
);
32+
constructor(
33+
public readonly logFilePath: string,
34+
ouptutChannel: vscode.OutputChannel,
35+
) {
36+
const ouptutChannelTransport = new OutputChannelTransport(ouptutChannel);
37+
ouptutChannelTransport.level = this.outputChannelLevel();
38+
this.logger = winston.createLogger({
39+
transports: [
40+
new winston.transports.File({ filename: logFilePath, level: "debug" }), // File logging at the 'debug' level
41+
ouptutChannelTransport,
42+
],
43+
format: winston.format.combine(
44+
winston.format.errors({ stack: true }),
45+
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }), // This is the format of `vscode.LogOutputChannel`
46+
winston.format.printf(
47+
(msg) =>
48+
`${msg.timestamp} [${msg.level}] ${msg.message} ${msg.stack ? msg.stack : ""}`,
49+
),
50+
),
51+
});
52+
if (process.env.NODE_ENV !== "production") {
53+
this.logger.add(
54+
new winston.transports.Console({
55+
level: "error",
56+
}),
57+
);
6158
}
59+
this.disposables.push(
60+
{
61+
dispose: () => this.logger.close(),
62+
},
63+
vscode.workspace.onDidChangeConfiguration((e) => {
64+
if (e.affectsConfiguration("lldb-dap.verboseLogging")) {
65+
ouptutChannelTransport.level = this.outputChannelLevel();
66+
}
67+
}),
68+
);
69+
}
6270

63-
debug(message: string, ...args: any[]) {
64-
this.logger.debug([message, ...args].map(m => this.normalizeMessage(m)).join(" "));
65-
}
71+
debug(message: string, ...args: any[]) {
72+
this.logger.debug(
73+
[message, ...args].map((m) => this.normalizeMessage(m)).join(" "),
74+
);
75+
}
6676

67-
info(message: string, ...args: any[]) {
68-
this.logger.info([message, ...args].map(m => this.normalizeMessage(m)).join(" "));
69-
}
77+
info(message: string, ...args: any[]) {
78+
this.logger.info(
79+
[message, ...args].map((m) => this.normalizeMessage(m)).join(" "),
80+
);
81+
}
7082

71-
warn(message: string, ...args: any[]) {
72-
this.logger.warn([message, ...args].map(m => this.normalizeMessage(m)).join(" "));
73-
}
83+
warn(message: string, ...args: any[]) {
84+
this.logger.warn(
85+
[message, ...args].map((m) => this.normalizeMessage(m)).join(" "),
86+
);
87+
}
7488

75-
error(message: Error | string, ...args: any[]) {
76-
if (message instanceof Error) {
77-
this.logger.error(message);
78-
this.logger.error([...args].map(m => this.normalizeMessage(m)).join(" "));
79-
return;
80-
}
81-
this.logger.error([message, ...args].map(m => this.normalizeMessage(m)).join(" "));
89+
error(message: Error | string, ...args: any[]) {
90+
if (message instanceof Error) {
91+
this.logger.error(message);
92+
this.logger.error(
93+
[...args].map((m) => this.normalizeMessage(m)).join(" "),
94+
);
95+
return;
8296
}
97+
this.logger.error(
98+
[message, ...args].map((m) => this.normalizeMessage(m)).join(" "),
99+
);
100+
}
83101

84-
private normalizeMessage(message: any) {
85-
if (typeof message === "string") {
86-
return message;
87-
}
88-
try {
89-
return JSON.stringify(message);
90-
} catch (e) {
91-
return `${message}`;
92-
}
102+
private normalizeMessage(message: any) {
103+
if (typeof message === "string") {
104+
return message;
93105
}
94-
95-
private outputChannelLevel(): string {
96-
return vscode.workspace.getConfiguration("lldb-dap").get("verboseLogging", false) ?
97-
"debug" : "info";
106+
try {
107+
return JSON.stringify(message);
108+
} catch (e) {
109+
return `${message}`;
98110
}
111+
}
99112

100-
dispose() {
101-
this.disposables.forEach(d => d.dispose());
102-
}
103-
}
113+
private outputChannelLevel(): string {
114+
return vscode.workspace
115+
.getConfiguration("lldb-dap")
116+
.get("verboseLogging", false)
117+
? "debug"
118+
: "info";
119+
}
120+
121+
dispose() {
122+
this.disposables.forEach((d) => d.dispose());
123+
}
124+
}

0 commit comments

Comments
 (0)