diff --git a/package-lock.json b/package-lock.json index 06b59a27dd6b110985a9c4f584b84b9935ae2a83..91c1aca81ac946c1fd36e4fd59904914710f8008 100755 --- a/package-lock.json +++ b/package-lock.json @@ -4592,13 +4592,6 @@ } } }, "@babel/core": { - "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.8.3.tgz", - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz", - "integrity": "sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==", - "dev": true - }, - "@babel/core": { "@babel/helper-member-expression-to-functions": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index 2386c68b559746bed1a67f6dca26378ff6b9423f..a1634692f7d62a226b5372b12fbb0f85b322ed11 100755 --- a/package.json +++ b/package.json @@ -174,8 +174,6 @@ "globrex": "^0.1.2", "import-from": "^3.0.0", "jest": "^25.5.4", "url": "https://github.com/bradlc/vscode-tailwindcss/issues", - "description": "Tailwind CSS class name completion", - "url": "https://github.com/bradlc/vscode-tailwindcss/issues", "preview": true, "mitt": "^1.2.0", "mkdirp": "^1.0.3", diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts index 2a59c26ff93e9a9feb7a7d988c0015ea492549db..79f462ecee02d56ab76b780cdae993e5b66bca31 100644 --- a/src/lsp/providers/diagnosticsProvider.ts +++ b/src/lsp/providers/diagnosticsProvider.ts @@ -15,16 +15,13 @@ indexToPosition, } from '../util/find' import { getClassNameMeta } from '../util/getClassNameMeta' import { getClassNameDecls } from '../util/getClassNameDecls' -import { + state: State, import { State, Settings } from '../util/state' import { getDocumentSettings } from '../util/getDocumentSettings' const dlv = require('dlv') import semver from 'semver' import { getLanguageBoundaries } from '../util/getLanguageBoundaries' import { absoluteRange } from '../util/absoluteRange' -import { isObject } from '../../class-names/isObject' -import levenshtein from 'js-levenshtein' -import { stringToPath } from '../util/stringToPath' function getUnsupportedApplyDiagnostics( state: State, @@ -280,107 +277,32 @@ ) matches.forEach((match) => { let base = match.groups.helper === 'theme' ? ['theme'] : [] - let keys = stringToPath(match.groups.key) - let value = dlv(state.config, [...base, ...keys]) TextDocument, -} from 'vscode-languageserver' - const isValid = (val: unknown): boolean => - typeof val === 'string' || -import { equal } from '../../util/array' import { isCssDoc } from '../util/css' - val instanceof String || -import { import { isCssDoc } from '../util/css' import { - let otherDecls = getClassNameDecls(state, otherClassName.className) - - const stitch = (keys: string[]): string => - keys.reduce((acc, cur, i) => { - if (i === 0) return cur -import { getDocumentSettings } from '../util/getDocumentSettings' +import { State, Settings } from '../util/state' Range, - return `${acc}.${cur}` - }, '') - let message: string TextDocument, -} from 'vscode-languageserver' - if (isValid(value)) { -import { equal(meta.context, otherMeta.context) && - // wasn't any funny business. If you have a theme object: - // { msg: 'hello' } and do theme('msg.0') -const dlv = require('dlv') TextDocument, -import { findClassNamesInRange, - Diagnostic, - // indexes) - let valid = true - for (let i = keys.length - 1; i >= 0; i--) { - let key = keys[i] - let parentValue = dlv(state.config, [...base, ...keys.slice(0, i)]) - if (/^[0-9]+$/.test(key)) { -import semver from 'semver' TextDocument, -import { - break - } - } else if (!isObject(parentValue)) { - valid = false - break - } - } - if (!valid) { -import semver from 'semver' findClassNamesInRange, - Range, import { TextDocument, - findClassListsInDocument, - message = `'${match.groups.key}' does not exist in your theme config.` -import { getLanguageBoundaries } from '../util/getLanguageBoundaries' + findClassNamesInRange, TextDocument, TextDocument, -import { + findClassNamesInRange, Diagnostic, TextDocument, -} from '../util/find' - ]) - if (isObject(parentValue)) { - let validKeys = Object.keys(parentValue) - .filter((key) => isValid(parentValue[key])) -import { getLanguageBoundaries } from '../util/getLanguageBoundaries' findClassNamesInRange, - (a, b) => - levenshtein(keys[keys.length - 1], a) - - levenshtein(keys[keys.length - 1], b) - ) -import { absoluteRange } from '../util/absoluteRange' DiagnosticSeverity, TextDocument, -import { stringToPath } from '../util/stringToPath' - ...keys.slice(0, keys.length - 1), - validKeys[0], - ])}'?` - } - } -import { absoluteRange } from '../util/absoluteRange' findClassNamesInRange, - message = `'${match.groups.key}' was found but does not resolve to a string.` - - if (isObject(value)) { - let firstValidKey = Object.keys(value).find((key) => - isValid(value[key]) - ) -import { isObject } from '../../class-names/isObject' Range, - message += ` Did you mean '${stitch([...keys, firstValidKey])}'?` - } - } - } - - if (!message) { return null } @@ -402,8 +325,11 @@ severity: severity === 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning, + document: TextDocument, } from 'vscode-languageserver' - Range, + typeof value === 'undefined' + ? `'${match.groups.key}' does not exist in your theme config.` + : `'${match.groups.key}' was found but does not resolve to a string.`, }) }) }) diff --git a/src/lsp/util/stringToPath.ts b/src/lsp/util/stringToPath.ts deleted file mode 100644 index b06e1532e1903abb99361f1df64c01ad8bf408cf..0000000000000000000000000000000000000000 --- a/src/lsp/util/stringToPath.ts +++ /dev/null @@ -1,15 +0,0 @@ -// https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L6735-L6744 -let rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g -let reEscapeChar = /\\(\\)?/g - -export function stringToPath(string: string): string[] { - let result: string[] = [] - if (string.charCodeAt(0) === 46 /* . */) { - result.push('') - } - // @ts-ignore - string.replace(rePropName, (match, number, quote, subString) => { - result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match) - }) - return result -}