ChoicescriptIDE / main

32 stars 6 forks source link

Smart indent matches partial command matches #133

Open CareyJWilliams opened 2 years ago

CareyJWilliams commented 2 years ago

The basic-language support in ChoicescriptIDE/monaco-editor defines the "smart" indentation behaviour based on RegExes. Whilst implementing *ifid I noticed that it's incorrectly treated as a indenting command, because the 'if' part is matched. Unfortunately this seems to extend to invalid commands as well, for e.g.:

*ifishouldnotiwouldnot

Will trigger an automatic indent.

danspinola commented 2 years ago

I don't know if it'll help, but you can add a boundary anchor \b to the regex, forcing it to match the exact word:

      '))\\b.*\\s*$'
CareyJWilliams commented 2 years ago

I don't know if it'll help, but you can add a boundary anchor \b to the regex, forcing it to match the exact word:

      '))\\b.*\\s*$'

Thanks Dan, I haven't yet had a chance to look at this (and many other bugs) in any great detail. Your suggestion certainly sounds feasible though, and I'd be very happy to take a PR ;)

danspinola commented 2 years ago

Sure, but you'll have to walk me through how to build it so I can test before pushing. 😅

CareyJWilliams commented 2 years ago

Sure, but you'll have to walk me through how to build it so I can test before pushing. 😅

  1. Clone: https://github.com/ChoicescriptIDE/monaco-editor
  2. run npm install . in the directory
  3. Make any desired changes to src/basic-languages/choicescript/choicescript.ts
  4. Build with npm run release
  5. Run tests with npm run test (unit) and npm run smoketest (integration)

There aren't actually any unit tests for ChoiceScript yet, because Monarch unit tests are extremely painful to write and I'm expecting a lot of churn in this area. Run them anyway just to make sure something hasn't gone horribly wrong, and then use a web-server to perform manual testing: e.g. python -m http.server and navigate to test/manual/index.html in a browser. Select ChoiceScript as the language (and sample) and ensure you're using a cs-* theme (or things won't highlight correctly):

Screenshot 2022-05-02 at 15 36 50

There's documentation and a playground for Monarch (the grammar framework) here: https://microsoft.github.io/monaco-editor/monarch.html.

That should get you going, but feel free to shout if you've got any more specific questions.

Don't worry about the validation errors, they're from the language server (which is very buggy atm) rather than the tokenizer.