Skip to content

Commit 0a2138d

Browse files
Treat <script lang=“tsx”> as containing JSX (#1175)
Fixes #1046
1 parent 72e97bc commit 0a2138d

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

packages/tailwindcss-language-server/tests/env/v4.test.js

+46-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'vitest'
22
import { init } from '../common'
33
import { HoverRequest } from 'vscode-languageserver'
4-
import { css, defineTest, js, json } from '../../src/testing'
4+
import { css, defineTest, html, js, json } from '../../src/testing'
55
import dedent from 'dedent'
66
import { CompletionRequest } from 'vscode-languageserver-protocol'
77

@@ -529,3 +529,48 @@ defineTest({
529529
})
530530
},
531531
})
532+
533+
defineTest({
534+
name: 'script + lang=tsx is treated as containing JSX',
535+
fs: {
536+
'app.css': css`
537+
@import 'tailwindcss';
538+
`,
539+
},
540+
prepare: async ({ root }) => ({ c: await init(root) }),
541+
handle: async ({ c }) => {
542+
let document = await c.openDocument({
543+
lang: 'vue',
544+
text: html`
545+
<script lang="tsx">
546+
function App() {
547+
return <div class="bg-black" />
548+
}
549+
</script>
550+
`,
551+
})
552+
553+
let hover = await c.sendRequest(HoverRequest.type, {
554+
textDocument: document,
555+
556+
// return <div class="bg-black" />
557+
// ^
558+
position: { line: 2, character: 24 },
559+
})
560+
561+
expect(hover).toEqual({
562+
contents: {
563+
language: 'css',
564+
value: dedent`
565+
.bg-black {
566+
background-color: var(--color-black) /* #000 = #000000 */;
567+
}
568+
`,
569+
},
570+
range: {
571+
start: { line: 2, character: 23 },
572+
end: { line: 2, character: 31 },
573+
},
574+
})
575+
},
576+
})

packages/tailwindcss-language-service/src/util/getLanguageBoundaries.ts

+8
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ export function getLanguageBoundaries(
197197
boundaries.push({ type: defaultType, range: { start: position, end: undefined } })
198198
} else if (token.type === 'lang') {
199199
boundaries[boundaries.length - 1].type = token.text
200+
201+
if (token.text === 'tsx') {
202+
boundaries[boundaries.length - 1].type = 'jsx'
203+
boundaries[boundaries.length - 1].lang = 'tsx'
204+
} else if (token.text === 'ts') {
205+
boundaries[boundaries.length - 1].type = 'js'
206+
boundaries[boundaries.length - 1].lang = 'ts'
207+
}
200208
} else if (token.type === 'type' && htmlScriptTypes.includes(token.text)) {
201209
boundaries[boundaries.length - 1].type = 'html'
202210
} else if (token.type === 'type' && jsxScriptTypes.includes(token.text)) {

packages/vscode-tailwindcss/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Prerelease
44

55
- Ensure hover information for `theme(…)` and other functions are shown when used in `@media` queries ([#1172](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1172))
6+
- Treat `<script lang=“tsx”>` as containing JSX ([#1175](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1175))
67

78
## 0.14.3
89

0 commit comments

Comments
 (0)