From fe3852bf75d7509188763b59d3dc6858b8a0a60f Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Sat, 13 Sep 2014 10:54:48 +0200 Subject: [PATCH 1/4] Enable UrlCodeHints for LESS/SCSS --- src/extensions/default/UrlCodeHints/main.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/main.js b/src/extensions/default/UrlCodeHints/main.js index 4e4178803b3..784d9f58259 100644 --- a/src/extensions/default/UrlCodeHints/main.js +++ b/src/extensions/default/UrlCodeHints/main.js @@ -43,7 +43,8 @@ define(function (require, exports, module) { urlHints, data, - htmlAttrs; + htmlAttrs, + styleModes = ["css", "text/x-less", "text/x-scss"]; /** * @constructor @@ -264,7 +265,7 @@ define(function (require, exports, module) { var mode = editor.getModeForSelection(); if (mode === "html") { return this.hasHtmlHints(editor, implicitChar); - } else if (mode === "css") { + } else if (styleModes.indexOf(mode) > -1) { return this.hasCssHints(editor, implicitChar); } @@ -424,7 +425,7 @@ define(function (require, exports, module) { } this.info = tagInfo; - } else if (mode === "css") { + } else if (styleModes.indexOf(mode) > -1) { this.info = CSSUtils.getInfoAtPos(this.editor, cursor); var context = this.info.context; @@ -540,7 +541,7 @@ define(function (require, exports, module) { if (mode === "html") { return this.insertHtmlHint(completion); - } else if (mode === "css") { + } else if (styleModes.indexOf(mode) > -1) { return this.insertCssHint(completion); } @@ -813,7 +814,7 @@ define(function (require, exports, module) { htmlAttrs = data.htmlAttrs; urlHints = new UrlCodeHints(); - CodeHintManager.registerHintProvider(urlHints, ["css", "html"], 5); + CodeHintManager.registerHintProvider(urlHints, ["css", "html", "less", "scss"], 5); FileSystem.on("change", _clearCachedHints); FileSystem.on("rename", _clearCachedHints); From 0931ac91814219263aaa1416ab1b1f0b3bfc5e30 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Thu, 18 Sep 2014 19:22:38 +0200 Subject: [PATCH 2/4] Unit tests. --- .../testfiles/subfolder/test.scss | 8 +++++ .../default/UrlCodeHints/unittests.js | 30 +++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/extensions/default/UrlCodeHints/testfiles/subfolder/test.scss diff --git a/src/extensions/default/UrlCodeHints/testfiles/subfolder/test.scss b/src/extensions/default/UrlCodeHints/testfiles/subfolder/test.scss new file mode 100644 index 00000000000..bbbb0f10e64 --- /dev/null +++ b/src/extensions/default/UrlCodeHints/testfiles/subfolder/test.scss @@ -0,0 +1,8 @@ +/* test.scss */ +body { + .test { + &.brackets { + background-image: url(); + } + } +} diff --git a/src/extensions/default/UrlCodeHints/unittests.js b/src/extensions/default/UrlCodeHints/unittests.js index d471a413e92..8aeebffe32e 100644 --- a/src/extensions/default/UrlCodeHints/unittests.js +++ b/src/extensions/default/UrlCodeHints/unittests.js @@ -41,6 +41,7 @@ define(function (require, exports, module) { var extensionPath = FileUtils.getNativeModuleDirectoryPath(module), testHtmlPath = extensionPath + "/testfiles/test.html", testCssPath = extensionPath + "/testfiles/subfolder/test.css", + testScssPath = extensionPath + "/testfiles/subfolder/test.scss", testDocument, testEditor, hintsObj; @@ -50,7 +51,7 @@ define(function (require, exports, module) { // strategically so that they sort the same on all OS's (i.e. folders are listed // first, and then files), but this is not true for UrlCodeHints folder. var testfilesDirHints = [ "subfolder/", "test.html"], - subfolderDirHints = [ "chevron.png", "test.css", "test.js"], + subfolderDirHints = [ "chevron.png", "test.css", "test.js", "test.scss"], UrlCodeHintsDirHintsMac = [ "../data.json", "../main.js", "../testfiles/", "../unittests.js"], UrlCodeHintsDirHints = [ "../testfiles/", "../data.json", "../main.js", "../unittests.js"]; @@ -277,7 +278,7 @@ define(function (require, exports, module) { tearDownTests(); }); - it("should hint for background-image: url()", function () { + it("should hint for background-image: url() in CSS", function () { runs(function () { testEditor.setCursorPos({ line: 3, ch: 26 }); hintsObj = null; @@ -287,6 +288,23 @@ define(function (require, exports, module) { runs(function () { verifyUrlHints(hintsObj.hints, subfolderDirHints); }); + + runs(function () { + tearDownTests(); + setupTests(testScssPath); + }); + }); + + it("should hint for background-image: url() in SCSS", function () { + runs(function () { + testEditor.setCursorPos({ line: 4, ch: 34 }); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + verifyUrlHints(hintsObj.hints, subfolderDirHints); + }); }); }); @@ -471,7 +489,7 @@ define(function (require, exports, module) { runs(function () { expect(hintsObj).toBeTruthy(); expect(hintsObj.hints).toBeTruthy(); - expect(hintsObj.hints.length).toBe(3); + expect(hintsObj.hints.length).toBe(subfolderDirHints.length); // Complete path is displayed expect(hintsObj.hints[0]).toBe("subfolder/chevron.png"); @@ -526,7 +544,7 @@ define(function (require, exports, module) { runs(function () { expect(hintsObj).toBeTruthy(); expect(hintsObj.hints).toBeTruthy(); - expect(hintsObj.hints.length).toBe(3); + expect(hintsObj.hints.length).toBe(subfolderDirHints.length); // Complete path is displayed expect(hintsObj.hints[0]).toBe("subfolder/chevron.png"); @@ -578,7 +596,7 @@ define(function (require, exports, module) { runs(function () { expect(hintsObj).toBeTruthy(); expect(hintsObj.hints).toBeTruthy(); - expect(hintsObj.hints.length).toBe(3); + expect(hintsObj.hints.length).toBe(subfolderDirHints.length); // Complete path is displayed expect(hintsObj.hints[0]).toBe("subfolder/chevron.png"); @@ -675,7 +693,7 @@ define(function (require, exports, module) { runs(function () { expect(hintsObj).toBeTruthy(); expect(hintsObj.hints).toBeTruthy(); - expect(hintsObj.hints.length).toBe(3); + expect(hintsObj.hints.length).toBe(subfolderDirHints.length); // Complete path is displayed expect(hintsObj.hints[0]).toBe("subfolder/chevron.png"); From ea17aa0fb1197a37dfbb3e17e06aeeea44bc4636 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Mon, 6 Oct 2014 21:45:38 +0200 Subject: [PATCH 3/4] Remove dependency between tests --- src/extensions/default/UrlCodeHints/unittests.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/unittests.js b/src/extensions/default/UrlCodeHints/unittests.js index 8aeebffe32e..c43592a5132 100644 --- a/src/extensions/default/UrlCodeHints/unittests.js +++ b/src/extensions/default/UrlCodeHints/unittests.js @@ -270,15 +270,13 @@ define(function (require, exports, module) { describe("Url Code Hints in a subfolder", function () { - beforeFirst(function () { - setupTests(testCssPath); - }); - - afterLast(function () { + afterEach(function () { tearDownTests(); }); it("should hint for background-image: url() in CSS", function () { + setupTests(testCssPath); + runs(function () { testEditor.setCursorPos({ line: 3, ch: 26 }); hintsObj = null; @@ -288,14 +286,11 @@ define(function (require, exports, module) { runs(function () { verifyUrlHints(hintsObj.hints, subfolderDirHints); }); - - runs(function () { - tearDownTests(); - setupTests(testScssPath); - }); }); it("should hint for background-image: url() in SCSS", function () { + setupTests(testScssPath); + runs(function () { testEditor.setCursorPos({ line: 4, ch: 34 }); hintsObj = null; From 2c99ecab050e5fcb36b97d955218a1fc130818c8 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Mon, 6 Oct 2014 22:01:40 +0200 Subject: [PATCH 4/4] Wrap setupTests() in runs() --- src/extensions/default/UrlCodeHints/unittests.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/unittests.js b/src/extensions/default/UrlCodeHints/unittests.js index c43592a5132..6cc690005cf 100644 --- a/src/extensions/default/UrlCodeHints/unittests.js +++ b/src/extensions/default/UrlCodeHints/unittests.js @@ -275,7 +275,9 @@ define(function (require, exports, module) { }); it("should hint for background-image: url() in CSS", function () { - setupTests(testCssPath); + runs(function () { + setupTests(testCssPath); + }); runs(function () { testEditor.setCursorPos({ line: 3, ch: 26 }); @@ -289,7 +291,9 @@ define(function (require, exports, module) { }); it("should hint for background-image: url() in SCSS", function () { - setupTests(testScssPath); + runs(function () { + setupTests(testScssPath); + }); runs(function () { testEditor.setCursorPos({ line: 4, ch: 34 });