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

Commit

Permalink
Merge pull request #9097 from MarcelGerber/less-scss-url-hints
Browse files Browse the repository at this point in the history
Enable UrlCodeHints for LESS/SCSS
  • Loading branch information
RaymondLim committed Oct 6, 2014
2 parents 3016e2b + 2c99eca commit 224af57
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
11 changes: 6 additions & 5 deletions src/extensions/default/UrlCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ define(function (require, exports, module) {

urlHints,
data,
htmlAttrs;
htmlAttrs,
styleModes = ["css", "text/x-less", "text/x-scss"];

/**
* @constructor
Expand Down Expand Up @@ -263,7 +264,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);
}

Expand Down Expand Up @@ -422,7 +423,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;
Expand Down Expand Up @@ -538,7 +539,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);
}

Expand Down Expand Up @@ -810,7 +811,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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* test.scss */
body {
.test {
&.brackets {
background-image: url();
}
}
}
39 changes: 28 additions & 11 deletions src/extensions/default/UrlCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"];

Expand Down Expand Up @@ -269,15 +270,15 @@ 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()", function () {
it("should hint for background-image: url() in CSS", function () {
runs(function () {
setupTests(testCssPath);
});

runs(function () {
testEditor.setCursorPos({ line: 3, ch: 26 });
hintsObj = null;
Expand All @@ -288,6 +289,22 @@ define(function (require, exports, module) {
verifyUrlHints(hintsObj.hints, subfolderDirHints);
});
});

it("should hint for background-image: url() in SCSS", function () {
runs(function () {
setupTests(testScssPath);
});

runs(function () {
testEditor.setCursorPos({ line: 4, ch: 34 });
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});

runs(function () {
verifyUrlHints(hintsObj.hints, subfolderDirHints);
});
});
});

describe("Project root relative Url Code Hints", function () {
Expand Down Expand Up @@ -471,7 +488,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");
Expand Down Expand Up @@ -526,7 +543,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");
Expand Down Expand Up @@ -578,7 +595,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");
Expand Down Expand Up @@ -675,7 +692,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");
Expand Down

0 comments on commit 224af57

Please sign in to comment.