Skip to content

Commit

Permalink
rename reference
Browse files Browse the repository at this point in the history
Signed-off-by: Shi Chen <[email protected]>
  • Loading branch information
CsCherrYY committed Feb 22, 2023
1 parent 9c65188 commit 6db6503
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,17 @@
"type": "boolean",
"markdownDescription": "Specify whether to replace all the occurrences of the subtype with the new extracted interface.",
"default": true
},
"java.refactoring.rename.references": {
"type": "string",
"enum": [
"auto",
"on",
"off"
],
"default": "auto",
"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`.",
"scope": "window"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ export namespace Commands {
* Rename Command.
*/
export const RENAME_COMMAND = 'java.action.rename';
/**
* Rename references Command.
*/
export const RENAME_REFERENCES_COMMAND = 'java.action.renameReferences';
/**
* Navigate To Super Method Command.
*/
Expand Down
19 changes: 17 additions & 2 deletions src/standardLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as fse from 'fs-extra';
import { findRuntimes } from "jdk-utils";
import * as net from 'net';
import * as path from 'path';
import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace } from "vscode";
import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams } from "vscode-languageclient";
import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit } from "vscode";
import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, RenameParams, RenameRequest, TextDocumentIdentifier, TextDocumentPositionParams, Range as LSRange } from "vscode-languageclient";
import { LanguageClient, StreamInfo } from "vscode-languageclient/node";
import { apiManager } from "./apiManager";
import * as buildPath from './buildpath';
Expand Down Expand Up @@ -585,6 +585,21 @@ export class StandardLanguageClient {
upgradeGradle(projectUri, version);
}));

context.subscriptions.push(commands.registerCommand(Commands.RENAME_REFERENCES_COMMAND, async (fileUri: string, originalName: string, newName: string, range: LSRange) => {
const edit = new WorkspaceEdit();
edit.replace(Uri.parse(fileUri), this.languageClient.protocol2CodeConverter.asRange(range), originalName);
await workspace.applyEdit(edit);
await workspace.saveAll();
const params: RenameParams = {
newName: newName,
textDocument: TextDocumentIdentifier.create(fileUri),
position: LSPosition.create(range.start.line, range.start.character),
};
const result = await this.languageClient.sendRequest(RenameRequest.type, params);
await workspace.applyEdit(this.languageClient.protocol2CodeConverter.asWorkspaceEdit(result));
await workspace.saveAll();
}));

languages.registerCodeActionsProvider({
language: "xml",
scheme: "file",
Expand Down
17 changes: 17 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ export function getJavaConfig(javaHome: string) {
break;
}

const isAutoBuildDisabled = javaConfig.autobuild.enabled === false;
const renameReference = javaConfig.refactoring.rename.references;
switch (renameReference) {
case "auto":
javaConfig.refactoring.rename.references = isAutoBuildDisabled;
break;
case "on":
javaConfig.refactoring.rename.references = true;
break;
case "off":
javaConfig.refactoring.rename.references = false;
break;
default:
javaConfig.refactoring.rename.references = false;
break;
}

const completionCaseMatching = javaConfig.completion.matchCase;
if (completionCaseMatching === "auto") {
javaConfig.completion.matchCase = isInsider ? "firstLetter" : "off";
Expand Down

0 comments on commit 6db6503

Please sign in to comment.