Emit notes from build tool plugin

While there's Diagnostics.error and Diagnostics.warning to emit erros and warnings from build tool plugins I can't figure out how to emit notes like the below:

image

I tried print("<FILE>:<LINE>:<COLUMN>: note: <MESSAGE>") but no success. Is it possible?

I don't think that those are build tool plugin diagnostics. I think that they are errors emitted from the compiler at compile time. Xcode can parse these messages and display them in its own UI.

e.g. here is a small amount of code which contains an error which prevents it from compiling successfully.


struct Test: ~Copyable {
	func doSomething() {
	}
}

struct DoWork {
	func doIt() {
		let x = Test()
		_ = consume x
		x.doSomething()   //  💣 Here's the error!
	}
}

let work = DoWork()
work.doIt()

The compiler emits the following when compiled from the command line:

MPB-16 ➜   movable swift build
Building for debugging...
/Users/diggory/Desktop/movable/Sources/main.swift:14:7: error: 'x' used after consume
                let x = Test()
                    ^
/Users/diggory/Desktop/movable/Sources/main.swift:15:15: note: consumed here
                _ = consume x
                            ^
/Users/diggory/Desktop/movable/Sources/main.swift:16:3: note: used here
                x.doSomething()
                ^
error: fatalError

In Xcode:

There doesn't appear to be a way to refer to other lines in build tool plugin diagnostics and have Xcode show UI about it. You can provide information in the Diagnostics, which will be displayed in the Xcode build logs...

(from a sample SwiftPM Build Tool)

		print("Hello - Print() statement from Build Tool Plugin...")
		Diagnostics.remark("Target source files: \(target.sourceFiles)\n")


		//		Diagnostics.error("Test Error from DemoBuildToolPlugin")
		//		Diagnostics.warning("Test Warning from DemoBuildToolPlugin")
		Diagnostics.remark("Test Remark from DemoBuildToolPlugin\n")

		Diagnostics.warning("A Test Warning... Look out for bears!\n", file: #file, line: 58)
		Diagnostics.warning("A Warning: we don't return any commands!\n", line: 64)

1 Like

Thanks for well explained answer! Diagnostics are pretty limited in build tool plugins. Besides notes they also lack support to fix-it, at least I couldn’t find a way to use them also.