-
Notifications
You must be signed in to change notification settings - Fork 38
Incorrect syntax highlighting with yats.vim #86
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
Comments
Thanks for your feedback, will take a look in my spare time. |
@sheerun I can reproduce this issue without |
@sheerun Closing this issue since it's not an issue of this plugin. |
@yuezk, @sheerun: The indenting is an issue with const head = <T>(arr: T[]): T => arr[0] I suggest reopening and renaming this issue or alternatively creating a new issue that tracks the problematic highlighting. |
@sQVe If that's issue with yats.vim maybe you'll open an issue there? |
@sQVe OK, I see. I'll reopen this issue. |
I think the highlighting of generic functions is an issue here around how a |
Created a simple repo that reproduces this issue both for |
My best guess at a fix would be an edit in the following lines: vim-jsx-pretty/after/syntax/jsx_pretty.vim Lines 38 to 41 in c3dc920
But it's tough for me to be sure; the regex is giving me a bit of a headache 😅 |
@davidroeca Thanks for your investigation. This regex is indeed complex because we have to use it to detect the jsx tag start boundaries and the boundaries vary greatly. Currently, it cannot be simplified because this plugin has no assumption on which plugin ( I will try to fix this issue in a few days. |
I think this issue is hard to fix and I'm trying to explain it. Vim syntax highlighting has its limitation because it uses the regex to match the syntax and it's a static match, for most of the cases, this mechanism works well since most of the language syntax is unambiguous. But the test case in this issue is ambiguous. const head = <T>(arr: T[]): T => arr[0]
A possible solution is that we make an assumption that if The workaround is to use the function expression: const head = function <T>(arr: T[]): T { return arr[0]; } or use the trailing comma after the type const head = <T,>(arr: T[]): T => arr[0] Reference: microsoft/TypeScript#15713 |
``` const head = <T,>(arr: T[]): T => arr[0] ``` #86
``` const head = <T,>(arr: T[]): T => arr[0] ``` #86
@yuezk I understand. Thank you for diving deep into this issue 🙏 I mostly write JavaScript / TypeScript in a functional manner so the likelyhood of me writing functions like It would be interesting to know how common the I vote to fixing the generic type case even though it might introduce a very specific issue with JSX. |
@sQVe You can update this plugin and use the workaround by adding a trailing comma after const head = <T,>(arr: T[]): T => arr[0] |
I also agree that Also good indicator is that it's capital case e.g. in my codebase there's |
Using a capital letter for a generic type is considered good practice but it is not required. The following snippet is valid TypeScript: const head = <t>(arr: t[]): t => arr[0]
// or even
const head = <span>(arr: span[]): span => arr[0] |
Then it's at least good clue :) |
@yuezk thanks for taking the time here! I’m good with either approach as long as what correctly highlights is compatible with what linters and prettier expect. I know prettier removes unnecessary parens. I’d assume most standard linter configs would complain about lower-case type variables. |
Hi, @sheerun @sQVe @davidroeca @tsuyoshicho This issue should have been fixed in #99. Update this plugin and take a look, Thanks. |
Uh oh!
There was an error while loading. Please reload this page.
.vimrc used:
When I have file with following contents:
And then press enter, next line is wrongly indented. Could you please fix this?
Reference: sheerun/vim-polyglot#428
The text was updated successfully, but these errors were encountered: