@@ -37,6 +37,7 @@ define(function (require, exports, module) {
3737 LanguageManager = require ( "language/LanguageManager" ) ,
3838 ProjectManager = require ( "project/ProjectManager" ) ,
3939 TokenUtils = require ( "utils/TokenUtils" ) ,
40+ IndexingWorker = require ( "worker/IndexingWorker" ) ,
4041 _ = require ( "thirdparty/lodash" ) ;
4142
4243 // Constants
@@ -1816,11 +1817,12 @@ define(function (require, exports, module) {
18161817 return selectors ;
18171818 }
18181819 for ( let item of selectorList ) {
1819- if ( regex . test ( item . selector ) ) {
1820+ if ( regex . test ( item ) || ! item . trim ( ) ) {
18201821 // this happens for scss selectors like #${var}-something. we ignore that for now instead of resolving
18211822 continue ;
18221823 }
1823- selectors . add ( extractSelectorBase ( item . selector ) ) ; // x:hover or x::some -> x
1824+ const extracted = extractSelectorBase ( item ) ;
1825+ extracted . trim ( ) && selectors . add ( extracted ) ; // x:hover or x::some -> x
18241826 }
18251827 return selectors ;
18261828 }
@@ -1845,22 +1847,41 @@ define(function (require, exports, module) {
18451847 }
18461848 }
18471849
1850+ const MODE_MAP = {
1851+ css : "CSS" ,
1852+ less : "LESS" ,
1853+ scss : "SCSS"
1854+ } ;
1855+
18481856 function _loadFileAndScanCSSSelectorCached ( fullPath ) {
18491857 return new Promise ( resolve => {
18501858 DocumentManager . getDocumentForPath ( fullPath )
18511859 . done ( function ( doc ) {
18521860 // Find all matching rules for the given CSS file's content, and add them to the
18531861 // overall search result
1854- let selectors ;
1862+ let selectors = new Set ( ) ;
18551863 const cachedSelectors = CSSSelectorCache . get ( fullPath ) ;
18561864 if ( cachedSelectors ) {
1857- selectors = cachedSelectors ;
1858- } else {
1859- selectors = extractAllSelectors ( doc . getText ( ) , doc . getLanguage ( ) . getMode ( ) ) ;
1860- selectors = _extractSelectorSet ( selectors ) ;
1861- CSSSelectorCache . set ( fullPath , selectors ) ;
1865+ resolve ( cachedSelectors ) ;
1866+ return ;
1867+ }
1868+ const langID = doc . getLanguage ( ) . getId ( ) ;
1869+ if ( ! MODE_MAP [ langID ] ) {
1870+ console . log ( "Cannot parse CSS for mode :" , langID , "ignoring" , fullPath ) ;
1871+ resolve ( selectors ) ;
1872+ return ;
18621873 }
1863- resolve ( selectors ) ;
1874+ console . log ( "scanning file for css selector collation: " , fullPath ) ;
1875+ IndexingWorker . execPeer ( "css_getAllSymbols" ,
1876+ { text : doc . getText ( ) , cssMode : "CSS" , filePath : fullPath } )
1877+ . then ( ( selectorArray ) => {
1878+ selectors = _extractSelectorSet ( selectorArray ) ;
1879+ CSSSelectorCache . set ( fullPath , selectors ) ;
1880+ resolve ( selectors ) ;
1881+ } ) . catch ( err => {
1882+ console . warn ( "CSS language service unable to get selectors for" + fullPath , err ) ;
1883+ resolve ( selectors ) ; // still resolve, so the overall result doesn't reject
1884+ } ) ;
18641885 } )
18651886 . fail ( function ( error ) {
18661887 console . warn ( "Unable to read " + fullPath + " during CSS selector search:" , error ) ;
@@ -1923,6 +1944,10 @@ define(function (require, exports, module) {
19231944 }
19241945
19251946 AppInit . appReady ( function ( ) {
1947+ if ( Phoenix . isSpecRunnerWindow ) {
1948+ // no unit tests event handlers
1949+ return ;
1950+ }
19261951 ProjectManager . on ( ProjectManager . EVENT_PROJECT_FILE_CHANGED , _projectFileChanged ) ;
19271952 ProjectManager . on ( ProjectManager . EVENT_PROJECT_OPEN , ( ) => {
19281953 CSSSelectorCache . clear ( ) ;
0 commit comments