@@ -2,7 +2,7 @@ import * as vscode from "vscode";
2
2
import { AtelierAPI } from "../api" ;
3
3
import { ClassDefinition } from "../utils/classDefinition" ;
4
4
import { DocumentContentProvider } from "./DocumentContentProvider" ;
5
- import { StudioOpenDialog } from "../queries " ;
5
+ import { config } from "../extension " ;
6
6
7
7
export class WorkspaceSymbolProvider implements vscode . WorkspaceSymbolProvider {
8
8
public provideWorkspaceSymbols (
@@ -12,11 +12,10 @@ export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
12
12
if ( query . length < 3 ) {
13
13
return null ;
14
14
}
15
- return Promise . all ( [
16
- this . byClasses ( query ) ,
17
- this . byRoutines ( query ) ,
18
- this . byMethods ( query ) ,
19
- ] ) . then ( ( [ classes , routines , methods ] ) => [ ...classes , ...routines , ...methods ] ) ;
15
+ return Promise . all ( [ this . byStudioDocuments ( query ) , this . byMethods ( query ) ] ) . then ( ( [ documents , methods ] ) => [
16
+ ...documents ,
17
+ ...methods ,
18
+ ] ) ;
20
19
}
21
20
22
21
private getApi ( ) : AtelierAPI {
@@ -25,27 +24,18 @@ export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
25
24
return new AtelierAPI ( currentFileUri || firstFolder ?. uri || "" ) ;
26
25
}
27
26
28
- private async byClasses ( query : string ) : Promise < vscode . SymbolInformation [ ] > {
29
- query = query . toUpperCase ( ) ;
30
- query = `*${ query } *` ;
31
- const library = query . replace ( / % ( \b \w + \b (? ! \. ) ) / , "%LIBRARY.$1" ) ;
32
- const sql = `
33
- SELECT TOP 10 Name ClassName FROM %Dictionary.ClassDefinition
34
- WHERE %SQLUPPER Name %MATCHES ? OR %SQLUPPER Name %MATCHES ?` ;
35
- const api = this . getApi ( ) ;
36
- const data = await api . actionQuery ( sql , [ library , query ] ) ;
37
- return data . result . content . map ( ( { ClassName } ) => ( {
38
- kind : vscode . SymbolKind . Class ,
39
- location : {
40
- uri : new ClassDefinition ( ClassName , undefined , api . ns ) . uri ,
41
- } ,
42
- name : ClassName ,
43
- } ) ) ;
44
- }
45
-
46
- private async byRoutines ( query : string ) : Promise < vscode . SymbolInformation [ ] > {
47
- query = `*${ query } *.mac,*${ query } *.int` ;
48
- const sql = `CALL %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)` ;
27
+ private async byStudioDocuments ( query : string ) : Promise < vscode . SymbolInformation [ ] > {
28
+ const searchAllDocTypes = config ( "searchAllDocTypes" ) ;
29
+ if ( searchAllDocTypes ) {
30
+ // Note: This query could be expensive if there are too many files available across the namespaces
31
+ // configured in the current vs code workspace. However, delimiting by specific file types
32
+ // means custom Studio documents cannot be found. So this is a trade off
33
+ query = `*${ query } *` ;
34
+ } else {
35
+ // Default is to only search classes, routines and include files
36
+ query = `*${ query } *.cls,*${ query } *.mac,*${ query } *.int,*${ query } *.inc` ;
37
+ }
38
+ const sql = `SELECT TOP 10 Name FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)` ;
49
39
const api = this . getApi ( ) ;
50
40
const direction = "1" ;
51
41
const orderBy = "1" ;
@@ -54,9 +44,17 @@ export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
54
44
const notStudio = "0" ;
55
45
const generated = "0" ;
56
46
47
+ const kindFromName = ( name : string ) => {
48
+ const nameLowerCase = name . toLowerCase ( ) ;
49
+ return nameLowerCase . endsWith ( "cls" )
50
+ ? vscode . SymbolKind . Class
51
+ : nameLowerCase . endsWith ( "zpm" )
52
+ ? vscode . SymbolKind . Module
53
+ : vscode . SymbolKind . File ;
54
+ } ;
57
55
const data = await api . actionQuery ( sql , [ query , direction , orderBy , systemFiles , flat , notStudio , generated ] ) ;
58
- return data . result . content . map ( ( { Name } : StudioOpenDialog ) => ( {
59
- kind : vscode . SymbolKind . File ,
56
+ return data . result . content . map ( ( { Name } ) => ( {
57
+ kind : kindFromName ( Name ) ,
60
58
location : {
61
59
uri : DocumentContentProvider . getUri ( Name , undefined , api . ns ) ,
62
60
} ,
0 commit comments