Skip to content

Commit ef17e39

Browse files
committed
Verify push model diagnostics still function
If we’re connected to an older client that doesn’t support the pull model we must push them to it.
1 parent 170368f commit ef17e39

2 files changed

Lines changed: 122 additions & 1 deletion

File tree

packages/tailwindcss-language-server/tests/css/css-server.test.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { expect } from 'vitest'
22
import { css, defineTest } from '../../src/testing'
33
import { createClient } from '../utils/client'
4-
import { SymbolKind } from 'vscode-languageserver'
4+
import {
5+
PublishDiagnosticsNotification,
6+
PublishDiagnosticsParams,
7+
SymbolKind,
8+
} from 'vscode-languageserver'
59

610
defineTest({
711
name: '@custom-variant',
@@ -713,3 +717,46 @@ defineTest({
713717
expect(completionsF).toEqual({ isIncomplete: false, items: [] })
714718
},
715719
})
720+
721+
defineTest({
722+
name: 'Clients not supporting pull-model diagnostics will have them pushed',
723+
prepare: async ({ root }) => ({
724+
client: await createClient({
725+
server: 'css',
726+
root,
727+
capabilities(caps) {
728+
// Disable pull-model diagnostics
729+
delete caps.textDocument!.diagnostic
730+
},
731+
}),
732+
}),
733+
handle: async ({ client }) => {
734+
let didPublishDiagnostics = new Promise<PublishDiagnosticsParams>((resolve) => {
735+
client.conn.onNotification(PublishDiagnosticsNotification.type, resolve)
736+
})
737+
738+
// We open a document so a project gets initialized
739+
// This will cause the server to push diagnostics to the client
740+
let doc = await client.open({
741+
lang: 'tailwindcss',
742+
text: css`
743+
@idonotexist {
744+
color: red;
745+
}
746+
`,
747+
})
748+
749+
let result = await didPublishDiagnostics
750+
751+
expect(result.uri).toEqual(doc.uri.toString())
752+
expect(result.diagnostics).toEqual([
753+
{
754+
code: 'unknownAtRules',
755+
source: 'tailwindcss',
756+
message: 'Unknown at rule @idonotexist',
757+
severity: 2,
758+
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 12 } },
759+
},
760+
])
761+
},
762+
})

packages/tailwindcss-language-server/tests/diagnostics/diagnostics.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { css, defineTest, json } from '../../src/testing'
55
import { createClient } from '../utils/client'
66
import {
77
DocumentDiagnosticReport,
8+
PublishDiagnosticsNotification,
9+
PublishDiagnosticsParams,
810
} from 'vscode-languageserver'
911

1012
withFixture('basic', (c) => {
@@ -499,3 +501,75 @@ defineTest({
499501
])
500502
},
501503
})
504+
505+
defineTest({
506+
name: 'Clients not supporting pull-model diagnostics will have them pushed',
507+
fs: {
508+
'app.css': '@import "tailwindcss"',
509+
},
510+
prepare: async ({ root }) => ({
511+
client: await createClient({
512+
root,
513+
capabilities(caps) {
514+
// Disable pull-model diagnostics
515+
delete caps.textDocument!.diagnostic
516+
},
517+
}),
518+
}),
519+
handle: async ({ client }) => {
520+
let didPublishDiagnostics = new Promise<PublishDiagnosticsParams>((resolve) => {
521+
client.conn.onNotification(PublishDiagnosticsNotification.type, resolve)
522+
})
523+
524+
// We open a document so a project gets initialized
525+
// This will cause the server to push diagnostics to the client
526+
let doc = await client.open({
527+
lang: 'html',
528+
text: '<div class="underline line-through">',
529+
})
530+
531+
let result = await didPublishDiagnostics
532+
533+
expect(result.uri).toEqual(doc.uri.toString())
534+
expect(result.diagnostics).toMatchObject([
535+
{
536+
code: 'cssConflict',
537+
source: 'tailwindcss',
538+
message: "'underline' applies the same CSS properties as 'line-through'.",
539+
className: {
540+
className: 'underline',
541+
classList: {
542+
classList: 'underline line-through',
543+
},
544+
},
545+
otherClassNames: [
546+
{
547+
className: 'line-through',
548+
classList: {
549+
classList: 'underline line-through',
550+
},
551+
},
552+
],
553+
},
554+
{
555+
code: 'cssConflict',
556+
source: 'tailwindcss',
557+
message: "'line-through' applies the same CSS properties as 'underline'.",
558+
className: {
559+
className: 'line-through',
560+
classList: {
561+
classList: 'underline line-through',
562+
},
563+
},
564+
otherClassNames: [
565+
{
566+
className: 'underline',
567+
classList: {
568+
classList: 'underline line-through',
569+
},
570+
},
571+
],
572+
},
573+
])
574+
},
575+
})

0 commit comments

Comments
 (0)