fix numbers being interpreted as colors

master
Brad Cornes 2020-05-03 20:52:14 +01:00
parent f809595659
commit 7978c9e6dc
2 changed files with 6 additions and 5 deletions

View File

@ -9,7 +9,7 @@ import {
} from 'vscode-languageserver' } from 'vscode-languageserver'
const dlv = require('dlv') const dlv = require('dlv')
import removeMeta from '../util/removeMeta' import removeMeta from '../util/removeMeta'
import { getColor, getColorFromString } from '../util/color' import { getColor, getColorFromValue } from '../util/color'
import { isHtmlContext } from '../util/html' import { isHtmlContext } from '../util/html'
import { isCssContext } from '../util/css' import { isCssContext } from '../util/css'
import { findLast, findJsxStrings, arrFindLast } from '../util/find' import { findLast, findJsxStrings, arrFindLast } from '../util/find'
@ -269,7 +269,7 @@ function provideCssHelperCompletions(
return { return {
isIncomplete: false, isIncomplete: false,
items: Object.keys(obj).map((item, index) => { items: Object.keys(obj).map((item, index) => {
let color = getColorFromString(obj[item]) let color = getColorFromValue(obj[item])
const replaceDot: boolean = const replaceDot: boolean =
item.indexOf('.') !== -1 && separator && separator.endsWith('.') item.indexOf('.') !== -1 && separator && separator.endsWith('.')
const insertClosingBrace: boolean = const insertClosingBrace: boolean =

View File

@ -61,11 +61,12 @@ export function getColor(
return { documentation: colorStrings[0] } return { documentation: colorStrings[0] }
} }
export function getColorFromString(str: string): string { export function getColorFromValue(value: unknown): string {
if (str === 'transparent') { if (typeof value !== 'string') return null
if (value === 'transparent') {
return 'rgba(0, 0, 0, 0.01)' return 'rgba(0, 0, 0, 0.01)'
} }
const color = new TinyColor(str) const color = new TinyColor(value)
if (color.isValid) { if (color.isValid) {
return color.toRgbString() return color.toRgbString()
} }