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

Add VSCode Formatting Ability #22

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SamKomesarook
Copy link

@SamKomesarook SamKomesarook commented Oct 21, 2021

  • Initialise VSCode formatting ability
  • Add format-on-save
  • Tests
    Add regex to support following changes:
  • Spacing between args in the score
  • Spacing between args in the score instrs
  • Align tabs in rows of opcodes
  • Spacing between constants/flags

@SamKomesarook
Copy link
Author

SamKomesarook commented Oct 22, 2021

@kunstmusik @stekyne Hey ya'll, would be great to get a quick prelim opinion from you both about how I was going to go about this in regard to #21. This branch has a basic example of the first way formatting could work, whereby we (kinda hackishly) parse each line via string.contains rules, and format them that way.

Alternatively, we could add a lexer/parser lib like ANTLR, create a csound grammar, tokenise each program, and programmatically style it. This would be far more accurate, but might be overkill and would be a lot more complex.

Am I good to build out functionality via the first method?

@kunstmusik
Copy link
Member

@SamKomesarook I think formatters are going to be difficult no matter which way you go (e.g., regexes, custom parsing, parser, etc). In particular, there's different styles of csound code and some of it is contextual (i.e., aligning comments that are to the right of text block). There's also code that spans multiple lines via \ or using function-call syntax like

opcode(1, 
              2, 
              3)

One thing you might look at is Nate Whetsell's linter-csound package for Atom:

https://github.com/nwhetsell/linter-csound

We've definitely reused a bit of his work in this project. Another might be to look at implementing a plugin for Prettier, but that might be difficult.

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.

2 participants