@@ -16,6 +16,9 @@ import camelCase from 'lodash.camelcase'
1616import { getCurrentWord } from './utils/get-current-word'
1717import { isColor } from './utils/is-color'
1818import { getSuggestions } from './suggestions'
19+ import { getCssVariable } from './utils/get-css-variable'
20+ import { getVariableInfo } from './utils/get-variable-info'
21+ import { getDocumentationLink } from './utils/get-documentation-link'
1922
2023// Create a connection for the server, using Node's IPC as a transport.
2124// Also include all preview / proposed LSP features.
@@ -152,19 +155,40 @@ connection.onHover(params => {
152155 if ( ! doc ) return null
153156
154157 const offset = doc . offsetAt ( params . position )
155- const currentWord = getCurrentWord ( doc , offset ) . slice ( 1 )
156- if ( ! currentWord ) return null
158+ const variableName = getCssVariable ( doc , offset )
157159
158- const currentVariable = null
159- // TODO: replace this with lookup from styleLint output
160- // flatten(Object.values(properties)).find(variable => variable.name === currentWord)
160+ if ( ! variableName ) return null
161+
162+ const variableInfo = getVariableInfo ( variableName )
163+
164+ if ( ! variableInfo ) return null
165+
166+ let markdown = `**\`${ variableInfo . name } \`**\n\n`
167+ markdown += `\n---\n\n`
168+
169+ markdown += `- **Kind:** [${ variableInfo . kind } ](https://primer.style/product/primitives/token-names/#${ variableInfo . kind } )\n`
170+ markdown += `- **Type:** ${ variableInfo . type } \n`
171+ markdown += `\n---\n\n`
161172
162- if ( currentVariable ) {
163- // TODO: would be nice to put docs link here as well
164- return { contents : currentVariable . value } as Hover
173+ if ( variableInfo . themeValues && Object . keys ( variableInfo . themeValues ) . length > 0 ) {
174+ for ( const [ themeName , value ] of Object . entries ( variableInfo . themeValues ) ) {
175+ markdown += `- **${ themeName } :** \`${ value } \`\n`
176+ }
177+ } else {
178+ markdown += `**Value:** \`${ variableInfo . value } \`\n\n`
165179 }
166180
167- return null
181+ markdown += `\n---\n\n`
182+
183+ const docLink = getDocumentationLink ( variableInfo . type )
184+ markdown += `[View documentation](${ docLink } )\n`
185+
186+ return {
187+ contents : {
188+ kind : 'markdown' ,
189+ value : markdown ,
190+ } ,
191+ } as Hover
168192} )
169193
170194connection . onDefinition ( params => {
0 commit comments