Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 224af57

Browse files
committed
Merge pull request #9097 from MarcelGerber/less-scss-url-hints
Enable UrlCodeHints for LESS/SCSS
2 parents 3016e2b + 2c99eca commit 224af57

3 files changed

Lines changed: 42 additions & 16 deletions

File tree

src/extensions/default/UrlCodeHints/main.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ define(function (require, exports, module) {
4242

4343
urlHints,
4444
data,
45-
htmlAttrs;
45+
htmlAttrs,
46+
styleModes = ["css", "text/x-less", "text/x-scss"];
4647

4748
/**
4849
* @constructor
@@ -263,7 +264,7 @@ define(function (require, exports, module) {
263264
var mode = editor.getModeForSelection();
264265
if (mode === "html") {
265266
return this.hasHtmlHints(editor, implicitChar);
266-
} else if (mode === "css") {
267+
} else if (styleModes.indexOf(mode) > -1) {
267268
return this.hasCssHints(editor, implicitChar);
268269
}
269270

@@ -422,7 +423,7 @@ define(function (require, exports, module) {
422423
}
423424
this.info = tagInfo;
424425

425-
} else if (mode === "css") {
426+
} else if (styleModes.indexOf(mode) > -1) {
426427
this.info = CSSUtils.getInfoAtPos(this.editor, cursor);
427428

428429
var context = this.info.context;
@@ -538,7 +539,7 @@ define(function (require, exports, module) {
538539

539540
if (mode === "html") {
540541
return this.insertHtmlHint(completion);
541-
} else if (mode === "css") {
542+
} else if (styleModes.indexOf(mode) > -1) {
542543
return this.insertCssHint(completion);
543544
}
544545

@@ -810,7 +811,7 @@ define(function (require, exports, module) {
810811
htmlAttrs = data.htmlAttrs;
811812

812813
urlHints = new UrlCodeHints();
813-
CodeHintManager.registerHintProvider(urlHints, ["css", "html"], 5);
814+
CodeHintManager.registerHintProvider(urlHints, ["css", "html", "less", "scss"], 5);
814815

815816
FileSystem.on("change", _clearCachedHints);
816817
FileSystem.on("rename", _clearCachedHints);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* test.scss */
2+
body {
3+
.test {
4+
&.brackets {
5+
background-image: url();
6+
}
7+
}
8+
}

src/extensions/default/UrlCodeHints/unittests.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ define(function (require, exports, module) {
4141
var extensionPath = FileUtils.getNativeModuleDirectoryPath(module),
4242
testHtmlPath = extensionPath + "/testfiles/test.html",
4343
testCssPath = extensionPath + "/testfiles/subfolder/test.css",
44+
testScssPath = extensionPath + "/testfiles/subfolder/test.scss",
4445
testDocument,
4546
testEditor,
4647
hintsObj;
@@ -50,7 +51,7 @@ define(function (require, exports, module) {
5051
// strategically so that they sort the same on all OS's (i.e. folders are listed
5152
// first, and then files), but this is not true for UrlCodeHints folder.
5253
var testfilesDirHints = [ "subfolder/", "test.html"],
53-
subfolderDirHints = [ "chevron.png", "test.css", "test.js"],
54+
subfolderDirHints = [ "chevron.png", "test.css", "test.js", "test.scss"],
5455
UrlCodeHintsDirHintsMac = [ "../data.json", "../main.js", "../testfiles/", "../unittests.js"],
5556
UrlCodeHintsDirHints = [ "../testfiles/", "../data.json", "../main.js", "../unittests.js"];
5657

@@ -269,15 +270,15 @@ define(function (require, exports, module) {
269270

270271
describe("Url Code Hints in a subfolder", function () {
271272

272-
beforeFirst(function () {
273-
setupTests(testCssPath);
274-
});
275-
276-
afterLast(function () {
273+
afterEach(function () {
277274
tearDownTests();
278275
});
279276

280-
it("should hint for background-image: url()", function () {
277+
it("should hint for background-image: url() in CSS", function () {
278+
runs(function () {
279+
setupTests(testCssPath);
280+
});
281+
281282
runs(function () {
282283
testEditor.setCursorPos({ line: 3, ch: 26 });
283284
hintsObj = null;
@@ -288,6 +289,22 @@ define(function (require, exports, module) {
288289
verifyUrlHints(hintsObj.hints, subfolderDirHints);
289290
});
290291
});
292+
293+
it("should hint for background-image: url() in SCSS", function () {
294+
runs(function () {
295+
setupTests(testScssPath);
296+
});
297+
298+
runs(function () {
299+
testEditor.setCursorPos({ line: 4, ch: 34 });
300+
hintsObj = null;
301+
expectAsyncHints(UrlCodeHints.hintProvider);
302+
});
303+
304+
runs(function () {
305+
verifyUrlHints(hintsObj.hints, subfolderDirHints);
306+
});
307+
});
291308
});
292309

293310
describe("Project root relative Url Code Hints", function () {
@@ -471,7 +488,7 @@ define(function (require, exports, module) {
471488
runs(function () {
472489
expect(hintsObj).toBeTruthy();
473490
expect(hintsObj.hints).toBeTruthy();
474-
expect(hintsObj.hints.length).toBe(3);
491+
expect(hintsObj.hints.length).toBe(subfolderDirHints.length);
475492

476493
// Complete path is displayed
477494
expect(hintsObj.hints[0]).toBe("subfolder/chevron.png");
@@ -526,7 +543,7 @@ define(function (require, exports, module) {
526543
runs(function () {
527544
expect(hintsObj).toBeTruthy();
528545
expect(hintsObj.hints).toBeTruthy();
529-
expect(hintsObj.hints.length).toBe(3);
546+
expect(hintsObj.hints.length).toBe(subfolderDirHints.length);
530547

531548
// Complete path is displayed
532549
expect(hintsObj.hints[0]).toBe("subfolder/chevron.png");
@@ -578,7 +595,7 @@ define(function (require, exports, module) {
578595
runs(function () {
579596
expect(hintsObj).toBeTruthy();
580597
expect(hintsObj.hints).toBeTruthy();
581-
expect(hintsObj.hints.length).toBe(3);
598+
expect(hintsObj.hints.length).toBe(subfolderDirHints.length);
582599

583600
// Complete path is displayed
584601
expect(hintsObj.hints[0]).toBe("subfolder/chevron.png");
@@ -675,7 +692,7 @@ define(function (require, exports, module) {
675692
runs(function () {
676693
expect(hintsObj).toBeTruthy();
677694
expect(hintsObj.hints).toBeTruthy();
678-
expect(hintsObj.hints.length).toBe(3);
695+
expect(hintsObj.hints.length).toBe(subfolderDirHints.length);
679696

680697
// Complete path is displayed
681698
expect(hintsObj.hints[0]).toBe("subfolder/chevron.png");

0 commit comments

Comments
 (0)