-
Notifications
You must be signed in to change notification settings - Fork 689
Fix(frontend): auto completion and render of tailwind classes in app editor #5817
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -467,33 +467,46 @@ | |||||
} | ||||||
|
||||||
function addTailwindClassCompletions() { | ||||||
// Define a custom word definition for Tailwind classes | ||||||
languages.setMonarchTokensProvider('tailwindcss', { | ||||||
tokenizer: { | ||||||
root: [[/[a-zA-Z0-9-]+/, 'tailwind-class']] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The regex pattern Consider updating the pattern to:
This would ensure proper recognition of the full range of Tailwind class syntax during autocompletion.
Suggested change
Spotted by Diamond |
||||||
} | ||||||
}) | ||||||
|
||||||
languages.registerCompletionItemProvider('tailwindcss', { | ||||||
triggerCharacters: ['-'], | ||||||
provideCompletionItems: function (model, position, context, token) { | ||||||
const word = model.getWordUntilPosition(position) | ||||||
const wordUntilPosition = model.getWordUntilPosition(position) | ||||||
const lineContent = model.getLineContent(position.lineNumber) | ||||||
|
||||||
// Get the text from the start of the line to the cursor | ||||||
const textUntilPosition = lineContent.substring(0, position.column - 1) | ||||||
// Find the last space before the cursor | ||||||
const lastSpaceIndex = textUntilPosition.lastIndexOf(' ') | ||||||
const startColumn = lastSpaceIndex === -1 ? 1 : lastSpaceIndex + 2 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The calculation
Suggested change
Spotted by Diamond |
||||||
|
||||||
const range = { | ||||||
startLineNumber: position.lineNumber, | ||||||
startColumn: word.startColumn, | ||||||
startColumn: startColumn, | ||||||
endLineNumber: position.lineNumber, | ||||||
endColumn: word.endColumn | ||||||
endColumn: position.column | ||||||
} | ||||||
|
||||||
if (word && word.word) { | ||||||
const currentWord = word.word | ||||||
|
||||||
const suggestions = tailwindClasses | ||||||
.filter((className) => className.includes(currentWord)) | ||||||
.map((className) => ({ | ||||||
label: className, | ||||||
kind: languages.CompletionItemKind.Class, | ||||||
insertText: className, | ||||||
documentation: 'Custom CSS class', | ||||||
range: range | ||||||
})) | ||||||
const currentWord = wordUntilPosition.word | ||||||
|
||||||
return { suggestions } | ||||||
} | ||||||
const suggestions = tailwindClasses | ||||||
.filter((className) => className.includes(currentWord)) | ||||||
.map((className) => ({ | ||||||
label: className, | ||||||
kind: languages.CompletionItemKind.Class, | ||||||
insertText: className, | ||||||
documentation: 'Tailwind CSS class', | ||||||
range: range, | ||||||
preselect: true | ||||||
})) | ||||||
|
||||||
return { suggestions: [] } | ||||||
return { suggestions } | ||||||
} | ||||||
}) | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider updating the Monarch token regex to include additional characters (like
:
) for Tailwind variant syntax (e.g.md:text-center
).