-
Notifications
You must be signed in to change notification settings - Fork 4.3k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Custom class name completion contexts #7553
Comments
The |
Thank you @bradlc. Would it make sense to have those regex's as an array in the vscode settings? It'll be more extensible though. I think it's that what you meant with user settings. That's a good idea. |
Added!
Yes exactly. It would be a user setting. |
In my case I pull some tailwind class combinations into my own config objects. Could one solution be to simply add a comment above these variables and make it work? For example a
|
It would be great to have an option to use custom regex in the user settings. I'm using tailwind in React and Svelte as components props. So, have typesafe and the plugin hints with that would be awesome. |
Hey @bradlc, I'd be interested in trying to help with this issue. Where would you suggest I start digging into the code? |
@bradlc Can we get an update? @will-t-harris volunteered to help with this feature but has not yet gotten a response. Thanks in advance! |
I managed to have some success by using this regex in the following matchers:
https://github.com/tailwindlabs/tailwindcss-intellisense/blob/81446acdb382922c6989d74710305ebfbe68cd4e/src/lsp/providers/completionProvider.ts#L129 I haven't worked on VS Code extensions before, but you can try it locally by running I also don't know regex very well. This is just an experiment to figure out where to make the change. The goal, of course would be to find matches with existing regex and a list of expressions from settings, but I haven't experimented with that yet. One thing I've noticed is that this doesn't work, but should...
Any thoughts on fixing the backtick issue? Also, specific regex to match some of the example strings would be helpful! Hope this is helpful @will-t-harris! |
@wfischer42 @bradlc Looks like the lexer may not be matching on backticks here? |
Hey everyone. This setting allows you to specify additional places where completions should be triggered. Hovers and linting are not currently supported. Here is an example:
Each item in the
The container is the Both regular expressions must contain exactly one capture group. You can also specify a single regular expression for simpler containers that contain a single class list:
So if you wanted both of these new contexts your setting might look like this:
If anyone has any questions or feedback let me know 👍 Please note that this feature is experimental and could change at any time, and enabling it could affect the performance of the extension. |
@MartsTech this should work for React Native "tailwindCSS.experimental.classRegex": [
["tailwind|yourModule\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
], usage <View style={tailwind('m-2')} />
<View style={tailwind("m-2")} />
<View style={tailwind(`m-2`)} />
<View style={[styles.myStyle, tailwind("m-2")]} />
<View style={[{padding: 20}, tailwind("m-2")]} />
<View style={[tailwind(`m-2`), tailwind(`p-2`)]} /> |
@catalinmiron isn't working for me, I'm using the package tailwind-react-native-classnames and used the Regex you showed but doesn't work. Also, how can I make Regex that accepts a syntax like this: |
Sharing my config as well as I didn't find it mentioned before: I wanted to allow setting up classes in objects at the beginning of my components, like this: const fieldStyles = /*tw*/ {
default: {
label: 'py-2',
input: 'px-3 py-2 font-medium text-sm',
},
inline: {
label: 'py-2',
input: 'px-3 py-2 font-medium text-sm',
},
}; I didn't want to use a function or tagged string literal to avoid the need for an additional import, so I opted for a comment tag: "tailwindCSS.experimental.classRegex": [["/\\*tw\\*/ ([^;]*);", "'([^']*)'"]] |
Wanted to add for those that encounter a weird issue that codemonkey800 mentioned above, where autocompletion or tooltip stops functioning after a certain number of lines/characters, is actually due to the limit on the custom regex matchers |
I'm not good with regex development, any idea of what regex could match this: const InputFieldClasses = ctl(`
py-2
px-3
w-full
rounded-md
border
border-gray-300
focus:border-primary
focus:ring-1
focus:ring-primary
transition
focus:outline-none
`); Seems like this works: const InputFieldClasses = ctl(`
py-2
px-3
w-full
rounded-md
border
border-gray-300
focus:border-primary
focus:ring-1
focus:ring-primary
focus:outline-none
${someBooleanValue && "transition"}
${someBooleanValue ? "transition" : "some other class"}
`); Thanks! |
In my case I want to match every attribute ending with |
I am currently using Skeleton → https://github.com/dvtng/react-loading-skeleton/ It has |
hey, i didn't need to set it in the with that in mind, i'm also trying to make it work with the <div class="p-2 bg-white">
<h1>Hello world!</h1>
</div> can be written as [:div {:class "p-2 bg-white"}
[:h1 "Hello world!"]] now an alternative to writing the class in a hash map like the above is to specify it like so: [:div.p-2.bg-white
[:h1 "Hello world!"]] hence i tried setting the class regex to match this particular case as well as the fact that it works with the more usual, |
Does not work, unfortunately.
|
Hi, is there any config to achieve getting classname suggestion if using external file in array format. here's my current setup on using tailwind to avoid long classnames in a div. the component:
the style file:
|
I managed to make it work using className as a constant name
and then reference it like
|
Any solution for why it run only once? (see #7553) |
Hi, I guess that's not what I'm looking for, instead I'd like to have the suggestion list shown when I edited the |
it works in a separate file. The only thing the constant name should be "className". Then just import it into your component file. I know, it is a workaround, but it works for me) |
@anisimovv wow, thanks a lot! it works great! |
Is it possible to give a better explanation of how this regex works? My guess is that you do it like this:
I am writing css like this in may own dsl in scala: cls"bg-blue-200" I saw this in stack overflow for the
So I tried:
and it works, but I also need to add "includeLanguages" for scala, and map it to html like this:
I tried also to add "cls" to With a bit of documentation I think this really should be added as a non-experimental feature. It works really great for me! |
In (Drupal) TWIG templates, element classes are often defined as a variable this way: These expressions seem to work in both places for tailwind classes typed after an opening apostrophe: (I'm sure they can be improved, though.) |
For styled-components, where your code looks like this.
add this to your
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
There has been quite a few requests for the extension to support class name completions in contexts other than a standard class(Name) attribute.
Some examples:
tailwind.macro
andtwin.macro
(Add scrolling-touch/auto docs #46, Support for tailwind.macro in styled/emotion like tw...
or tw.div...
tailwindcss-intellisense#123):tailwind-rn
(Add@important
at-rule #99):tailwind-ppx
(Algolia's DocSearch ready! ✨ #120):I just wanted to consolidate all of these requests into a single issue that can be tracked more easily, as I think the solution could be the same for each of them.
I am reluctant to hard-code each of these cases into the extension because none of them are "official" methods of using Tailwind, and it may become a maintenance burden.
However, I am open to the idea of adding a user setting which would allow the definition of custom regular expressions. For example for
tailwind-rn
your regular expression might be something like:/\btailwind\([^)]+/ig
If you're interested in this feature feel free to "watch" this issue for updates, and post any comments/suggestions you may have.
The text was updated successfully, but these errors were encountered: