Skip to content

Commit

Permalink
Fix #2649: Add support for choosing search scope (#3748)
Browse files Browse the repository at this point in the history
- 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 <gayanper@gmail.com>
  • Loading branch information
gayanper authored Sep 25, 2024
1 parent 9186a51 commit 50d5bf5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ The following settings are supported:
* `java.completion.collapseCompletionItems`: Enable/disable the collapse of overloaded methods in completion items. Overrides `java.completion.guessMethodArguments`. Defaults to `false`.
* `java.diagnostic.filter`: Specifies a list of file patterns for which matching documents should not have their diagnostics reported (eg. '**/Foo.java').

New in 1.35.0
* `java.search.scope`: Specifies the scope which must be used for search operation like
- Find Reference
- Call Hierarchy
- Workspace Symbols

Semantic Highlighting
===============
[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).
Expand Down
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
{
"title": "$(trash) Clean Workspace Cache...",
"command": "java.clean.workspace"
},
{
"command": "java.change.searchScope",
"title": "$(search) Search Scope",
"category": "Java"
}
],
"semanticTokenTypes": [
Expand Down Expand Up @@ -1438,6 +1443,21 @@
"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'.",
"scope": "window",
"order": 80
},
"java.search.scope": {
"type": "string",
"enum": [
"all",
"main"
],
"enumDescriptions": [
"Search on all classpath entries including reference libraries and projects.",
"All classpath entries excluding test classpath entries."
],
"default": "all",
"markdownDescription": "Specifies the scope which must be used for search operation like \n - Find Reference\n - Call Hierarchy\n - Workspace Symbols",
"scope": "window",
"order": 90
}
}
},
Expand Down Expand Up @@ -1658,6 +1678,11 @@
"command": "java.action.doCleanup",
"title": "%java.action.doCleanup%",
"category": "Java"
},
{
"command": "java.change.searchScope",
"title": "%java.change.searchScope%",
"category": "Java"
}
],
"keybindings": [
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"java.server.restart": "Restart Java Language Server",
"java.edit.smartSemicolonDetection": "Java Smart Semicolon Detection",
"java.action.filesExplorerPasteAction": "Paste Clipboard Text Into a File",
"java.action.doCleanup": "Performs Cleanup Actions"
"java.action.doCleanup": "Performs Cleanup Actions",
"java.change.searchScope": "Change Search Scope"
}
5 changes: 5 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ export namespace Commands {
*/
export const OPEN_STATUS_SHORTCUT = "_java.openShortcuts";

/**
* Change java search scope.
*/
export const CHANGE_JAVA_SEARCH_SCOPE = "java.change.searchScope";

}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,16 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
}
});

context.subscriptions.push(commands.registerCommand(Commands.CHANGE_JAVA_SEARCH_SCOPE, async () => {
const selection = await window.showQuickPick(["all", "main"], {
canPickMany: false,
placeHolder: `Current: ${workspace.getConfiguration().get("java.search.scope")}`,
});
if(selection) {
workspace.getConfiguration().update("java.search.scope", selection, false);
}
}));

context.subscriptions.push(snippetCompletionProvider.initialize());
context.subscriptions.push(serverStatusBarProvider);
context.subscriptions.push(languageStatusBarProvider);
Expand Down
3 changes: 2 additions & 1 deletion test/lightweight-mode-suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ suite('Java Language Extension - LightWeight', () => {
Commands.OPEN_FILE,
Commands.CLEAN_SHARED_INDEXES,
Commands.RESTART_LANGUAGE_SERVER,
Commands.FILESEXPLORER_ONPASTE
Commands.FILESEXPLORER_ONPASTE,
Commands.CHANGE_JAVA_SEARCH_SCOPE
].sort();
const foundJavaCommands = commands.filter((value) => {
return JAVA_COMMANDS.indexOf(value)>=0 || value.startsWith('java.');
Expand Down
1 change: 1 addition & 0 deletions test/standard-mode-suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ suite('Java Language Extension - Standard', () => {
Commands.RESOLVE_SOURCE_ATTACHMENT,
Commands.FILESEXPLORER_ONPASTE,
Commands.RESOLVE_PASTED_TEXT,
Commands.CHANGE_JAVA_SEARCH_SCOPE
].sort();
const foundJavaCommands = commands.filter((value) => {
return JAVA_COMMANDS.indexOf(value)>=0 || value.startsWith('java.');
Expand Down

0 comments on commit 50d5bf5

Please sign in to comment.