Skip to content

Refactor language service setup and usage #1271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Run tests
- name: Run service tests
working-directory: packages/tailwindcss-language-service
run: pnpm run build && pnpm run test

- name: Run server tests
working-directory: packages/tailwindcss-language-server
run: |
cd packages/tailwindcss-language-server &&
pnpm run build &&
pnpm run test
pnpm run build && pnpm run test
27 changes: 13 additions & 14 deletions packages/tailwindcss-language-server/src/lsp/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import type { TextDocument } from 'vscode-languageserver-textdocument'
import type { State } from '@tailwindcss/language-service/src/util/state'
import { doValidate } from '@tailwindcss/language-service/src/diagnostics/diagnosticsProvider'
import isExcluded from '../util/isExcluded'
import type { LanguageService } from '@tailwindcss/language-service/src/service'

export async function provideDiagnostics(state: State, document: TextDocument) {
if (await isExcluded(state, document)) {
clearDiagnostics(state, document)
} else {
state.editor?.connection.sendDiagnostics({
uri: document.uri,
diagnostics: await doValidate(state, document),
})
}
}
export async function provideDiagnostics(
service: LanguageService,
state: State,
document: TextDocument,
) {
if (!state.enabled) return
let doc = await service.open(document.uri)
let report = await doc?.diagnostics()

// No need to send diagnostics if the document is unchanged
if (report.kind === 'unchanged') return

export function clearDiagnostics(state: State, document: TextDocument): void {
state.editor?.connection.sendDiagnostics({
uri: document.uri,
diagnostics: [],
diagnostics: report?.items ?? [],
})
}
Loading