Skip to content

Support dot syntax for Tailwind CSS #97

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

Merged
merged 5 commits into from
Nov 10, 2017
Merged

Conversation

m2de
Copy link
Contributor

@m2de m2de commented Nov 8, 2017

I have tested this and all existing functionality is unaffected but when using @apply in css files it will automatically enforce dot syntax for all classes even when typing the class name without the leading dot.

@zignd
Copy link
Owner

zignd commented Nov 9, 2017

Good catch! But I guess we can improve it a bit. I was experimenting with your solution and figured out a few fields that can be set on the CompletionItem so that we can display the IntelliSense list of available class names without the . prefix. I also figured out how to make the completion work with or without the . but still inserting the class name with the period prefix once you accept the completion.

I'd like to you to apply this change over yours, and feel free to improve it if you want to:

diff --git a/src/extension.ts b/src/extension.ts
index ffe0db8..3dc6077 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -92,13 +92,16 @@ function provideCompletionItemsGenerator(languageSelector: string, classMatchReg
 
             // Creates a collection of CompletionItem based on the classes already cached
             let completionItems = uniqueDefinitions.map(definition => {
-                return new vscode.CompletionItem(`${classPrefix}${definition.className}`, vscode.CompletionItemKind.Variable);
+                const completionItem = new vscode.CompletionItem(`${definition.className}`, vscode.CompletionItemKind.Variable);
+                completionItem.filterText = `${classPrefix}${definition.className}`;
+                completionItem.insertText = `${classPrefix}${definition.className}`;
+                return completionItem;
             });
 
             // Removes from the collection the classes already specified on the class attribute
             for (let i = 0; i < classesOnAttribute.length; i++) {
                 for (let j = 0; j < completionItems.length; j++) {
-                    if (completionItems[j].label === classesOnAttribute[i]) {
+                    if (completionItems[j].insertText === classesOnAttribute[i]) {
                         completionItems.splice(j, 1);
                     }
                 }

m2de added 2 commits November 9, 2017 06:29
Because the insertedText might now differ from the class name label,
the inserted text should be used to determine if a class is already
inserted.
This update uses the prefix when the item is being inserted instead of
showing it within the auto-complete selection.
@m2de
Copy link
Contributor Author

m2de commented Nov 9, 2017

Nice one @zignd, thanks for that. This does make the behaviour feel more consistent with or without prefix. Changes pushed up.

@zignd
Copy link
Owner

zignd commented Nov 10, 2017

Sorry for taking this long to reply, I will merge the pull request then and release a new version in a moment.

@zignd zignd merged commit 445456d into zignd:master Nov 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants