From feb19371f43ea4cd7752f08a549d292f471d966f Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Tue, 28 Apr 2020 00:06:47 +0100 Subject: [PATCH] vary @tailwind completions based on version --- packages/tailwindcss-class-names/src/index.js | 1 + .../package-lock.json | 6 ++++ .../tailwindcss-language-server/package.json | 1 + .../src/providers/completionProvider.ts | 28 +++++++++++++------ .../src/util/state.ts | 1 + 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/tailwindcss-class-names/src/index.js b/packages/tailwindcss-class-names/src/index.js index e7a78ef..c87d271 100644 --- a/packages/tailwindcss-class-names/src/index.js +++ b/packages/tailwindcss-class-names/src/index.js @@ -93,6 +93,7 @@ export default async function getClassNames( const resolvedConfig = resolveConfig({ cwd, config }) return { + version, configPath, config: resolvedConfig, separator: typeof userSeperator === 'undefined' ? ':' : userSeperator, diff --git a/packages/tailwindcss-language-server/package-lock.json b/packages/tailwindcss-language-server/package-lock.json index 2bf6cb9..280ac2e 100644 --- a/packages/tailwindcss-language-server/package-lock.json +++ b/packages/tailwindcss-language-server/package-lock.json @@ -151,6 +151,12 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + }, "subarg": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/subarg/-/subarg-1.0.0.tgz", diff --git a/packages/tailwindcss-language-server/package.json b/packages/tailwindcss-language-server/package.json index 14590ad..dba232f 100644 --- a/packages/tailwindcss-language-server/package.json +++ b/packages/tailwindcss-language-server/package.json @@ -22,6 +22,7 @@ "emmet-helper": "0.0.1", "glob-exec": "^0.1.1", "line-column": "^1.0.2", + "semver": "^7.3.2", "tailwindcss-class-names": "0.0.1", "typescript": "^3.8.3", "vscode-languageserver": "^5.2.1", diff --git a/packages/tailwindcss-language-server/src/providers/completionProvider.ts b/packages/tailwindcss-language-server/src/providers/completionProvider.ts index 3dccb9f..53a1238 100644 --- a/packages/tailwindcss-language-server/src/providers/completionProvider.ts +++ b/packages/tailwindcss-language-server/src/providers/completionProvider.ts @@ -21,6 +21,7 @@ import { isValidLocationForEmmetAbbreviation } from '../util/isValidLocationForE import { getDocumentSettings } from '../util/getDocumentSettings' import { isJsContext } from '../util/js' import { naturalExpand } from '../util/naturalExpand' +import semver from 'semver' function completionsFromClassList( state: State, @@ -306,7 +307,7 @@ function provideCssHelperCompletions( } } -// TODO: vary items based on Tailwind version +// TODO: vary docs links based on Tailwind version function provideTailwindDirectiveCompletions( state: State, { position, textDocument }: CompletionParams @@ -329,14 +330,23 @@ function provideTailwindDirectiveCompletions( return { isIncomplete: false, items: [ - { - label: 'base', - documentation: { - kind: MarkupKind.Markdown, - value: - 'This injects Tailwind’s base styles and any base styles registered by plugins.\n\n[Tailwind CSS Documentation](https://tailwindcss.com/docs/functions-and-directives/#tailwind)', - }, - }, + semver.gte(state.version, '1.0.0-beta.1') + ? { + label: 'base', + documentation: { + kind: MarkupKind.Markdown, + value: + 'This injects Tailwind’s base styles and any base styles registered by plugins.\n\n[Tailwind CSS Documentation](https://tailwindcss.com/docs/functions-and-directives/#tailwind)', + }, + } + : { + label: 'preflight', + documentation: { + kind: MarkupKind.Markdown, + value: + 'This injects Tailwind’s base styles, which is a combination of Normalize.css and some additional base styles.\n\n[Tailwind CSS Documentation](https://v0.tailwindcss.com/docs/functions-and-directives/#tailwind)', + }, + }, { label: 'components', documentation: { diff --git a/packages/tailwindcss-language-server/src/util/state.ts b/packages/tailwindcss-language-server/src/util/state.ts index d41127d..401cedf 100644 --- a/packages/tailwindcss-language-server/src/util/state.ts +++ b/packages/tailwindcss-language-server/src/util/state.ts @@ -29,6 +29,7 @@ export type Settings = { export type State = null | { enabled: boolean + version?: string configPath?: string config?: any separator?: string