diff --git a/packages/tailwindcss-language-server/src/providers/hoverProvider.ts b/packages/tailwindcss-language-server/src/providers/hoverProvider.ts index 5ce792101bf49e000c10ce9bfb4523f44eda5827..7b4f9fee47cc4d06b91d1bb579cfbc45f4271182 100644 --- a/packages/tailwindcss-language-server/src/providers/hoverProvider.ts +++ b/packages/tailwindcss-language-server/src/providers/hoverProvider.ts @@ -4,73 +4,22 @@ import { getClassNameAtPosition, getClassNameParts, } from '../util/getClassNameAtPosition' -import { stringifyCss, stringifyConfigValue } from '../util/stringify' +import { stringifyCss } from '../util/stringify' const dlv = require('dlv') import escapeClassName from 'css.escape' import { isHtmlContext } from '../util/html' -import { isCssContext } from '../util/css' export function provideHover( state: State, params: TextDocumentPositionParams ): Hover { - return ( - provideClassNameHover(state, params) || provideCssHelperHover(state, params) - ) -} - -function provideCssHelperHover( - state: State, - { textDocument, position }: TextDocumentPositionParams -): Hover { - let doc = state.editor.documents.get(textDocument.uri) - - if (!isCssContext(doc, position)) return null - - const line = doc.getText({ - start: { line: position.line, character: 0 }, - end: { line: position.line + 1, character: 0 }, - }) - - const match = line.match( - /(?theme|config)\((?['"])(?[^)]+)\k\)/ - ) - - if (match === null) return null - - const startChar = match.index + 7 - const endChar = startChar + match.groups.key.length - - if (position.character < startChar || position.character >= endChar) { - return null - } - - let key = match.groups.key - .split(/(\[[^\]]+\]|\.)/) - .filter(Boolean) - .filter((x) => x !== '.') - .map((x) => x.replace(/^\[([^\]]+)\]$/, '$1')) - - if (key.length === 0) return null + let doc = state.editor.documents.get(params.textDocument.uri) - if (match.groups.helper === 'theme') { - key = ['theme', ...key] + if (isHtmlContext(doc, params.position)) { + return provideClassNameHover(state, params) } - const value = stringifyConfigValue(dlv(state.config, key)) - - if (value === null) return null - - return { - contents: { kind: 'plaintext', value }, - range: { - start: { line: position.line, character: startChar }, - end: { - line: position.line, - character: endChar, - }, - }, - } + return null } function provideClassNameHover( @@ -78,9 +27,6 @@ state: State, { textDocument, position }: TextDocumentPositionParams ): Hover { let doc = state.editor.documents.get(textDocument.uri) - - if (!isHtmlContext(doc, position)) return null - let hovered = getClassNameAtPosition(doc, position) if (!hovered) return null diff --git a/packages/tailwindcss-language-server/src/util/stringify.ts b/packages/tailwindcss-language-server/src/util/stringify.ts index e8b1b7d7bb5ba7eb3c4a25f4de5ed709e463c313..50b82a198d8244d4f162b0d075498c800f8ff6cd 100644 --- a/packages/tailwindcss-language-server/src/util/stringify.ts +++ b/packages/tailwindcss-language-server/src/util/stringify.ts @@ -9,7 +9,7 @@ .filter((y) => typeof y === 'string') .filter(Boolean) .join(', ') } - return null + return '' } export function stringifyCss(