Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin Idea: Shebang lines to auto-detect language #2174

Closed
joshgoebel opened this issue Oct 9, 2019 · 8 comments
Closed

Plugin Idea: Shebang lines to auto-detect language #2174

joshgoebel opened this issue Oct 9, 2019 · 8 comments
Labels
enhancement An enhancement or new feature plugin Specific plugin or plugin discussion

Comments

@joshgoebel
Copy link
Member

joshgoebel commented Oct 9, 2019

Ie if starts with:

#!/usr/bin/env python

Python relevancy +100, etc. Or would this not be that useful in practice? Was just at hough I had reading a LOT of Python samples. :) I guess the trick is we're not always given full samples, but seems like when we are this would be a dead giveaway a lot of the time?

@joshgoebel
Copy link
Member Author

joshgoebel commented Oct 9, 2019

If there was value I'd suggesting adding it as a feature in general... such that you had a shebang: key that took a regex and you could do something simple like:

shebang: 'python'

Or get more complex... and the parser itself would check the very first like for "#!.*shebang pattern.*$" or something.

@joshgoebel joshgoebel added enhancement An enhancement or new feature and removed question labels Oct 11, 2019
@joshgoebel joshgoebel changed the title Any thoughts on adding shebang lines as a concept? Idea: Any thoughts on adding shebang lines as a concept? Oct 16, 2019
@joshgoebel
Copy link
Member Author

@egor-rogov Any objections to the idea if we find someone to work on it? Just a relevance boost if there is a matching shebang line that starts the content... if not I'll promote to "help welcome". If you're super opposed for some reason this can just die.

I just thought it was a helpful idea for snippet that DID actually contain a shebang.

@egor-rogov
Copy link
Collaborator

Can't this be emulated using regex? What is the probability to find "false shebang" below the first line?

@joshgoebel
Copy link
Member Author

Maybe (although I'm not sure a rule can match only the first line), but the idea here would be to abstract the concept and encourage grammars to support it - if we thought it was a good idea. Hence making it easy with some smart defaults like:

{ shebang: "ruby" }

And we could build a smart regex to detect many common shebang patterns.

This could also be a plugin too though... I'll start a thread on hooks (which we'd need for useful plugins).

@joshgoebel joshgoebel changed the title Idea: Any thoughts on adding shebang lines as a concept? Plugin Idea: Shebang lines to auto-detect language Oct 26, 2019
@joshgoebel joshgoebel added plugin Specific plugin or plugin discussion and removed parser labels Oct 26, 2019
@egor-rogov
Copy link
Collaborator

although I'm not sure a rule can match only the first line

Have you ever seen something that can be mistaken to shebang in the middle of code? Is it worth to stick to the first line at all?

we could build a smart regex to detect many common shebang patterns

Why the core should be concerned with language specifics (say, #!/usr/bin/env python or #!/usr/bin/env python2 or#!/usr/bin/python3 )? I think that this knowledge must reside in the language grammar.

@joshgoebel
Copy link
Member Author

joshgoebel commented Dec 5, 2019

Why the core should be concerned with language specifics (say, #!/usr/bin/env python or #!/usr/bin/env python2 or#!/usr/bin/python3 )? I think that this knowledge must reside in the language grammar.

I meant that the key distinguishing part: python\d would be the grammar's responsibility but the core could deal with launch variants like /usr/bin vs /bin vs /opt/bin, /usr/bin/env, etc...

Closing this for now. This is the kind of thing a plug-in could/should handle.

@egor-rogov
Copy link
Collaborator

This is the kind of thing a plug-in could/should handle.

Agree.

@joshgoebel
Copy link
Member Author

The languages might still need to SUPPORT that plugin though by providing a shebang key or such, but we can circle back around to that when we've made more progress on plugins in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature plugin Specific plugin or plugin discussion
Projects
None yet
Development

No branches or pull requests

2 participants