|
1 | 1 | import * as vscode from 'vscode'
|
2 | 2 | import path from 'node:path'
|
3 | 3 | import { type Middleware } from 'vscode-languageclient'
|
4 |
| -import { getCSSLanguageService } from 'vscode-css-languageservice' |
| 4 | +import { |
| 5 | + getCSSLanguageService, |
| 6 | + getLESSLanguageService, |
| 7 | + getSCSSLanguageService, |
| 8 | + type LanguageService, |
| 9 | +} from 'vscode-css-languageservice' |
5 | 10 |
|
6 |
| -getCSSLanguageService() |
| 11 | +const cssLangService = getCSSLanguageService() |
| 12 | +const lessLangService = getLESSLanguageService() |
| 13 | +const scssLangService = getSCSSLanguageService() |
7 | 14 |
|
8 | 15 | const getWxssDiagnostics = () =>
|
9 | 16 | vscode.workspace.getConfiguration('glass-easel-analyzer').get('wxssDiagnosticsMode') as string
|
10 | 17 |
|
11 |
| -const cssLangService = getCSSLanguageService() |
12 |
| - |
13 |
| -const doCssValidation = async (uri: vscode.Uri) => { |
| 18 | +const doCssValidation = async (uri: vscode.Uri, ls: LanguageService) => { |
14 | 19 | const doc = await vscode.workspace.openTextDocument(uri)
|
15 |
| - const sheet = cssLangService.parseStylesheet(doc as any) |
16 |
| - return cssLangService.doValidation(doc as any, sheet) |
| 20 | + const sheet = ls.parseStylesheet(doc as any) |
| 21 | + return ls.doValidation(doc as any, sheet) |
17 | 22 | }
|
18 | 23 |
|
19 | 24 | const middleware: Middleware = {
|
20 | 25 | handleDiagnostics(uri, diagnostics, next) {
|
21 | 26 | if (path.extname(uri.path) === '.wxss') {
|
22 | 27 | const mode = getWxssDiagnostics()
|
23 |
| - if (mode === 'disabled') { |
24 |
| - next(uri, diagnostics) |
25 |
| - } else { |
| 28 | + if (mode === 'CSS' || mode === 'LESS' || mode === 'SCSS') { |
| 29 | + let ls: LanguageService = cssLangService |
| 30 | + if (mode === 'LESS') ls = lessLangService |
| 31 | + else if (mode === 'SCSS') ls = scssLangService |
26 | 32 | // eslint-disable-next-line @typescript-eslint/no-floating-promises
|
27 |
| - doCssValidation(uri) |
| 33 | + doCssValidation(uri, ls) |
28 | 34 | // eslint-disable-next-line promise/no-callback-in-promise
|
29 | 35 | .then((diag) => next(uri, diag as any))
|
30 | 36 | .catch(() => {
|
31 | 37 | // eslint-disable-next-line @typescript-eslint/no-floating-promises
|
32 | 38 | vscode.window.showErrorMessage('Failed to get CSS diagnostics')
|
33 | 39 | })
|
| 40 | + } else { |
| 41 | + next(uri, diagnostics) |
34 | 42 | }
|
35 | 43 | return
|
36 | 44 | }
|
|
0 commit comments