Skip to content

Commit 39ceff5

Browse files
committed
feat: support LESS and SCSS as wxss diagnostic mode
1 parent 5b771a8 commit 39ceff5

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

vscode-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"glass-easel-analyzer.wxssDiagnosticsMode": {
9595
"scope": "window",
9696
"type": "string",
97-
"enum": ["CSS", "disabled"],
97+
"enum": ["CSS", "LESS", "SCSS", "disabled"],
9898
"default": "CSS",
9999
"description": "The diagnostics information used for WXSS."
100100
}

vscode-extension/src/middleware.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
11
import * as vscode from 'vscode'
22
import path from 'node:path'
33
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'
510

6-
getCSSLanguageService()
11+
const cssLangService = getCSSLanguageService()
12+
const lessLangService = getLESSLanguageService()
13+
const scssLangService = getSCSSLanguageService()
714

815
const getWxssDiagnostics = () =>
916
vscode.workspace.getConfiguration('glass-easel-analyzer').get('wxssDiagnosticsMode') as string
1017

11-
const cssLangService = getCSSLanguageService()
12-
13-
const doCssValidation = async (uri: vscode.Uri) => {
18+
const doCssValidation = async (uri: vscode.Uri, ls: LanguageService) => {
1419
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)
1722
}
1823

1924
const middleware: Middleware = {
2025
handleDiagnostics(uri, diagnostics, next) {
2126
if (path.extname(uri.path) === '.wxss') {
2227
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
2632
// eslint-disable-next-line @typescript-eslint/no-floating-promises
27-
doCssValidation(uri)
33+
doCssValidation(uri, ls)
2834
// eslint-disable-next-line promise/no-callback-in-promise
2935
.then((diag) => next(uri, diag as any))
3036
.catch(() => {
3137
// eslint-disable-next-line @typescript-eslint/no-floating-promises
3238
vscode.window.showErrorMessage('Failed to get CSS diagnostics')
3339
})
40+
} else {
41+
next(uri, diagnostics)
3442
}
3543
return
3644
}

0 commit comments

Comments
 (0)