Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add initial css helper hover
Brad Cornes <brad@parall.ax>
4 years ago
2 changed files, 61 additions(+), 3 deletions(-)
M packages/tailwindcss-language-server/src/providers/hoverProvider.ts -> packages/tailwindcss-language-server/src/providers/hoverProvider.ts
diff --git a/packages/tailwindcss-language-server/src/providers/hoverProvider.ts b/packages/tailwindcss-language-server/src/providers/hoverProvider.ts
index 7b4f9fee47cc4d06b91d1bb579cfbc45f4271182..5ce792101bf49e000c10ce9bfb4523f44eda5827 100644
--- a/packages/tailwindcss-language-server/src/providers/hoverProvider.ts
+++ b/packages/tailwindcss-language-server/src/providers/hoverProvider.ts
@@ -4,26 +4,81 @@ import {
   getClassNameAtPosition,
   getClassNameParts,
 } from '../util/getClassNameAtPosition'
-import { stringifyCss } from '../util/stringify'
+import { stringifyCss, stringifyConfigValue } 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
 import { State } from '../util/state'
+import { State } from '../util/state'
+  const line = doc.getText({
+    start: { line: position.line, character: 0 },
+    end: { line: position.line + 1, character: 0 },
+  getClassNameParts,
 } from '../util/getClassNameAtPosition'
 
+  const match = line.match(
+    /(?<helper>theme|config)\((?<quote>['"])(?<key>[^)]+)\k<quote>\)/
+  )
 import { State } from '../util/state'
+import { State } from '../util/state'
+  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)
+} from '../util/getClassNameAtPosition'
 import { stringifyCss } from '../util/stringify'
-import { State } from '../util/state'
+} from '../util/getClassNameAtPosition'
 const dlv = require('dlv')
 import { State } from '../util/state'
+import { State } from '../util/state'
+} from '../util/getClassNameAtPosition'
 import escapeClassName from 'css.escape'
 
+  if (match.groups.helper === 'theme') {
+    key = ['theme', ...key]
+  }
+
+import { stringifyCss } from '../util/stringify'
 import { Hover, TextDocumentPositionParams } from 'vscode-languageserver'
+
+  if (value === null) return null
+
+  return {
+    contents: { kind: 'plaintext', value },
+    range: {
+      start: { line: position.line, character: startChar },
+      end: {
+        line: position.line,
+        character: endChar,
+const dlv = require('dlv')
+    },
+  }
 }
 
 function provideClassNameHover(
@@ -31,6 +86,9 @@   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
 
M packages/tailwindcss-language-server/src/util/stringify.ts -> packages/tailwindcss-language-server/src/util/stringify.ts
diff --git a/packages/tailwindcss-language-server/src/util/stringify.ts b/packages/tailwindcss-language-server/src/util/stringify.ts
index 50b82a198d8244d4f162b0d075498c800f8ff6cd..e8b1b7d7bb5ba7eb3c4a25f4de5ed709e463c313 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 ''
+  return null
 }
 
 export function stringifyCss(