tidalcycles / vscode-tidalcycles

Support for TidalCycles in VSCode
GNU General Public License v3.0
35 stars 11 forks source link

Make custom grammar + restrict key combination to this grammar #26

Open KoltesDigital opened 4 years ago

KoltesDigital commented 4 years ago

Like for the Atom plugin, I suggest making your own grammar, which would merely extends Haskell. It also gives the opportunity to add autocompletion (#11).

My real issue: I regularly use Ctrl+Enter to make new lines, and I'm frustrated that this plugin squats this key combination for all languages.

kkeri commented 3 years ago

My real issue: I regularly use Ctrl+Enter to make new lines, and I'm frustrated that this plugin squats this key combination for all languages.

My issue too. Is it possible to make the shortcut conditional or language specific, so I could use Ctrl+Enter in my normal workflow to insert new lines?

yaxu commented 3 years ago

This plugin is short of maintainers, but PRs are very welcome.

kkeri commented 3 years ago

The same request goes for Shift+Enter too, what is used for multiline search and commit messages.

As @KoltesDigital suggested, you probably have to define your own language ID so you can make use of the editorLangId when clause context.

kkeri commented 3 years ago

@yaxu this seems to be a low hanging fruit. AFAIK adding a language ID to package.json then scoping relevant keyboard shortcuts to the language ID would resolve this issue. (Not the custom grammar part, but the OP noticed that his "real issue" is with keyboard shortcuts and solving it doesn't require a custom grammar.)

Although I found an unrelated problem. I checked out the code, ran tests and one of them failed. It leads to a rather complex constructor and is eventually related to the VS Code extension API. I'm not ready to dig into it at the moment. Will you accept a PR even if I don't fix the failing test case?

yaxu commented 3 years ago

I've not looked at the code at all, @kindohm might have a view on that

kindohm commented 3 years ago

@kkeri I would be happy to take a look at a PR, regardless of the state of the tests. I will take a look at the tests in the meantime.

I also want to make sure I understand the feature. Would this allow you to use the Tidal keyboard shortcuts in a .tidal file, and use the same keyboard shortcuts for a different purpose in a different type of file?

kkeri commented 3 years ago

@kindohm thanks for your feedback.

Yes, this feature would restrict shortcuts like Ctrl+Enter to .tidal files. Anywhere else, including editors for other languages, the source control view, the global search view etc. key bindings wouldn't be affected. Of course we should apply the restriction only to editor specific shortcuts.

Although there is something you should know about. I wrongly assumed that this can be done without making a custom grammar. However defining a new language ID for Tidal files conflicts with the suggested user setting that associates *.tidal files with Haskell. Ergo users have to choose between keyboard shortcuts and syntax highlight. It would be an undesirable side effect.

I can't invest into writing a full fledged Haskell syntax, but I can try to find one whose license is compatible with this project.

kindohm commented 3 years ago

@kkeri thanks for digging in to this.

I don't think we want to lose the syntax highlighting.

One workaround is to define your own keyboard shortcut to eval Tidal code. e.g. remap the "Eval Multiline" command to something other than Ctrl-Enter.

kkeri commented 3 years ago

@kindohm I agree, losing syntax highlight is not an option. I keep exploring, including filing an issue to the VS Code project. Possibly there are other embedded DSLs that could benefit from using the syntax highlighter of the parent language.

Until then I'll be using my own keyboard shortcuts.

kkeri commented 3 years ago

I found a possible workaround. It would allow for using Haskell highlighters as before, but it doesn't work as expected. I reported the issue to Microsoft. https://github.com/microsoft/vscode/issues/117190