Skip to content

Commit 3d57b3c

Browse files
committed
Merge branch 'diagnostics'
2 parents 647b556 + c8ece3f commit 3d57b3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1967
-231
lines changed

.github/autocomplete.png

256 KB
Loading

.github/banner.png

19.6 KB
Loading

.github/hover.png

235 KB
Loading

.github/linting.png

267 KB
Loading

.vscodeignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ contributing.md
88
node_modules/**
99
src/**
1010
tests/**
11-
img/**
11+
.github/**

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
## 0.4.0
4+
5+
- Added linting and quick fixes for both CSS and markup
6+
- Updated module resolution for compatibility with pnpm (#128)
7+
- The extension now ignores the `purge` option when extracting class names (#131)
8+
- Fixed hover offsets for class names which appear after interpolations
9+
10+
## 0.3.1
11+
12+
- Fixed class attribute completions not showing when using the following Pug syntax (#125):
13+
```
14+
div(class="")
15+
```
16+
- Fixed hover previews not showing when using a computed class attribute in Vue templates
17+
- Restore missing readme images
18+
- Update settings descriptions to use markdown
19+
320
## 0.3.0
421

522
### General

README.md

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,36 @@
1-
# Tailwind CSS IntelliSense
1+
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/diagnostics/.github/banner.png" alt="" />
22

3-
> [Tailwind CSS](https://tailwindcss.com/) class name completion for VS Code
3+
Tailwind CSS IntelliSense enhances the Tailwind development experience by providing Visual Studio Code users with advanced features such as autocomplete, syntax highlighting, and linting.
44

5-
**[Get it from the VS Code Marketplace →](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)**
5+
## Installation
66

7-
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/master/img/html.gif" alt="HTML autocompletion" width="750">
7+
**[Install via the Visual Studio Code Marketplace →](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)**
88

9-
## Requirements
10-
11-
This extension requires:
12-
- a `tailwind.config.js` file to be [present in your project folder](https://github.com/bradlc/vscode-tailwindcss/blob/master/package.json#L38). You can create it with `npx tailwind init`.
13-
- `tailwindcss` to be installed (present in project `node_modules/`)
9+
In order for the extension to activate you must have [`tailwindcss` installed](https://tailwindcss.com/docs/installation/#1-install-tailwind-via-npm) and a [Tailwind config file](https://tailwindcss.com/docs/installation/#3-create-your-tailwind-config-file-optional) named `tailwind.config.js` or `tailwind.js` in your workspace.
1410

1511
## Features
1612

17-
Tailwind CSS IntelliSense uses your projects Tailwind installation and configuration to provide suggestions as you type.
18-
19-
It also includes features that improve the overall Tailwind experience, including improved syntax highlighting, and CSS previews.
20-
21-
### HTML (including Vue, JSX, PHP etc.)
22-
23-
- [Class name suggestions, including support for Emmet syntax](#class-name-suggestions-including-support-for-emmet-syntax)
24-
- Suggestions include color previews where applicable, for example for text and background colors
25-
- They also include a preview of the actual CSS for that class name
26-
- [CSS preview when hovering over class names](#css-preview-when-hovering-over-class-names)
27-
28-
### CSS
29-
30-
- [Suggestions when using `@apply` and config helpers](#suggestions-when-using-apply-and-config)
31-
- Suggestions when using the `@screen` directive
32-
- Suggestions when using the `@variants` directive
33-
- [Improves syntax highlighting when using `@apply` and config helpers](#improves-syntax-highlighting-when-using-apply-and-config-helpers)
34-
35-
## Examples
13+
### Autocomplete
3614

37-
#### Class name suggestions, including support for Emmet syntax
15+
Intelligent suggestions for class names, as well as [CSS functions and directives](https://tailwindcss.com/docs/functions-and-directives/).
3816

39-
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/master/img/html.gif" alt="HTML autocompletion" width="750">
17+
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/diagnostics/.github/autocomplete.png" alt="" />
4018

41-
#### CSS preview when hovering over class names
19+
### Linting
4220

43-
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/master/img/html-hover.gif" alt="HTML hover preview" width="750">
21+
Highlights errors and potential bugs in both your CSS and your markup.
4422

45-
#### Suggestions when using `@apply` and config helpers
23+
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/diagnostics/.github/linting.png" alt="" />
4624

47-
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/master/img/css.gif" alt="CSS autocompletion" width="750">
25+
### Hover Preview
4826

49-
#### Improves syntax highlighting when using `@apply` and config helpers
27+
See the complete CSS for a Tailwind class name by hovering over it.
5028

51-
Before:
29+
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/diagnostics/.github/hover.png" alt="" />
5230

53-
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/master/img/css-highlighting-before.png" alt="CSS syntax highlighting before" width="400">
31+
### CSS Syntax Highlighting
5432

55-
After:
56-
57-
<img src="https://raw.githubusercontent.com/bradlc/vscode-tailwindcss/master/img/css-highlighting-after.png" alt="CSS syntax highlighting after" width="400">
33+
Provides syntax definitions so that Tailwind features are highlighted correctly.
5834

5935
## Settings
6036

@@ -70,7 +46,7 @@ This setting allows you to add additional language support. The key of each entr
7046
}
7147
```
7248

73-
### `tailwindcss.emmetCompletions`
49+
### `tailwindCSS.emmetCompletions`
7450

7551
Enable completions when using [Emmet](https://emmet.io/)-style syntax, for example `div.bg-red-500.uppercase`. **Default: `false`**
7652

@@ -79,3 +55,43 @@ Enable completions when using [Emmet](https://emmet.io/)-style syntax, for examp
7955
"tailwindCSS.emmetCompletions": true
8056
}
8157
```
58+
59+
### `tailwindCSS.validate`
60+
61+
Enable linting. Rules can be configured individually using the `tailwindcss.lint` settings:
62+
63+
- `ignore`: disable lint rule entirely
64+
- `warning`: rule violations will be considered "warnings," typically represented by a yellow underline
65+
- `error`: rule violations will be considered "errors," typically represented by a red underline
66+
67+
#### `tailwindCSS.lint.invalidScreen`
68+
69+
Unknown screen name used with the [`@screen` directive](https://tailwindcss.com/docs/functions-and-directives/#screen). **Default: `error`**
70+
71+
#### `tailwindCSS.lint.invalidVariant`
72+
73+
Unknown variant name used with the [`@variants` directive](https://tailwindcss.com/docs/functions-and-directives/#variants). **Default: `error`**
74+
75+
#### `tailwindCSS.lint.invalidTailwindDirective`
76+
77+
Unknown value used with the [`@tailwind` directive](https://tailwindcss.com/docs/functions-and-directives/#tailwind). **Default: `error`**
78+
79+
#### `tailwindCSS.lint.invalidApply`
80+
81+
Unsupported use of the [`@apply` directive](https://tailwindcss.com/docs/functions-and-directives/#apply). **Default: `error`**
82+
83+
#### `tailwindCSS.lint.invalidConfigPath`
84+
85+
Unknown or invalid path used with the [`theme` helper](https://tailwindcss.com/docs/functions-and-directives/#theme). **Default: `error`**
86+
87+
#### `tailwindCSS.lint.cssConflict`
88+
89+
Class names on the same HTML element which apply the same CSS property or properties. **Default: `warning`**
90+
91+
## Troubleshooting
92+
93+
If you’re having issues getting the IntelliSense features to activate, there are a few things you can check:
94+
95+
- Ensure that you have a Tailwind config file in your workspace and that this is named `tailwind.config.js` or `tailwind.js`. Check out the Tailwind documentation for details on [creating a config file](https://tailwindcss.com/docs/installation/#3-create-your-tailwind-config-file-optional).
96+
- Ensure that the `tailwindcss` module is installed in your workspace, via `npm`, `yarn`, or `pnpm`. Tailwind CSS IntelliSense does not currently support Yarn Plug'n'Play.
97+
- If you installed `tailwindcss` or created your config file while your project was already open in Visual Studio Code you may need to reload the editor. You can either restart VS Code entirely, or use the `Developer: Reload Window` command which can be found in the command palette.

img/css-highlighting-after.png

-33.6 KB
Binary file not shown.

img/css-highlighting-before.png

-32.5 KB
Binary file not shown.

img/css.gif

-1.4 MB
Binary file not shown.

img/html-hover.gif

-592 KB
Binary file not shown.

img/html.gif

-2.77 MB
Binary file not shown.

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"name": "vscode-tailwindcss",
33
"displayName": "Tailwind CSS IntelliSense",
4-
"description": "Tailwind CSS class name completion",
4+
"description": "Intelligent Tailwind CSS tooling for VS Code",
55
"preview": true,
66
"author": "Brad Cornes <hello@bradley.dev>",
77
"license": "MIT",
88
"version": "0.3.1",
9-
"homepage": "https://github.com/bradlc/vscode-tailwindcss",
9+
"homepage": "https://github.com/tailwindcss/intellisense",
1010
"bugs": {
11-
"url": "https://github.com/bradlc/vscode-tailwindcss/issues",
11+
"url": "https://github.com/tailwindcss/intellisense/issues",
1212
"email": "hello@bradley.dev"
1313
},
1414
"repository": {
1515
"type": "git",
16-
"url": "https://github.com/bradlc/vscode-tailwindcss.git"
16+
"url": "https://github.com/tailwindcss/intellisense.git"
1717
},
1818
"publisher": "bradlc",
1919
"keywords": [
@@ -28,10 +28,11 @@
2828
"vscode": "^1.33.0"
2929
},
3030
"categories": [
31+
"Linters",
3132
"Other"
3233
],
3334
"galleryBanner": {
34-
"color": "#f1f5f8"
35+
"color": "#f9fafb"
3536
},
3637
"icon": "media/icon.png",
3738
"activationEvents": [
@@ -69,6 +70,78 @@
6970
},
7071
"default": {},
7172
"markdownDescription": "Enable features in languages that are not supported by default. Add a mapping here between the new language and an already supported language.\n E.g.: `{\"plaintext\": \"html\"}`"
73+
},
74+
"tailwindCSS.validate": {
75+
"type": "boolean",
76+
"default": true,
77+
"markdownDescription": "Enable linting",
78+
"scope": "language-overridable"
79+
},
80+
"tailwindCSS.lint.cssConflict": {
81+
"type": "string",
82+
"enum": [
83+
"ignore",
84+
"warning",
85+
"error"
86+
],
87+
"default": "warning",
88+
"markdownDescription": "Class names on the same HTML element which apply the same CSS property or properties",
89+
"scope": "language-overridable"
90+
},
91+
"tailwindCSS.lint.invalidApply": {
92+
"type": "string",
93+
"enum": [
94+
"ignore",
95+
"warning",
96+
"error"
97+
],
98+
"default": "error",
99+
"markdownDescription": "Unsupported use of the [`@apply` directive](https://tailwindcss.com/docs/functions-and-directives/#apply)",
100+
"scope": "language-overridable"
101+
},
102+
"tailwindCSS.lint.invalidScreen": {
103+
"type": "string",
104+
"enum": [
105+
"ignore",
106+
"warning",
107+
"error"
108+
],
109+
"default": "error",
110+
"markdownDescription": "Unknown screen name used with the [`@screen` directive](https://tailwindcss.com/docs/functions-and-directives/#screen)",
111+
"scope": "language-overridable"
112+
},
113+
"tailwindCSS.lint.invalidVariant": {
114+
"type": "string",
115+
"enum": [
116+
"ignore",
117+
"warning",
118+
"error"
119+
],
120+
"default": "error",
121+
"markdownDescription": "Unknown variant name used with the [`@variants` directive](https://tailwindcss.com/docs/functions-and-directives/#variants)",
122+
"scope": "language-overridable"
123+
},
124+
"tailwindCSS.lint.invalidConfigPath": {
125+
"type": "string",
126+
"enum": [
127+
"ignore",
128+
"warning",
129+
"error"
130+
],
131+
"default": "error",
132+
"markdownDescription": "Unknown or invalid path used with the [`theme` helper](https://tailwindcss.com/docs/functions-and-directives/#theme)",
133+
"scope": "language-overridable"
134+
},
135+
"tailwindCSS.lint.invalidTailwindDirective": {
136+
"type": "string",
137+
"enum": [
138+
"ignore",
139+
"warning",
140+
"error"
141+
],
142+
"default": "error",
143+
"markdownDescription": "Unknown value used with the [`@tailwind` directive](https://tailwindcss.com/docs/functions-and-directives/#tailwind)",
144+
"scope": "language-overridable"
72145
}
73146
}
74147
}
@@ -93,6 +166,7 @@
93166
"chokidar": "^3.3.1",
94167
"concurrently": "^5.1.0",
95168
"css.escape": "^1.5.1",
169+
"detect-indent": "^6.0.0",
96170
"dlv": "^1.1.3",
97171
"dset": "^2.0.1",
98172
"esm": "^3.2.25",
@@ -111,6 +185,7 @@
111185
"resolve-from": "^5.0.0",
112186
"rimraf": "^3.0.2",
113187
"semver": "^7.3.2",
188+
"sift-string": "0.0.2",
114189
"stack-trace": "0.0.10",
115190
"terser": "^4.6.12",
116191
"tiny-invariant": "^1.1.0",

src/class-names/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ export default async function getClassNames(
141141
postcss,
142142
browserslist,
143143
}),
144+
modules: {
145+
tailwindcss,
146+
postcss,
147+
},
144148
}
145149
}
146150

src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
OutputChannel,
1212
WorkspaceFolder,
1313
Uri,
14+
ConfigurationScope,
1415
} from 'vscode'
1516
import {
1617
LanguageClient,
@@ -22,6 +23,7 @@ import { DEFAULT_LANGUAGES } from './lib/languages'
2223
import isObject from './util/isObject'
2324
import { dedupe, equal } from './util/array'
2425
import { createEmitter } from './lib/emitter'
26+
import { onMessage } from './lsp/notifications'
2527

2628
const CLIENT_ID = 'tailwindcss-intellisense'
2729
const CLIENT_NAME = 'Tailwind CSS IntelliSense'
@@ -150,6 +152,9 @@ export function activate(context: ExtensionContext) {
150152
client.onReady().then(() => {
151153
let emitter = createEmitter(client)
152154
registerConfigErrorHandler(emitter)
155+
onMessage(client, 'getConfiguration', async (scope) => {
156+
return Workspace.getConfiguration('tailwindCSS', scope)
157+
})
153158
})
154159

155160
client.start()

src/lib/emitter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import mitt from 'mitt'
22
import { LanguageClient } from 'vscode-languageclient'
33
import crypto from 'crypto'
4+
import { Connection } from 'vscode-languageserver'
45

56
export interface NotificationEmitter {
67
on: (name: string, handler: (args: any) => void) => void
78
off: (name: string, handler: (args: any) => void) => void
89
emit: (name: string, args: any) => Promise<any>
910
}
1011

11-
export function createEmitter(client: LanguageClient): NotificationEmitter {
12+
export function createEmitter(
13+
client: LanguageClient | Connection
14+
): NotificationEmitter {
1215
const emitter = mitt()
1316
const registered: string[] = []
1417

@@ -26,7 +29,7 @@ export function createEmitter(client: LanguageClient): NotificationEmitter {
2629
emitter.off(name, handler)
2730
}
2831

29-
const emit = (name: string, params: any) => {
32+
const emit = (name: string, params: Record<string, any> = {}) => {
3033
return new Promise((resolve, _reject) => {
3134
const id = crypto.randomBytes(16).toString('hex')
3235
on(`${name}Response`, (result) => {

src/lsp/notifications.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Connection } from 'vscode-languageserver'
2+
import { LanguageClient } from 'vscode-languageclient'
23

34
export function onMessage(
4-
connection: Connection,
5+
connection: LanguageClient | Connection,
56
name: string,
6-
handler: (params: any) => any
7+
handler: (params: any) => Thenable<Record<string, any>>
78
): void {
89
connection.onNotification(`tailwindcss/${name}`, async (params: any) => {
910
const { _id, ...rest } = params

0 commit comments

Comments
 (0)