11import { dirname , basename , normalize , relative } from "path" ;
22import { Event } from "vscode" ;
3- import { EnvironmentContext } from "../common/app" ;
3+ import { App } from "../common/app" ;
44import {
55 FileTreeDirectory ,
66 FileTreeLeaf ,
@@ -11,6 +11,8 @@ import { FilePathDiscovery } from "../common/vscode/file-path-discovery";
1111import { containsPath } from "../common/files" ;
1212import { getOnDiskWorkspaceFoldersObjects } from "../common/vscode/workspace-folders" ;
1313import { QueryLanguage } from "../common/query-language" ;
14+ import { LanguageContextStore } from "../language-context-store" ;
15+ import { AppEvent , AppEventEmitter } from "../common/events" ;
1416
1517const QUERY_FILE_EXTENSION = ".ql" ;
1618
@@ -31,24 +33,36 @@ export class QueryDiscovery
3133 extends FilePathDiscovery < Query >
3234 implements QueryDiscoverer
3335{
36+ public readonly onDidChangeQueries : AppEvent < void > ;
37+ private readonly onDidChangeQueriesEmitter : AppEventEmitter < void > ;
38+
3439 constructor (
35- private readonly env : EnvironmentContext ,
40+ private readonly app : App ,
3641 private readonly queryPackDiscovery : QueryPackDiscoverer ,
42+ private readonly languageContext : LanguageContextStore ,
3743 ) {
3844 super ( "Query Discovery" , `**/*${ QUERY_FILE_EXTENSION } ` ) ;
3945
46+ // Set up event emitters
47+ this . onDidChangeQueriesEmitter = this . push ( app . createEventEmitter < void > ( ) ) ;
48+ this . onDidChangeQueries = this . onDidChangeQueriesEmitter . event ;
49+
50+ // Handlers
4051 this . push (
4152 this . queryPackDiscovery . onDidChangeQueryPacks (
4253 this . recomputeAllData . bind ( this ) ,
4354 ) ,
4455 ) ;
45- }
46-
47- /**
48- * Event that fires when the set of queries in the workspace changes.
49- */
50- public get onDidChangeQueries ( ) : Event < void > {
51- return this . onDidChangePathData ;
56+ this . push (
57+ this . onDidChangePathData ( ( ) => {
58+ this . onDidChangeQueriesEmitter . fire ( ) ;
59+ } ) ,
60+ ) ;
61+ this . push (
62+ this . languageContext . onLanguageContextChanged ( ( ) => {
63+ this . onDidChangeQueriesEmitter . fire ( ) ;
64+ } ) ,
65+ ) ;
5266 }
5367
5468 /**
@@ -64,16 +78,18 @@ export class QueryDiscovery
6478
6579 const roots = [ ] ;
6680 for ( const workspaceFolder of getOnDiskWorkspaceFoldersObjects ( ) ) {
67- const queriesInRoot = pathData . filter ( ( query ) =>
68- containsPath ( workspaceFolder . uri . fsPath , query . path ) ,
81+ const queriesInRoot = pathData . filter (
82+ ( query ) =>
83+ containsPath ( workspaceFolder . uri . fsPath , query . path ) &&
84+ this . languageContext . shouldInclude ( query . language ) ,
6985 ) ;
7086 if ( queriesInRoot . length === 0 ) {
7187 continue ;
7288 }
7389 const root = new FileTreeDirectory < string > (
7490 workspaceFolder . uri . fsPath ,
7591 workspaceFolder . name ,
76- this . env ,
92+ this . app . environment ,
7793 ) ;
7894 for ( const query of queriesInRoot ) {
7995 const dirName = dirname ( normalize ( relative ( root . path , query . path ) ) ) ;
0 commit comments