Skip to content

Commit

Permalink
Fix redhat-developer#2649: Add support for choosing search scope
Browse files Browse the repository at this point in the history
Provide two scopes to search from for search operations such as
- reference search
- call hierarchy search

Signed-off-by: Gayan Perera <gayanper@gmail.com>
  • Loading branch information
gayanper committed Sep 17, 2024
1 parent c27ab7d commit 31de294
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,19 @@
"default": "ask",
"markdownDescription": "Specifies whether to reload the sources of the open class files when their source jar files are changed.",
"scope": "window"
},
"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"
}
}
}
Expand Down Expand Up @@ -1657,6 +1670,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
12 changes: 12 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { loadSupportedJreNames } from './jdkUtils';
import { BuildFileSelector, PICKED_BUILD_FILES, cleanupWorkspaceState } from './buildFilesSelector';
import { pasteFile } from './pasteAction';
import { ServerStatusKind } from './serverStatus';
import { searchScopeBarProvider } from './searchScopeStatusBarProvider';

const syntaxClient: SyntaxLanguageClient = new SyntaxLanguageClient();
const standardClient: StandardLanguageClient = new StandardLanguageClient();
Expand Down Expand Up @@ -545,6 +546,17 @@ 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: "Choose a Java Search Scope",
});
if(selection) {
workspace.getConfiguration().update("java.search.scope", selection, false).then(() => searchScopeBarProvider.update());
}
}));
context.subscriptions.push(searchScopeBarProvider);

context.subscriptions.push(snippetCompletionProvider.initialize());
context.subscriptions.push(serverStatusBarProvider);
context.subscriptions.push(languageStatusBarProvider);
Expand Down
41 changes: 41 additions & 0 deletions src/searchScopeStatusBarProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

import { StatusBarAlignment, StatusBarItem, window, workspace } from "vscode";
import { Disposable } from "vscode-languageclient";
import { Commands } from "./commands";

class SearchScopeStatusBarProvider implements Disposable {
private statusBarItem: StatusBarItem;

constructor() {
this.statusBarItem = window.createStatusBarItem("java.searchScope", StatusBarAlignment.Right);
this.statusBarItem.show();
this.statusBarItem.command = {
title: "%java.change.searchScope%",
command: Commands.CHANGE_JAVA_SEARCH_SCOPE,
};
this.update();
}

public dispose(): void {
this.statusBarItem?.dispose();
}

public update() {
const value = workspace.getConfiguration().get("java.search.scope");
switch(value) {
case "main": {
this.statusBarItem.text = `\$(search) Java: Main`;
this.statusBarItem.tooltip = "Current java search scope : Search only on main classpath entries";
break;
}
default: {
this.statusBarItem.text = `\$(search) Java: All`;
this.statusBarItem.tooltip = "Current java search scope : Search only on all classpath entries";
break;
}
}
}
}

export const searchScopeBarProvider: SearchScopeStatusBarProvider = new SearchScopeStatusBarProvider();

0 comments on commit 31de294

Please sign in to comment.