Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}
35 changes: 24 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,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()", function () {
it("should hint for background-image: url() in CSS", function () {
setupTests(testCssPath);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safer to wrap it with runs(function () { ...});.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


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

it("should hint for background-image: url() in SCSS", 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 +484,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 +539,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 +591,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 +688,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