Skip to content

Commit 6db6503

Browse files
committed
rename reference
Signed-off-by: Shi Chen <[email protected]>
1 parent 9c65188 commit 6db6503

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

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 diagnostics and corresponding quick fix when a symbol name is manually changed without using Rename refactoring. When set to `auto`, the diagnotics 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)