diff --git a/README.md b/README.md index 61614e16c4..33ecc2388e 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ The following settings are supported: - auto - on - off -* `java.sharedIndexes.location`: Specifies a common index location for all workspaces. See default values as follows: +* `java.sharedIndexes.location`: Specifies a common index location for all workspaces. See default values as follows: - Windows: First use `"$APPDATA\\.jdt\\index"`, or `"~\\.jdt\\index"` if it does not exist - macOS: `"~/Library/Caches/.jdt/index"` - Linux: First use `"$XDG_CACHE_HOME/.jdt/index"`, or `"~/.cache/.jdt/index"` if it does not exist @@ -226,6 +226,9 @@ The following settings are supported: * `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`. * `java.configuration.maven.defaultMojoExecutionAction` : Specifies default mojo execution action when no associated metadata can be detected. Defaults to `ignore`. +New in 1.16.0 +* `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`. + 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). diff --git a/package.json b/package.json index 5b005cab55..a372401ef9 100644 --- a/package.json +++ b/package.json @@ -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 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`", + "scope": "window" } } }, diff --git a/src/commands.ts b/src/commands.ts index 371448fee9..808d96b4ff 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -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. */ diff --git a/src/standardLanguageClient.ts b/src/standardLanguageClient.ts index 70828f0084..3d68cfdc5b 100644 --- a/src/standardLanguageClient.ts +++ b/src/standardLanguageClient.ts @@ -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'; @@ -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", diff --git a/src/utils.ts b/src/utils.ts index 3a22388f80..71c2ac2bfd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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";