Skip to content

Commit

Permalink
add hover providers support for color hover variants
Browse files Browse the repository at this point in the history
  • Loading branch information
rrenildopereiraa committed Nov 4, 2024
1 parent b434819 commit 2062112
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ All notable changes to the Yumma CSS Intellisense will be documented in this fil

### Added

- Add breakpoints, modifiers completions and hovers
- Add support for `sm:*`, `md:*`, `lg:*`, `xxl:*` and `h:*` variants for hover providers.

### Changed

- Rename `yumma.ts` to `index.ts`
- Rename `yumma.ts` to `index.ts`.

### Removed

Expand Down
34 changes: 32 additions & 2 deletions src/providers/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ export const hoverProvider = vscode.languages.registerHoverProvider(
const range = new vscode.Range(start, end);
const word = document.getText(range);
const escapedWord = word.replace(/:/g, "\\:");

if (word.startsWith("h:")) {
const baseClass = word.slice(2);
const colorUtil = colorUtils.find((colorUtil) =>
baseClass.startsWith(colorUtil.classPrefix)
);

if (colorUtil) {
const color = baseColors.find(
(color) =>
`${colorUtil.classPrefix}${color.className}` === baseClass
);

if (color) {
const markdownString = new vscode.MarkdownString();

markdownString.appendCodeblock(
`.${escapedWord}:hover {\n ${colorUtil.classValue}: ${color.classValue};\n}`,
"css"
);

markdownString.appendMarkdown(
`\n\nThe [${word}](${baseUrl}${colorUtil.classLink}) color utility only applies when the element is hovered.`
);

markdownString.isTrusted = true;
return new vscode.Hover(markdownString, range);
}
}
}

const colorUtil = colorUtils.find((colorUtil) =>
word.startsWith(colorUtil.classPrefix)
Expand Down Expand Up @@ -121,7 +151,7 @@ export const hoverProvider = vscode.languages.registerHoverProvider(
"css"
);
markdownString.appendMarkdown(
`\n\nThe [${word}](${baseUrl}${utilClass.classLink}) utility only acts when you are hovering.`
`\n\nThe [${word}](${baseUrl}${utilClass.classLink}) utility only applies when the element is hovered.`
);
markdownString.isTrusted = true;

Expand Down Expand Up @@ -160,7 +190,7 @@ export const hoverProvider = vscode.languages.registerHoverProvider(
"css"
);
markdownString.appendMarkdown(
`\n\nThe [${word}](${baseUrl}${utilClass.classLink}) utility will only apply when the specified viewport is reached.`
`\n\nThe [${word}](${baseUrl}${utilClass.classLink}) utility only applies when the specified viewport is reached.`
);
markdownString.isTrusted = true;

Expand Down

0 comments on commit 2062112

Please sign in to comment.