-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support generics over multiple lines #21
base: main
Are you sure you want to change the base?
Conversation
Ah, this seems like it would be a bit challenging, since type parameters can also receive type parameters! I guess there was microsoft/TypeScript-TmLanguage#452, but it seems like the eventual commit microsoft/TypeScript-TmLanguage@632a9db didn't resolve the issue that is causing these difficulties here... Btw, I've asked about multi-line generic type parameter support with the |
I'm guessing the tokens that you're looking for are these ones:
I showed this overlay by using the |
Oh it looks like this may be a limitation of the TextMate tmLanguage single-line lookup: microsoft/TypeScript-TmLanguage#761 |
Yeah, the type parameter scopes are missing once the type parameters are spread across multiple lines. This may be possible to support with multiple regular expressions, but I don't feel like writing those myself. The way to go is probably to hook into the semantic highlighting if that's supported. |
Oh ok, wasn't aware that the semantic highlighting information was available to extensions / TS language service plugins. That would be the best, for sure! If that is complex, then writing regex is something that I have done a lot, and may be able to help there. |
Sorry, I wasn't clear. I don't know if extensions can hook into semantic highlighting. If they can, that may be the way to go.
The textmate grammar regex do somehow support function parameters over multiple lines. This makes me think that in theory they should be able to support type parameters over multiple lines, too. Those regexes are massive, though, e.g.:
I haven't written this myself. I copied it from the TypeScript grammar. Since the regex is so massive, I've even written regex-help.mjs to add/remove newlines/indentation to a regex to make it easier to read. It's been a while, so I don't fully remember. I think I copied the regular expression to a file, the did something like: # copy regex to file regex.txt
$ node ./regex-help.mjs prettify regex.txt >pretty.txt
# edit pretty.txt
$ node ./regex-help.mjs minify pretty.txt >new_regex.txt
# copy new regex and add to grammar The bits that I've learned about textmate grammar, I've tried to document here: https://github.com/frigus02/vscode-sql-tagged-template-literals#interesting-bits-about-the-grammar If you can come up with a regex that supports multi line type parameters I'd be happy to have a look! |
Any progress on this one? I ran into the same problem when implementing this project https://github.com/vlcn-io/typed-sql which generates TypeScript types from the query string in the template literal. E.g., cities-example.mov |
hmm, the function call case you linked (
Maybe this won't be too hard to get working based on that example. @frigus02 - is there a good way to iterate on these regexes as I change them? I have an idea on how to make it work but I'm not sure of a good testing flow other than:
which is really laborious |
This is my first time doing tmlanguage definitions but it seems like your regexes can be vastly simplified. I opened a PR with my changes. The |
Fixes #20
This may be harder to do that I had hoped:
As shown in the screenshot the textmate scopes don't seem to understand generics over multiple lines. That means we can't piggyback on those regexes and have to write our own. The reason for why they're still highlighted properly is semantic highlighting. Without that it looks like this: