-
Notifications
You must be signed in to change notification settings - Fork 7.6k
#10071 bash detection for extensionless file #10141
base: master
Are you sure you want to change the base?
#10071 bash detection for extensionless file #10141
Conversation
drive-by comment: the language modes themselves should define how to detect them via the text of the document. |
(In other words, language manager should not be hardcoded to detect bash scripts... a bash mode, likely defined in an extension, would detect that.) |
Should I add an attribute like |
It might be tricky since every language needs different code for detection |
You could think about possibly using a regex. And that's right that every language needs to do something different to detect, which is why it belongs in the language mode definition. Also, the search could probably be restricted to the first line of the file. BTW, you'll need to sign the CLA before we could accept any pull requests. I'll also note that we have a large backlog of pull requests at the moment, so I can't guarantee how quickly we'll get to this one... sorry about that. |
It's okay, thanks a lot! I signed the CLA. I will change my code and push it to see. |
Since extensionless files are likely to be script, so I re-implement it as general shebang detection instead of bash specifed. It might have better performance as well because no need to go through each language object to test regexp. Thanks to @apla, I have a clear idea of using regexp now. |
*/ | ||
Document.prototype._updateLanguage = function () { | ||
Document.prototype._updateLanguage = function (rawText) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is called from other places that won't pass rawText
(e.g. _notifyFilePathChanged()
, DocumentManager._handleLanguageAdded()
, etc.). Will the behavior be correct then? It safer & simpler to remove the arg and just invoke this.getText()
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But also... since this is called in multiple cases, various actions will trigger a "re-check" of the document's text. If the user edits the document to add/remove the shebang, at what point would they expect the document to switch to/from Bash mode? We should make sure that feels predictable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this.getText()
won't exist cause the functions are called by Document
constructor. Therefore, using rawText
is probably the best way to pass the contents to LanguageManager
. So far, the shebang detection happens only when user opens a file, I am not sure about the "re-check" triggers during editing. Could you or anybody help me for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and yes rawText
can be null, so _updateLanguage()
can be called without rawText
.
I really would appreciate this or a extension, I am tired of manually switching to bash. Well I will probably rename all my scripts to .sh now even if I not really like it. |
Hi, this is probably not the best solution. Please review my code and let me know :)