Skip to content

Commit 50d5bf5

Browse files
authored
Fix #2649: Add support for choosing search scope (#3748)
- Provide two scopes (all, main) for search operations such as reference search, call hierarchy search, workspace symbols - Add a shortcut in to the java status menu Signed-off-by: Gayan Perera <[email protected]>
1 parent 9186a51 commit 50d5bf5

File tree

7 files changed

+51
-2
lines changed

7 files changed

+51
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ The following settings are supported:
250250
* `java.completion.collapseCompletionItems`: Enable/disable the collapse of overloaded methods in completion items. Overrides `java.completion.guessMethodArguments`. Defaults to `false`.
251251
* `java.diagnostic.filter`: Specifies a list of file patterns for which matching documents should not have their diagnostics reported (eg. '**/Foo.java').
252252

253+
New in 1.35.0
254+
* `java.search.scope`: Specifies the scope which must be used for search operation like
255+
- Find Reference
256+
- Call Hierarchy
257+
- Workspace Symbols
258+
253259
Semantic Highlighting
254260
===============
255261
[Semantic Highlighting](https://github.com/redhat-developer/vscode-java/wiki/Semantic-Highlighting) fixes numerous syntax highlighting issues with the default Java Textmate grammar. However, you might experience a few minor issues, particularly a delay when it kicks in, as it needs to be computed by the Java Language server, when opening a new file or when typing. Semantic highlighting can be disabled for all languages using the `editor.semanticHighlighting.enabled` setting, or for Java only using [language-specific editor settings](https://code.visualstudio.com/docs/getstarted/settings#_languagespecific-editor-settings).

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@
105105
{
106106
"title": "$(trash) Clean Workspace Cache...",
107107
"command": "java.clean.workspace"
108+
},
109+
{
110+
"command": "java.change.searchScope",
111+
"title": "$(search) Search Scope",
112+
"category": "Java"
108113
}
109114
],
110115
"semanticTokenTypes": [
@@ -1438,6 +1443,21 @@
14381443
"markdownDescription": "The patterns for the methods that will be disabled to show the inlay hints. Supported pattern examples:\n - `java.lang.Math.*` - All the methods from java.lang.Math.\n - `*.Arrays.asList` - Methods named as 'asList' in the types named as 'Arrays'.\n - `*.println(*)` - Methods named as 'println'.\n - `(from, to)` - Methods with two parameters named as 'from' and 'to'.\n - `(arg*)` - Methods with one parameter whose name starts with 'arg'.",
14391444
"scope": "window",
14401445
"order": 80
1446+
},
1447+
"java.search.scope": {
1448+
"type": "string",
1449+
"enum": [
1450+
"all",
1451+
"main"
1452+
],
1453+
"enumDescriptions": [
1454+
"Search on all classpath entries including reference libraries and projects.",
1455+
"All classpath entries excluding test classpath entries."
1456+
],
1457+
"default": "all",
1458+
"markdownDescription": "Specifies the scope which must be used for search operation like \n - Find Reference\n - Call Hierarchy\n - Workspace Symbols",
1459+
"scope": "window",
1460+
"order": 90
14411461
}
14421462
}
14431463
},
@@ -1658,6 +1678,11 @@
16581678
"command": "java.action.doCleanup",
16591679
"title": "%java.action.doCleanup%",
16601680
"category": "Java"
1681+
},
1682+
{
1683+
"command": "java.change.searchScope",
1684+
"title": "%java.change.searchScope%",
1685+
"category": "Java"
16611686
}
16621687
],
16631688
"keybindings": [

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
"java.server.restart": "Restart Java Language Server",
2828
"java.edit.smartSemicolonDetection": "Java Smart Semicolon Detection",
2929
"java.action.filesExplorerPasteAction": "Paste Clipboard Text Into a File",
30-
"java.action.doCleanup": "Performs Cleanup Actions"
30+
"java.action.doCleanup": "Performs Cleanup Actions",
31+
"java.change.searchScope": "Change Search Scope"
3132
}

src/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ export namespace Commands {
356356
*/
357357
export const OPEN_STATUS_SHORTCUT = "_java.openShortcuts";
358358

359+
/**
360+
* Change java search scope.
361+
*/
362+
export const CHANGE_JAVA_SEARCH_SCOPE = "java.change.searchScope";
363+
359364
}
360365

361366
/**

src/extension.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,16 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
545545
}
546546
});
547547

548+
context.subscriptions.push(commands.registerCommand(Commands.CHANGE_JAVA_SEARCH_SCOPE, async () => {
549+
const selection = await window.showQuickPick(["all", "main"], {
550+
canPickMany: false,
551+
placeHolder: `Current: ${workspace.getConfiguration().get("java.search.scope")}`,
552+
});
553+
if(selection) {
554+
workspace.getConfiguration().update("java.search.scope", selection, false);
555+
}
556+
}));
557+
548558
context.subscriptions.push(snippetCompletionProvider.initialize());
549559
context.subscriptions.push(serverStatusBarProvider);
550560
context.subscriptions.push(languageStatusBarProvider);

test/lightweight-mode-suite/extension.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ suite('Java Language Extension - LightWeight', () => {
2525
Commands.OPEN_FILE,
2626
Commands.CLEAN_SHARED_INDEXES,
2727
Commands.RESTART_LANGUAGE_SERVER,
28-
Commands.FILESEXPLORER_ONPASTE
28+
Commands.FILESEXPLORER_ONPASTE,
29+
Commands.CHANGE_JAVA_SEARCH_SCOPE
2930
].sort();
3031
const foundJavaCommands = commands.filter((value) => {
3132
return JAVA_COMMANDS.indexOf(value)>=0 || value.startsWith('java.');

test/standard-mode-suite/extension.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ suite('Java Language Extension - Standard', () => {
120120
Commands.RESOLVE_SOURCE_ATTACHMENT,
121121
Commands.FILESEXPLORER_ONPASTE,
122122
Commands.RESOLVE_PASTED_TEXT,
123+
Commands.CHANGE_JAVA_SEARCH_SCOPE
123124
].sort();
124125
const foundJavaCommands = commands.filter((value) => {
125126
return JAVA_COMMANDS.indexOf(value)>=0 || value.startsWith('java.');

0 commit comments

Comments
 (0)