Skip to content

Commit d87f551

Browse files
committed
chore: css defined in html style block will appear in css class hints
1 parent 64b196f commit d87f551

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

src/extensions/default/HTMLCodeHints/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ define(function (require, exports, module) {
255255
const segments = queryStr.split(" ");
256256
queryStr = segments[segments.length-1];
257257
const deferred = $.Deferred();
258-
CSSUtils.getAllCssSelectorsInProject({includeClasses: true}).then(hints=>{
258+
CSSUtils.getAllCssSelectorsInProject({includeClasses: true, scanCurrentHtml: true}).then(hints=>{
259259
const result = $.map(hints, function (pvalue) {
260260
pvalue = pvalue.slice(1); // remove.
261261
if(!pvalue || pvalue.includes("#") || pvalue.includes("\\") || pvalue.includes("/")){

src/extensions/default/JavaScriptCodeHints/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ define(function (require, exports, module) {
210210
*/
211211
function formatHints(hints, query) {
212212
return hints.map(function (token) {
213-
var $hintObj = $("<span>").addClass("brackets-js-hints");
213+
var $hintObj = $("<span>").addClass("brackets-js-hints brackets-hints");
214214

215215
// level indicates either variable scope or property confidence
216216
if (!type.property && !token.builtin && token.depth !== undefined) {

src/language/CSSUtils.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,17 +1903,60 @@ define(function (require, exports, module) {
19031903
return selector;
19041904
}
19051905

1906+
const _htmlLikeFileExts = ["htm", "html", "xhtml", "php"];
1907+
function _isHtmlLike(editor) {
1908+
if (!editor) {
1909+
return false;
1910+
}
1911+
const fullPath = editor.document.file.fullPath;
1912+
return (_htmlLikeFileExts.indexOf(LanguageManager.getLanguageForPath(fullPath).getId()) !== -1);
1913+
}
1914+
1915+
function _getAllSelectorsInCurrentHTMLEditor() {
1916+
return new Promise(resolve=>{
1917+
let selectors = new Set();
1918+
const htmlEditor = EditorManager.getCurrentFullEditor();
1919+
if (!htmlEditor || !_isHtmlLike(htmlEditor) ) {
1920+
resolve(selectors);
1921+
return;
1922+
}
1923+
1924+
// Find all <style> blocks in the HTML file
1925+
const styleBlocks = HTMLUtils.findStyleBlocks(htmlEditor);
1926+
let cssText = "";
1927+
1928+
styleBlocks.forEach(function (styleBlockInfo) {
1929+
// Search this one <style> block's content
1930+
cssText += styleBlockInfo.text;
1931+
});
1932+
const fullPath = htmlEditor.document.file.fullPath;
1933+
IndexingWorker.execPeer("css_getAllSymbols", {text: cssText, cssMode: "CSS", filePath: fullPath})
1934+
.then((selectorArray)=>{
1935+
selectors = _extractSelectorSet(selectorArray);
1936+
CSSSelectorCache.set(fullPath, selectors);
1937+
resolve(selectors);
1938+
}).catch(err=>{
1939+
console.warn("CSS language service unable to get selectors for" + fullPath, err);
1940+
resolve(selectors); // still resolve, so the overall result doesn't reject
1941+
});
1942+
});
1943+
}
1944+
19061945
let globalPrecacheRun = 0;
19071946
function getAllCssSelectorsInProject(options = {
19081947
includeClasses: true,
1909-
includeIDs: true
1948+
includeIDs: true,
1949+
scanCurrentHtml: true
19101950
}) {
19111951
globalPrecacheRun ++; // we need to stop the pre cache logic from doing the same cache again
19121952
return new Promise(resolve=>{
19131953
ProjectManager.getAllFiles(ProjectManager.getLanguageFilter(["css", "less", "scss"]))
19141954
.done(function (cssFiles) {
19151955
// Create an array of promises from the array of cssFiles
19161956
const promises = cssFiles.map(fileInfo => _loadFileAndScanCSSSelectorCached(fileInfo.fullPath));
1957+
if(options.scanCurrentHtml){
1958+
promises.push(_getAllSelectorsInCurrentHTMLEditor());
1959+
}
19171960
const mergedSets = new Set();
19181961
// Use Promise.allSettled to handle all promises
19191962
Promise.allSettled(promises)

src/languageTools/styles/default_provider_style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ span.brackets-hints-with-type-details {
8585
color: #6495ed !important;
8686
}
8787

88+
.codehint-menu {
89+
font-family: SourceCodePro;
90+
}
91+
8892
.brackets-hints .matched-hint {
8993
font-weight: 500;
9094
color: #437900;

0 commit comments

Comments
 (0)