Currently, the filetype is autodetected only when a new document is opened. If a user adds a filetype shebang line, the only way to redetect the filetype is to close and reopen the document. (While the user could manually change the filetype, the purpose of the shebang line is to avoid manual filetype selection, which is cumbersome because of the multiply nested menus.)
The following change could address this issue without affecting most other users:
* Re-detect filetype on reload, but change filetype only when the current filetype is None or a shebang line is used. - Users are unlikely to change the filetype to None. - Users are unlikely to keep a shebang line for the wrong type.
There is a PR (not yet merged) for the project organizer plugin that changes the filetype of header files to match the corresponding source file. It currently does so only on the document-open signal, so changing the filetype on could cause the "wrong" filetype to be reassigned to the header. However, since the change would be restricted to when the current filetype is None or a new type is determined by shebang, incorrect filetype reassignment is unlikely.
This functionality cannot be implemented in a plugin because `filetypes_detect_from_file` does not report whether the filetype was detected from filename or shebang line.