Skip to content

Commit c1867c5

Browse files
committed
Not done
Issue:
1 parent dca7546 commit c1867c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+660
-434
lines changed

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,18 @@
584584
"default": ".build/attachments",
585585
"markdownDescription": "The path to a directory that will be used to store attachments produced during a test run.\n\nA relative path resolves relative to the root directory of the workspace running the test(s)",
586586
"scope": "machine-overridable"
587+
},
588+
"swift.outputChannelLevel": {
589+
"type": "string",
590+
"default": "info",
591+
"markdownDescription": "The the level of the Swift output channel. This has no affect on the verbosity of messages written to the extension's log file.",
592+
"enum": [
593+
"debug",
594+
"info",
595+
"warn",
596+
"error"
597+
],
598+
"scope": "machine-overridable"
587599
}
588600
}
589601
},
@@ -927,7 +939,8 @@
927939
"swift.diagnostics": {
928940
"type": "boolean",
929941
"default": false,
930-
"markdownDescription": "Output additional diagnostics to the Swift Output View.",
942+
"markdownDescription": "Output additional diagnostics to the Swift output channel.",
943+
"deprecationMessage": "**Deprecated**: Please use `#swift.outputChannelLevel#` instead.",
931944
"order": 100,
932945
"scope": "machine-overridable"
933946
}

src/DiagnosticsManager.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ export class DiagnosticsManager implements vscode.Disposable {
9999
);
100100
});
101101
})
102-
.catch(e =>
103-
context.outputChannel.log(`${e}`, 'Failed to provide "swiftc" diagnostics')
104-
);
102+
.catch(e => context.logger.error(`Failed to provide "swiftc" diagnostics: ${e}`));
105103
});
106104
const fileTypes = validFileTypes.join(",");
107105
this.workspaceFileWatcher = vscode.workspace.createFileSystemWatcher(

src/FolderContext.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import { WorkspaceContext, FolderOperation } from "./WorkspaceContext";
2222
import { BackgroundCompilation } from "./BackgroundCompilation";
2323
import { TaskQueue } from "./tasks/TaskQueue";
2424
import { isPathInsidePath } from "./utilities/filesystem";
25-
import { SwiftOutputChannel } from "./ui/SwiftOutputChannel";
2625
import { SwiftToolchain } from "./toolchain/toolchain";
26+
import { SwiftLogger } from "./logging/SwiftLogger";
2727

2828
export class FolderContext implements vscode.Disposable {
2929
private packageWatcher: PackageWatcher;
@@ -96,7 +96,7 @@ export class FolderContext implements vscode.Disposable {
9696
void vscode.window.showErrorMessage(
9797
`Failed to load ${folderContext.name}/Package.swift: ${error.message}`
9898
);
99-
workspaceContext.outputChannel.log(
99+
workspaceContext.logger.info(
100100
`Failed to load Package.swift: ${error.message}`,
101101
folderContext.name
102102
);
@@ -145,8 +145,8 @@ export class FolderContext implements vscode.Disposable {
145145
}
146146

147147
/** Load Swift Plugins and store in Package */
148-
async loadSwiftPlugins(outputChannel: SwiftOutputChannel) {
149-
await this.swiftPackage.loadSwiftPlugins(this.toolchain, outputChannel);
148+
async loadSwiftPlugins(logger: SwiftLogger) {
149+
await this.swiftPackage.loadSwiftPlugins(this.toolchain, logger);
150150
}
151151

152152
/**

src/PackageWatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class PackageWatcher {
155155
return Version.fromString(contents.toString().trim());
156156
} catch (error) {
157157
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
158-
this.workspaceContext.outputChannel.appendLine(
158+
this.workspaceContext.logger.error(
159159
`Failed to read .swift-version file at ${versionFile}: ${error}`
160160
);
161161
}

src/SwiftPackage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import { execSwift, getErrorDescription, hashString } from "./utilities/utilitie
1919
import { isPathInsidePath } from "./utilities/filesystem";
2020
import { SwiftToolchain } from "./toolchain/toolchain";
2121
import { BuildFlags } from "./toolchain/BuildFlags";
22-
import { SwiftOutputChannel } from "./ui/SwiftOutputChannel";
2322
import { lineBreakRegex } from "./utilities/tasks";
23+
import { SwiftLogger } from "./logging/SwiftLogger";
2424

2525
/** Swift Package Manager contents */
2626
interface PackageContents {
@@ -308,7 +308,7 @@ export class SwiftPackage {
308308
private static async loadPlugins(
309309
folder: vscode.Uri,
310310
toolchain: SwiftToolchain,
311-
outputChannel: SwiftOutputChannel
311+
logger: SwiftLogger
312312
): Promise<PackagePlugin[]> {
313313
try {
314314
const { stdout } = await execSwift(["package", "plugin", "--list"], toolchain, {
@@ -329,7 +329,7 @@ export class SwiftPackage {
329329
}
330330
return plugins;
331331
} catch (error) {
332-
outputChannel.appendLine(`Failed to laod plugins: ${error}`);
332+
logger.error(`Failed to load plugins: ${error}`);
333333
// failed to load resolved file return undefined
334334
return [];
335335
}
@@ -371,8 +371,8 @@ export class SwiftPackage {
371371
this.workspaceState = await SwiftPackage.loadWorkspaceState(this.folder);
372372
}
373373

374-
public async loadSwiftPlugins(toolchain: SwiftToolchain, outputChannel: SwiftOutputChannel) {
375-
this.plugins = await SwiftPackage.loadPlugins(this.folder, toolchain, outputChannel);
374+
public async loadSwiftPlugins(toolchain: SwiftToolchain, logger: SwiftLogger) {
375+
this.plugins = await SwiftPackage.loadPlugins(this.folder, toolchain, logger);
376376
}
377377

378378
/** Return if has valid contents */

src/SwiftSnippets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export async function debugSnippetWithOptions(
120120
return result;
121121
});
122122
} catch (error) {
123-
ctx.outputChannel.appendLine(`Failed to debug snippet: ${error}`);
123+
ctx.logger.error(`Failed to debug snippet: ${error}`);
124124
// ignore error if task failed to run
125125
return false;
126126
}

src/TestExplorer/TestExplorer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class TestExplorer {
270270
// we fall back to discovering tests with SPM.
271271
await this.discoverTestsInWorkspaceLSP(token);
272272
} catch {
273-
this.folderContext.workspaceContext.outputChannel.logDiagnostic(
273+
this.folderContext.workspaceContext.logger.debug(
274274
"workspace/tests LSP request not supported, falling back to SPM to discover tests.",
275275
"Test Discovery"
276276
);
@@ -300,7 +300,7 @@ export class TestExplorer {
300300
)
301301
.then(selected => {
302302
if (selected === enable) {
303-
explorer.folderContext.workspaceContext.outputChannel.log(
303+
explorer.folderContext.workspaceContext.logger.info(
304304
`Enabling SourceKit-LSP after swift-testing message`
305305
);
306306
void vscode.workspace
@@ -310,7 +310,7 @@ export class TestExplorer {
310310
/* Put in worker queue */
311311
});
312312
} else if (selected === ok) {
313-
explorer.folderContext.workspaceContext.outputChannel.log(
313+
explorer.folderContext.workspaceContext.logger.info(
314314
`User acknowledged that SourceKit-LSP is disabled`
315315
);
316316
}
@@ -399,7 +399,7 @@ export class TestExplorer {
399399
} else {
400400
explorer.setErrorTestItem(errorDescription);
401401
}
402-
explorer.folderContext.workspaceContext.outputChannel.log(
402+
explorer.folderContext.workspaceContext.logger.error(
403403
`Test Discovery Failed: ${errorDescription}`,
404404
explorer.folderContext.name
405405
);
@@ -439,7 +439,7 @@ export class TestExplorer {
439439
* @param errorDescription Error description to display
440440
*/
441441
private setErrorTestItem(errorDescription: string | undefined, title = "Test Discovery Error") {
442-
this.folderContext.workspaceContext.outputChannel.log(
442+
this.folderContext.workspaceContext.logger.error(
443443
`Test Discovery Error: ${errorDescription}`
444444
);
445445
this.controller.items.forEach(item => {

src/TestExplorer/TestRunner.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ export class TestRunner {
658658
await this.runSession(runState);
659659
}
660660
} catch (error) {
661-
this.workspaceContext.outputChannel.log(`Error: ${getErrorDescription(error)}`);
661+
this.workspaceContext.logger.error(`Error: ${getErrorDescription(error)}`);
662662
this.testRun.appendOutput(`\r\nError: ${getErrorDescription(error)}`);
663663
}
664664

@@ -726,7 +726,7 @@ export class TestRunner {
726726
await SwiftTestingConfigurationSetup.cleanupAttachmentFolder(
727727
this.folderContext,
728728
testRunTime,
729-
this.workspaceContext.outputChannel
729+
this.workspaceContext.logger
730730
);
731731
});
732732
}
@@ -923,11 +923,7 @@ export class TestRunner {
923923
const xUnitParser = new TestXUnitParser(
924924
this.folderContext.toolchain.hasMultiLineParallelTestOutput
925925
);
926-
const results = await xUnitParser.parse(
927-
buffer,
928-
runState,
929-
this.workspaceContext.outputChannel
930-
);
926+
const results = await xUnitParser.parse(buffer, runState, this.workspaceContext.logger);
931927
if (results) {
932928
this.testRun.appendOutput(
933929
`\r\nExecuted ${results.tests} tests, with ${results.failures} failures and ${results.errors} errors.\r\n`
@@ -1007,7 +1003,7 @@ export class TestRunner {
10071003
// output test build configuration
10081004
if (configuration.diagnostics) {
10091005
const configJSON = JSON.stringify(swiftTestBuildConfig);
1010-
this.workspaceContext.outputChannel.logDiagnostic(
1006+
this.workspaceContext.logger.debug(
10111007
`swift-testing Debug Config: ${configJSON}`,
10121008
this.folderContext.name
10131009
);
@@ -1034,7 +1030,7 @@ export class TestRunner {
10341030
// output test build configuration
10351031
if (configuration.diagnostics) {
10361032
const configJSON = JSON.stringify(xcTestBuildConfig);
1037-
this.workspaceContext.outputChannel.logDiagnostic(
1033+
this.workspaceContext.logger.debug(
10381034
`XCTest Debug Config: ${configJSON}`,
10391035
this.folderContext.name
10401036
);
@@ -1062,15 +1058,15 @@ export class TestRunner {
10621058

10631059
LoggingDebugAdapterTracker.setDebugSessionCallback(
10641060
session,
1065-
this.workspaceContext.outputChannel,
1061+
this.workspaceContext.logger,
10661062
output => {
10671063
outputHandler(output);
10681064
}
10691065
);
10701066

10711067
// add cancellation
10721068
const cancellation = this.testRun.token.onCancellationRequested(() => {
1073-
this.workspaceContext.outputChannel.logDiagnostic(
1069+
this.workspaceContext.logger.debug(
10741070
"Test Debugging Cancelled",
10751071
this.folderContext.name
10761072
);
@@ -1084,7 +1080,7 @@ export class TestRunner {
10841080
if (e.name !== config.name) {
10851081
return;
10861082
}
1087-
this.workspaceContext.outputChannel.logDiagnostic(
1083+
this.workspaceContext.logger.debug(
10881084
"Stop Test Debugging",
10891085
this.folderContext.name
10901086
);
@@ -1113,7 +1109,7 @@ export class TestRunner {
11131109
this.testRun.testRunStarted();
11141110
}
11151111

1116-
this.workspaceContext.outputChannel.logDiagnostic(
1112+
this.workspaceContext.logger.debug(
11171113
"Start Test Debugging",
11181114
this.folderContext.name
11191115
);
@@ -1137,7 +1133,7 @@ export class TestRunner {
11371133
await SwiftTestingConfigurationSetup.cleanupAttachmentFolder(
11381134
this.folderContext,
11391135
testRunTime,
1140-
this.workspaceContext.outputChannel
1136+
this.workspaceContext.logger
11411137
);
11421138
});
11431139
}

src/TestExplorer/TestXUnitParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import * as xml2js from "xml2js";
1616
import { ITestRunState } from "./TestParsers/TestRunState";
17-
import { SwiftOutputChannel } from "../ui/SwiftOutputChannel";
17+
import { SwiftLogger } from "../logging/SwiftLogger";
1818

1919
export interface TestResults {
2020
tests: number;
@@ -50,14 +50,14 @@ export class TestXUnitParser {
5050
async parse(
5151
buffer: string,
5252
runState: ITestRunState,
53-
outputChannel: SwiftOutputChannel
53+
logger: SwiftLogger
5454
): Promise<TestResults | undefined> {
5555
const xml = await xml2js.parseStringPromise(buffer);
5656
try {
5757
return await this.parseXUnit(xml, runState);
5858
} catch (error) {
5959
// ignore error
60-
outputChannel.appendLine(`Error parsing xUnit output: ${error}`);
60+
logger.error(`Error parsing xUnit output: ${error}`);
6161
return undefined;
6262
}
6363
}

src/WorkspaceContext.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import * as vscode from "vscode";
1616
import * as path from "path";
1717
import { FolderContext } from "./FolderContext";
1818
import { StatusItem } from "./ui/StatusItem";
19-
import { SwiftOutputChannel } from "./ui/SwiftOutputChannel";
2019
import { swiftLibraryPathKey } from "./utilities/utilities";
2120
import { isExcluded, isPathInsidePath } from "./utilities/filesystem";
2221
import { LanguageClientToolchainCoordinator } from "./sourcekit-lsp/LanguageClientToolchainCoordinator";
@@ -37,6 +36,8 @@ import { isValidWorkspaceFolder, searchForPackages } from "./utilities/workspace
3736
import { SwiftPluginTaskProvider } from "./tasks/SwiftPluginTaskProvider";
3837
import { SwiftTaskProvider } from "./tasks/SwiftTaskProvider";
3938
import { LLDBDebugConfigurationProvider } from "./debugger/debugAdapterFactory";
39+
import { SwiftLogger } from "./logging/SwiftLogger";
40+
import { SwiftLoggerFactory } from "./logging/SwiftLoggerFactory";
4041

4142
/**
4243
* Context for whole workspace. Holds array of contexts for each workspace folder
@@ -71,12 +72,15 @@ export class WorkspaceContext implements vscode.Disposable {
7172
public onDidStartBuild = this.buildStartEmitter.event;
7273
public onDidFinishBuild = this.buildFinishEmitter.event;
7374

75+
public loggerFactory: SwiftLoggerFactory;
76+
7477
private constructor(
7578
extensionContext: vscode.ExtensionContext,
7679
public tempFolder: TemporaryFolder,
77-
public outputChannel: SwiftOutputChannel,
80+
public logger: SwiftLogger,
7881
public globalToolchain: SwiftToolchain
7982
) {
83+
this.loggerFactory = new SwiftLoggerFactory(extensionContext.logUri);
8084
this.statusItem = new StatusItem();
8185
this.buildStatus = new SwiftBuildStatus(this.statusItem);
8286
this.languageClientManager = new LanguageClientToolchainCoordinator(this, {
@@ -88,11 +92,7 @@ export class WorkspaceContext implements vscode.Disposable {
8892
this.diagnostics = new DiagnosticsManager(this);
8993
this.taskProvider = new SwiftTaskProvider(this);
9094
this.pluginProvider = new SwiftPluginTaskProvider(this);
91-
this.launchProvider = new LLDBDebugConfigurationProvider(
92-
process.platform,
93-
this,
94-
outputChannel
95-
);
95+
this.launchProvider = new LLDBDebugConfigurationProvider(process.platform, this, logger);
9696
this.documentation = new DocumentationManager(extensionContext, this);
9797
this.currentDocument = null;
9898
this.commentCompletionProvider = new CommentCompletionProviders();
@@ -199,7 +199,7 @@ export class WorkspaceContext implements vscode.Disposable {
199199
this.diagnostics,
200200
this.documentation,
201201
this.languageClientManager,
202-
this.outputChannel,
202+
this.logger,
203203
this.statusItem,
204204
this.buildStatus,
205205
];
@@ -230,11 +230,11 @@ export class WorkspaceContext implements vscode.Disposable {
230230
/** Get swift version and create WorkspaceContext */
231231
static async create(
232232
extensionContext: vscode.ExtensionContext,
233-
outputChannel: SwiftOutputChannel,
233+
logger: SwiftLogger,
234234
toolchain: SwiftToolchain
235235
): Promise<WorkspaceContext> {
236236
const tempFolder = await TemporaryFolder.create();
237-
return new WorkspaceContext(extensionContext, tempFolder, outputChannel, toolchain);
237+
return new WorkspaceContext(extensionContext, tempFolder, logger, toolchain);
238238
}
239239

240240
/**
@@ -446,7 +446,7 @@ export class WorkspaceContext implements vscode.Disposable {
446446
// find context with root folder
447447
const index = this.folders.findIndex(context => context.folder.fsPath === folder.fsPath);
448448
if (index !== -1) {
449-
this.outputChannel.log(`Adding package folder ${folder} twice`, "WARN");
449+
this.logger.warn(`Adding package folder ${folder} twice`);
450450
return this.folders[index];
451451
}
452452
const folderContext = await FolderContext.create(folder, workspaceFolder, this);

0 commit comments

Comments
 (0)