Skip to content

Commit 6a59007

Browse files
committed
rename reference
Signed-off-by: Shi Chen <chenshi@microsoft.com>
1 parent 9c65188 commit 6a59007

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,17 @@ The following settings are supported:
218218
- auto
219219
- on
220220
- off
221-
* `java.sharedIndexes.location`: Specifies a common index location for all workspaces. See default values as follows:
221+
* `java.sharedIndexes.location`: Specifies a common index location for all workspaces. See default values as follows:
222222
- Windows: First use `"$APPDATA\\.jdt\\index"`, or `"~\\.jdt\\index"` if it does not exist
223223
- macOS: `"~/Library/Caches/.jdt/index"`
224224
- Linux: First use `"$XDG_CACHE_HOME/.jdt/index"`, or `"~/.cache/.jdt/index"` if it does not exist
225225
* `java.refactoring.extract.interface.replace`: Specify whether to replace all the occurrences of the subtype with the new extracted interface. Defaults to `true`.
226226
* `java.import.maven.disableTestClasspathFlag` : Enable/disable test classpath segregation. When enabled, this permits the usage of test resources within a Maven project as dependencies within the compile scope of other projects. Defaults to `false`.
227227
* `java.configuration.maven.defaultMojoExecutionAction` : Specifies default mojo execution action when no associated metadata can be detected. Defaults to `ignore`.
228228

229+
New in 1.16.0
230+
* `java.refactoring.rename.references`: Specify whether to provide diagnostic and quick fix to rename all the references when a symbol name is manually changed without using rename refactoring. When set to `auto`, the diagnostic and quick fix will be provided if `java.autobuild.enabled` is set to `false`.
231+
229232
Semantic Highlighting
230233
===============
231234
[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

+11
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,17 @@
10801080
"type": "boolean",
10811081
"markdownDescription": "Specify whether to replace all the occurrences of the subtype with the new extracted interface.",
10821082
"default": true
1083+
},
1084+
"java.refactoring.rename.references": {
1085+
"type": "string",
1086+
"enum": [
1087+
"auto",
1088+
"on",
1089+
"off"
1090+
],
1091+
"default": "auto",
1092+
"markdownDescription": "Specify whether to provide diagnostic and quick fix to rename all the references when a symbol name is manually changed without using rename refactoring. When set to `auto`, the diagnostic and quick fix will be provided if `java.autobuild.enabled` is set to `false`",
1093+
"scope": "window"
10831094
}
10841095
}
10851096
},

src/commands.ts

+4
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ export namespace Commands {
218218
* Rename Command.
219219
*/
220220
export const RENAME_COMMAND = 'java.action.rename';
221+
/**
222+
* Rename references Command.
223+
*/
224+
export const RENAME_REFERENCES_COMMAND = 'java.action.renameReferences';
221225
/**
222226
* Navigate To Super Method Command.
223227
*/

src/standardLanguageClient.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import * as fse from 'fs-extra';
44
import { findRuntimes } from "jdk-utils";
55
import * as net from 'net';
66
import * as path from 'path';
7-
import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace } from "vscode";
8-
import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams } from "vscode-languageclient";
7+
import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit } from "vscode";
8+
import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, RenameParams, RenameRequest, TextDocumentIdentifier, TextDocumentPositionParams, Range as LSRange } from "vscode-languageclient";
99
import { LanguageClient, StreamInfo } from "vscode-languageclient/node";
1010
import { apiManager } from "./apiManager";
1111
import * as buildPath from './buildpath';
@@ -585,6 +585,21 @@ export class StandardLanguageClient {
585585
upgradeGradle(projectUri, version);
586586
}));
587587

588+
context.subscriptions.push(commands.registerCommand(Commands.RENAME_REFERENCES_COMMAND, async (fileUri: string, originalName: string, newName: string, range: LSRange) => {
589+
const edit = new WorkspaceEdit();
590+
edit.replace(Uri.parse(fileUri), this.languageClient.protocol2CodeConverter.asRange(range), originalName);
591+
await workspace.applyEdit(edit);
592+
await workspace.saveAll();
593+
const params: RenameParams = {
594+
newName: newName,
595+
textDocument: TextDocumentIdentifier.create(fileUri),
596+
position: LSPosition.create(range.start.line, range.start.character),
597+
};
598+
const result = await this.languageClient.sendRequest(RenameRequest.type, params);
599+
await workspace.applyEdit(this.languageClient.protocol2CodeConverter.asWorkspaceEdit(result));
600+
await workspace.saveAll();
601+
}));
602+
588603
languages.registerCodeActionsProvider({
589604
language: "xml",
590605
scheme: "file",

src/utils.ts

+17
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@ export function getJavaConfig(javaHome: string) {
205205
break;
206206
}
207207

208+
const isAutoBuildDisabled = javaConfig.autobuild.enabled === false;
209+
const renameReference = javaConfig.refactoring.rename.references;
210+
switch (renameReference) {
211+
case "auto":
212+
javaConfig.refactoring.rename.references = isAutoBuildDisabled;
213+
break;
214+
case "on":
215+
javaConfig.refactoring.rename.references = true;
216+
break;
217+
case "off":
218+
javaConfig.refactoring.rename.references = false;
219+
break;
220+
default:
221+
javaConfig.refactoring.rename.references = false;
222+
break;
223+
}
224+
208225
const completionCaseMatching = javaConfig.completion.matchCase;
209226
if (completionCaseMatching === "auto") {
210227
javaConfig.completion.matchCase = isInsider ? "firstLetter" : "off";

0 commit comments

Comments
 (0)