Skip to content

Commit 67483b7

Browse files
Merge pull request #534 from isc-kiyer/symbol-search-all-studio-doc-types
Support searching for all Studio document types when using Cmd + T.
2 parents 09ed56d + de953d9 commit 67483b7

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@
833833
"default": "cuk",
834834
"description": "Compilation flags."
835835
},
836+
"objectscript.searchAllDocTypes": {
837+
"type": "boolean",
838+
"default": false,
839+
"markdownDescription": "Whether [Quick Open](https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_quick-open) should search across all Studio Document types. Default is to only search classes, routines and include files."
840+
},
836841
"objectscript.overwriteServerChanges": {
837842
"type": "boolean",
838843
"default": false,

src/providers/WorkspaceSymbolProvider.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22
import { AtelierAPI } from "../api";
33
import { ClassDefinition } from "../utils/classDefinition";
44
import { DocumentContentProvider } from "./DocumentContentProvider";
5-
import { StudioOpenDialog } from "../queries";
5+
import { config } from "../extension";
66

77
export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
88
public provideWorkspaceSymbols(
@@ -12,11 +12,10 @@ export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
1212
if (query.length < 3) {
1313
return null;
1414
}
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+
]);
2019
}
2120

2221
private getApi(): AtelierAPI {
@@ -25,27 +24,18 @@ export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
2524
return new AtelierAPI(currentFileUri || firstFolder?.uri || "");
2625
}
2726

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(?,?,?,?,?,?,?)`;
4939
const api = this.getApi();
5040
const direction = "1";
5141
const orderBy = "1";
@@ -54,9 +44,17 @@ export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
5444
const notStudio = "0";
5545
const generated = "0";
5646

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+
};
5755
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),
6058
location: {
6159
uri: DocumentContentProvider.getUri(Name, undefined, api.ns),
6260
},

0 commit comments

Comments
 (0)