update css helper hovers

master
Brad Cornes 2021-07-12 15:23:16 +01:00
parent 114284865d
commit 569635067c
4 changed files with 21 additions and 12 deletions

View File

@ -27,6 +27,7 @@
"postcss-selector-parser": "6.0.2", "postcss-selector-parser": "6.0.2",
"semver": "7.3.2", "semver": "7.3.2",
"sift-string": "0.0.2", "sift-string": "0.0.2",
"stringify-object": "3.3.0",
"vscode-emmet-helper-bundled": "0.0.1", "vscode-emmet-helper-bundled": "0.0.1",
"vscode-languageclient": "7.0.0", "vscode-languageclient": "7.0.0",
"vscode-languageserver": "7.0.0", "vscode-languageserver": "7.0.0",

View File

@ -20,7 +20,7 @@ function pathToString(path: string | string[]): string {
}, '') }, '')
} }
function validateConfigPath( export function validateConfigPath(
state: State, state: State,
path: string | string[], path: string | string[],
base: string[] = [] base: string[] = []

View File

@ -7,6 +7,7 @@ import { findClassNameAtPosition } from './util/find'
import { validateApply } from './util/validateApply' import { validateApply } from './util/validateApply'
import { getClassNameParts } from './util/getClassNameAtPosition' import { getClassNameParts } from './util/getClassNameAtPosition'
import * as jit from './util/jit' import * as jit from './util/jit'
import { validateConfigPath } from './diagnostics/getInvalidConfigPathDiagnostics'
export async function doHover( export async function doHover(
state: State, state: State,
@ -50,12 +51,14 @@ function provideCssHelperHover(state: State, document: TextDocument, position: P
key = ['theme', ...key] key = ['theme', ...key]
} }
const value = stringifyConfigValue(dlv(state.config, key)) const value = validateConfigPath(state, key).isValid
? stringifyConfigValue(dlv(state.config, key))
: null
if (value === null) return null if (value === null) return null
return { return {
contents: { kind: 'plaintext', value }, contents: { kind: 'markdown', value: ['```plaintext', value, '```'].join('\n') },
range: { range: {
start: { line: position.line, character: startChar }, start: { line: position.line, character: startChar },
end: { end: {

View File

@ -3,17 +3,22 @@ const dlv = require('dlv')
import escapeClassName from 'css.escape' import escapeClassName from 'css.escape'
import { ensureArray } from './array' import { ensureArray } from './array'
import { remToPx } from './remToPx' import { remToPx } from './remToPx'
import stringifyObject from 'stringify-object'
import isObject from './isObject'
export function stringifyConfigValue(x: any): string { export function stringifyConfigValue(x: any): string {
if (typeof x === 'string') return x if (isObject(x)) return `${Object.keys(x).length} values`
if (typeof x === 'number') return x.toString() if (typeof x === 'function') return 'ƒ'
if (Array.isArray(x)) { return stringifyObject(x, {
return x inlineCharacterLimit: Infinity,
.filter((y) => typeof y === 'string') singleQuotes: false,
.filter(Boolean) transform: (obj, prop, originalResult) => {
.join(', ') if (typeof obj[prop] === 'function') {
return 'ƒ'
} }
return null return originalResult
},
})
} }
export function stringifyCss( export function stringifyCss(