@@ -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 )
0 commit comments