Skip to content

Commit 9c1069d

Browse files
authored
Deduplicate swift diagnostics (#821)
* Deduplicate swift diagnostics Fixes #653 * Keeping "$swiftc" problem matcher around in case it is still being used * Add "diagnosticsCollection" setting to give more control on which diagnostics are kept around and provided to the user * Setup diagnostics from task output and hooking into sourcekit-lsp * Handle merging based on "diagnosticsCollection" setting This does not include serialized diagnostics which will involve changes in swift itself * Add some more diagnostics tests Have tests for parsing from task output, controlling the parsing of a diagnostic across multiple onWrite callbacks, and for handling the merging of diagnostics based on the diagnosticsCollection setting * Fix some issues with cleaning up old diagnostics * Makes sure always cleanup swiftc diagnostics in case diagnosticsCollection setting changed * De-duplicate error messages until swift 6 is fixed * Make sure diagnostic message capitalization is consistent Whether swiftc or SourceKit capitalize the first letter of their message or not, we'll make sure always capitalize so message user sees is consistent, and we can properly merge from the different sources * Parse note diagnotics as nested related information Notes are attached to the preceding error or warning, so when we come across a note, add it as RelatedInformation to the previous Diagnostic Additionally let the user configure the -diagnostic-style option, using "llvm" as the default so we can parse these notes * Only cleanup swiftc diagnostics after new build is done Will listen to change in settings to clear SourceKit or swiftc errors if they are respectfully disabled * Simplify diagnostic merging logic * Fix rebase error * Fix failing CI tests
1 parent ccd5a7f commit 9c1069d

15 files changed

+1336
-46
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"configurations": [
3+
{
4+
"type": "lldb",
5+
"request": "launch",
6+
"sourceLanguages": [
7+
"swift"
8+
],
9+
"args": [],
10+
"cwd": "${workspaceFolder:diagnostics}",
11+
"name": "Debug diagnostics",
12+
"program": "${workspaceFolder:diagnostics}/.build/debug/diagnostics",
13+
"preLaunchTask": "swift: Build Debug diagnostics"
14+
},
15+
{
16+
"type": "lldb",
17+
"request": "launch",
18+
"sourceLanguages": [
19+
"swift"
20+
],
21+
"args": [],
22+
"cwd": "${workspaceFolder:diagnostics}",
23+
"name": "Release diagnostics",
24+
"program": "${workspaceFolder:diagnostics}/.build/release/diagnostics",
25+
"preLaunchTask": "swift: Build Release diagnostics"
26+
},
27+
{
28+
"type": "lldb",
29+
"request": "launch",
30+
"sourceLanguages": [
31+
"swift"
32+
],
33+
"args": [],
34+
"cwd": "${workspaceFolder:diagnostics}",
35+
"name": "Debug diagnostics",
36+
"program": "${workspaceFolder:diagnostics}/.build/debug/diagnostics",
37+
"preLaunchTask": "swift: Build Debug diagnostics"
38+
},
39+
{
40+
"type": "lldb",
41+
"request": "launch",
42+
"sourceLanguages": [
43+
"swift"
44+
],
45+
"args": [],
46+
"cwd": "${workspaceFolder:diagnostics}",
47+
"name": "Release diagnostics",
48+
"program": "${workspaceFolder:diagnostics}/.build/release/diagnostics",
49+
"preLaunchTask": "swift: Build Release diagnostics"
50+
}
51+
]
52+
}

assets/test/diagnostics/Package.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// swift-tools-version: 5.6
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "diagnostics",
8+
dependencies: [],
9+
targets: [
10+
// Targets are the basic building blocks of a package, defining a module or a test suite.
11+
// Targets can depend on other targets in this package and products from dependencies.
12+
.executableTarget(
13+
name: "diagnostics",
14+
dependencies: [],
15+
path: "Sources"),
16+
]
17+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
func error() {
2+
baz + 1
3+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func myFunc() -> Int {
2+
var unused = "hello"
3+
return 1
4+
}
5+
6+
let foo = myFunc()
7+
let bar = 2
8+
bar = 3
9+
var line: String?
10+
repeat {
11+
print("Enter a string: ", terminator: "")
12+
line = readLine()
13+
print(line ?? "nil")
14+
} while line != nil;

package.json

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,42 @@
230230
"scope": "machine-overridable",
231231
"order": 7
232232
},
233-
"swift.problemMatchCompileErrors": {
234-
"type": "boolean",
235-
"default": true,
236-
"description": "List compile errors in the Problems View.",
233+
"swift.diagnosticsCollection": {
234+
"type": "string",
235+
"default": "keepSourceKit",
236+
"description": "Controls how diagnostics from the various providers are merged into the `swift` diagnostics collection.",
237+
"enum": [
238+
"onlySwiftc",
239+
"onlySourceKit",
240+
"keepSwiftc",
241+
"keepSourceKit",
242+
"keepAll"
243+
],
244+
"enumDescriptions": [
245+
"Only provide diagnostics from `swiftc`.",
246+
"Only provide diagnostics from `SourceKit`.",
247+
"When merging diagnostics, give precedence to diagnostics from `swiftc`.",
248+
"When merging diagnostics, give precedence to diagnostics from `SourceKit`.",
249+
"Keep diagnostics from all providers."
250+
],
237251
"order": 8
238252
},
253+
"swift.diagnosticsStyle": {
254+
"type": "string",
255+
"default": "llvm",
256+
"description": "Controls which -diagnostic-style option to pass to `swiftc` when running `swift` tasks.",
257+
"enum": [
258+
"default",
259+
"llvm",
260+
"swift"
261+
],
262+
"enumDescriptions": [
263+
"Use whichever diagnostics style `swiftc` produces by default.",
264+
"Use the \"llvm\" diagnostic style. This allows the parsing of \"notes\".",
265+
"Use the \"swift\" diagnostic style. This means that \"notes\" will not be parsed. This option will not work for Swift versions prior to 5.10."
266+
],
267+
"order": 9
268+
},
239269
"swift.excludePathsFromPackageDependencies": {
240270
"description": "A list of paths to exclude from the Package Dependencies view.",
241271
"type": "array",
@@ -246,13 +276,13 @@
246276
".git",
247277
".github"
248278
],
249-
"order": 9
279+
"order": 10
250280
},
251281
"swift.backgroundCompilation": {
252282
"type": "boolean",
253283
"default": false,
254284
"markdownDescription": "**Experimental**: Run `swift build` in the background whenever a file is saved.",
255-
"order": 10
285+
"order": 11
256286
},
257287
"swift.actionAfterBuildError": {
258288
"type": "string",
@@ -267,25 +297,25 @@
267297
"Focus on Build Task Terminal"
268298
],
269299
"markdownDescription": "Action after a Build task generates errors.",
270-
"order": 11
300+
"order": 12
271301
},
272302
"swift.buildPath": {
273303
"type": "string",
274304
"default": "",
275305
"markdownDescription": "Path to the build directory passed to all swift package manager commands.",
276-
"order": 12
306+
"order": 13
277307
},
278308
"swift.disableSwiftPackageManagerIntegration": {
279309
"type": "boolean",
280310
"default": false,
281311
"markdownDescription": "Disables automated Build Tasks, Package Dependency view, Launch configuration generation and TestExplorer.",
282-
"order": 13
312+
"order": 14
283313
},
284314
"swift.showCreateSwiftProjectInWelcomePage": {
285315
"type": "boolean",
286316
"default": true,
287317
"description": "Controls whether or not the create new swift project button appears in the welcome page.",
288-
"order": 14
318+
"order": 15
289319
},
290320
"swift.openAfterCreateNewProject": {
291321
"type": "string",
@@ -303,7 +333,7 @@
303333
],
304334
"default": "prompt",
305335
"description": "Controls whether to open a swift project automatically after creating it.",
306-
"order": 15
336+
"order": 16
307337
},
308338
"swift.showBuildStatus": {
309339
"type": "string",
@@ -321,7 +351,7 @@
321351
"Show the Swift build status in the \"Progress Message\" status bar item provided by VSCode.",
322352
"Show the Swift build status as a progress notification."
323353
],
324-
"order": 16
354+
"order": 17
325355
}
326356
}
327357
},

0 commit comments

Comments
 (0)