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

Shebang and Modeline Detection #47

Merged
merged 2 commits into from
Jun 18, 2023

Conversation

thecoolwinter
Copy link
Contributor

Description

Adds shebang and mode line detection to the CodeLanguage.detectLanguage function.

Shebangs are commonly used in scripting languages like python or ruby to allow the scripts to be run by the operating system by adding a "#! ..." line at the top of the file.

modelines are used by Emacs and Vim to configure editor functionality. Both have parameters for setting the file type.

CodeLanguage.detectLanguage can now detect both shebangs and modelines via the optional parameters prefixBuffer and suffixBuffer. It will check the prefix buffer for a valid shebang, and if found attempt to parse it. If no shebang is found, it will attempt to find and parse a valid modeline from either the prefix or suffix (Emacs modelines can be in the first or last 5 lines of the file).

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

Once the changes are propagated to CodeEditTextView and CodeEdit, opened files can detect shebangs and modelines:

Python detection:
Screenshot 2023-06-17 at 6 21 19 PM

Vim modeline detecting javascript:
Screenshot 2023-06-17 at 6 21 34 PM

Node:
Screenshot 2023-06-17 at 7 23 39 PM

Copy link
Contributor

@bombardier200 bombardier200 left a comment

Choose a reason for hiding this comment

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

LGTM!

@thecoolwinter thecoolwinter merged commit aa7d922 into CodeEditApp:main Jun 18, 2023
matthijseikelenboom pushed a commit to CodeEditApp/CodeEditSourceEditor that referenced this pull request Jun 18, 2023
## Updates to CodeEditLanguages:
- Add JSDoc Grammar in
CodeEditApp/CodeEditLanguages#45
- Shebang and Modeline Detection in
CodeEditApp/CodeEditLanguages#47
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.

🐞 Detect File Language Via shebang
3 participants