Skip to content

Commit 927d261

Browse files
committed
chore: add new css language service with less/scss style lint
1 parent e7af923 commit 927d261

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@fortawesome/fontawesome-free": "^6.1.2",
9292
"@highlightjs/cdn-assets": "^11.5.1",
9393
"@phcode/fs": "^3.0.0",
94-
"@phcode/language-support": "^1.0.6",
94+
"@phcode/language-support": "^1.0.7",
9595
"@pixelbrackets/gfm-stylesheet": "^1.1.0",
9696
"@prettier/plugin-php": "^0.22.2",
9797
"@uiw/file-icons": "^1.3.2",

src/extensions/default/CSSCodeHints/css-lint.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ define(function (require, exports, module) {
2929
// Load dependent modules
3030
const CodeInspection = brackets.getModule("language/CodeInspection"),
3131
Strings = brackets.getModule("strings"),
32+
LanguageManager = brackets.getModule("language/LanguageManager"),
33+
StringUtils = brackets.getModule("utils/StringUtils"),
3234
IndexingWorker = brackets.getModule("worker/IndexingWorker");
3335

3436
IndexingWorker.loadScriptInWorker(`${module.uri}/../worker/css-worker.js`);
@@ -41,15 +43,27 @@ define(function (require, exports, module) {
4143
}
4244
}
4345

46+
const cssMode = {
47+
css: "CSS",
48+
less: "LESS",
49+
scss: "SCSS"
50+
};
51+
4452
/**
4553
* Run JSLint on the current document. Reports results to the main UI. Displays
4654
* a gold star when no errors are found.
4755
*/
4856
async function lintOneFile(text, fullPath) {
4957
return new Promise((resolve)=>{
58+
const languageId = LanguageManager.getLanguageForPath(fullPath).getId();
59+
if(!cssMode[languageId]){
60+
console.error("Unknown language id to lint: ", languageId, fullPath);
61+
resolve();
62+
return;
63+
}
5064
IndexingWorker.execPeer("cssLint", {
5165
text,
52-
cssMode: "CSS",
66+
cssMode: cssMode[languageId],
5367
filePath: fullPath
5468
}).then(lintResult =>{
5569
if (lintResult && lintResult.length) {
@@ -70,8 +84,11 @@ define(function (require, exports, module) {
7084
}
7185

7286
// Register for JS files
73-
CodeInspection.register("css", {
74-
name: Strings.CSS_LINT_NAME,
75-
scanFileAsync: lintOneFile
76-
});
87+
const supportedLanguages = ["css", "less", "scss"];
88+
for(let language of supportedLanguages){
89+
CodeInspection.register(language, {
90+
name: StringUtils.format(Strings.CSS_LINT_NAME, cssMode[language]),
91+
scanFileAsync: lintOneFile
92+
});
93+
}
7794
});

src/extensions/default/CSSCodeHints/worker/css-worker.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222

2323
(function () {
2424
function cssLint(params) {
25-
return CSSLanguageService.validateCSS(params.text, params.cssMode, params.filePath, {
25+
const cssMode = CSSLanguageService.CSS_MODES[params.cssMode];
26+
if(!cssMode) {
27+
throw new Error("Language mode not supported "+ params.cssMode);
28+
}
29+
return CSSLanguageService.validateCSS(params.text, cssMode, params.filePath, {
2630
duplicateProperties: "warning",
2731
zeroUnits: "warning",
2832
emptyRules: "warning",

src/nls/root/strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ define({
877877
"JSHINT_NAME": "JSHint",
878878

879879
// extension css code hints
880-
"CSS_LINT_NAME": "CSS Lint",
880+
"CSS_LINT_NAME": "{0} Lint",
881881

882882
// Features/QuickView and quick view extensions
883883
"CMD_ENABLE_QUICK_VIEW": "Quick View on Hover",

src/worker/language-service-worker-thread.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ importScripts('../thirdparty/no-minify/language-worker.js');
2525

2626
(function () {
2727
function CSSGetAllSymbols({text, cssMode, filePath}) {
28-
if(!CSSLanguageService.CSS_MODES[cssMode]) {
28+
const cssModeID = CSSLanguageService.CSS_MODES[cssMode];
29+
if(!cssModeID) {
2930
throw new Error("Language mode not supported "+ cssMode);
3031
}
31-
return CSSLanguageService.getAllSymbols(text, cssMode, filePath);
32+
return CSSLanguageService.getAllSymbols(text, cssModeID, filePath);
3233
}
3334

3435
function htmlGetAllLinks({text, htmlMode, filePath}) {
35-
if(!HTMLLanguageService.HTML_MODES[htmlMode]) {
36+
const htmlModeID = HTMLLanguageService.HTML_MODES[htmlMode];
37+
if(!htmlModeID) {
3638
throw new Error("Language mode not supported "+ htmlMode);
3739
}
38-
return HTMLLanguageService.getAllDocumentLinks(text, htmlMode, filePath);
40+
return HTMLLanguageService.getAllDocumentLinks(text, htmlModeID, filePath);
3941
}
4042

4143
WorkerComm.setExecHandler("css_getAllSymbols", CSSGetAllSymbols);

0 commit comments

Comments
 (0)