SourceKitten icon indicating copy to clipboard operation
SourceKitten copied to clipboard

Muting SourceKit warnings on Linux

Open vinivendra opened this issue 5 years ago • 2 comments

(Sorry if this isn't the best place for this!)

I'm using SourceKittenFramework to do an indexing request on a Swift file. When that file has warnings, the SourceKit request prints those warnings to the console, and my program's output gets confusing. This happens on Ubuntu, but not on macOS.

Is there a way to use SourceKitten to mute those warnings? Is it something that has to be fixed on SourceKit itself?

vinivendra avatar Dec 30 '20 13:12 vinivendra

This should be the place for this kind of issue, but I don't know what warnings you're referring to, so I can't help you right now. Can you share more about what's happening? Ideally with steps to reproduce that I can follow on both macOS and Linux to identify the difference?

jpsim avatar Dec 31 '20 20:12 jpsim

Sure, no problem. Here's a gist with some files that should help explain the issue.

Basically, I created a short test.swift file (in the gist). When I compile it with Swift, it raises this warning, as expected:

test.swift:2:6: warning: initialization of variable 'x' was never used; consider replacing with assignment to '_' or removing it
        var x = 0
        ~~~~^
        _

Then, I created a new Swift package using swift package init --name Example --type executable. I added SourceKitten to the Package.swift file (also in the gist).

Finally, I added some code to the package's main.swift file (also in the gist) so that it'll use SourceKitten to execute an indexing request on the test.swift file.

When I run this on macOS BigSur using swift run it compiles and runs normally, and nothing gets printed to the console.

However, when I run this on Linux (on a Docker container using this Dockerfile) with swift run, it prints the above warning to the console. Ideally, I'd like the program to not print this warning.

vinivendra avatar Dec 31 '20 23:12 vinivendra