Skip to content

Report diagnostics for script files with shebangs based on fallback build settings#2426

Draft
ahoppen wants to merge 1 commit intoswiftlang:mainfrom
ahoppen:script-diagnostics
Draft

Report diagnostics for script files with shebangs based on fallback build settings#2426
ahoppen wants to merge 1 commit intoswiftlang:mainfrom
ahoppen:script-diagnostics

Conversation

@ahoppen
Copy link
Copy Markdown
Member

@ahoppen ahoppen commented Jan 5, 2026

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

…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
@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Jan 5, 2026

@swift-ci Please test

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking you could have something like #!/usr/bin/swift -language-mode 6, would it be worth trying to detect that or not?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we probably should. The correct implementation would be:

  • BuildServerManager should 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 BuildServerManager needs 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 in BuildServerManager, 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.

Copy link
Copy Markdown
Member

@rintaro rintaro Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random thoughts:

  • It's possible the file has a weird shebang like #!/opt/bin/myRunner where myRunner is a wrapper of swift with extra compiler arguments. So having shebang might not be enough for getting the build arguments for the file.
  • BuildServerManager might want to delegate the primary languageService to translate the shebang line to the build settings. Because it's language/compiler specific.

@ahoppen ahoppen marked this pull request as draft January 6, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swift scripts update errors and warnings only after running

3 participants