Report diagnostics for script files with shebangs based on fallback build settings#2426
Draft
ahoppen wants to merge 1 commit intoswiftlang:mainfrom
Draft
Report diagnostics for script files with shebangs based on fallback build settings#2426ahoppen wants to merge 1 commit intoswiftlang:mainfrom
ahoppen wants to merge 1 commit intoswiftlang:mainfrom
Conversation
…uild settings If a file has a shebang, we know that it can be executed on its own and thus we can produce semantic diagnostics even with fallback build settings. Fixes swiftlang#2383
fb598ab to
c79ca1c
Compare
Member
Author
|
@swift-ci Please test |
hamishknight
approved these changes
Jan 5, 2026
Comment on lines
+84
to
+85
| // The only exception is if the file starts with a shebang. In that case we know that the file can be executed on | ||
| // its own without additional compiler arguments. |
Contributor
There was a problem hiding this comment.
Strictly speaking you could have something like #!/usr/bin/swift -language-mode 6, would it be worth trying to detect that or not?
Member
Author
There was a problem hiding this comment.
Hmm, we probably should. The correct implementation would be:
BuildServerManagershould look at file contents when it synthesizes fallback settings and if it discovers a shebang (a) include compiler arguments from there in the build settings it returns and (b) not mark the returned build settings as fallback- Now
BuildServerManagerneeds to watch this file for changes so that we can reload build settings when they are modified. It would likely be sufficient to only do this when the file has been saved to disk but we’d need to start keeping track which files we have returned fallback build settings for and watch all of them inBuildServerManager, which we currently don’t do. This will likely be the tricky part. Let’s see if I have an idea in a few days.
Member
There was a problem hiding this comment.
Random thoughts:
- It's possible the file has a weird shebang like
#!/opt/bin/myRunnerwheremyRunneris a wrapper ofswiftwith extra compiler arguments. So having shebang might not be enough for getting the build arguments for the file. BuildServerManagermight want to delegate the primarylanguageServiceto translate the shebang line to the build settings. Because it's language/compiler specific.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a file has a shebang, we know that it can be executed on its own and thus we can produce semantic diagnostics even with fallback build settings.
Fixes #2383