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 24, 2023
1 parent 6572351 commit f386cc2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,17 @@ 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
* `java.refactoring.extract.interface.replace`: Specify whether to replace all the occurrences of the subtype with the new extracted interface. Defaults to `true`.
* `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).
Expand Down
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 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"
}
}
},
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
21 changes: 18 additions & 3 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, WorkspaceEdit } 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, WorkspaceEdit as LSWorkspaceEdit } from "vscode-languageclient";
import { LanguageClient, StreamInfo } from "vscode-languageclient/node";
import { apiManager } from "./apiManager";
import * as buildPath from './buildpath';
Expand Down Expand Up @@ -563,6 +563,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(await this.languageClient.protocol2CodeConverter.asWorkspaceEdit(result));
await workspace.saveAll();
}));

languages.registerCodeActionsProvider({
language: "xml",
scheme: "file",
Expand Down Expand Up @@ -716,7 +731,7 @@ export function showNoLocationFound(message: string): void {
);
}

export async function applyWorkspaceEdit(workspaceEdit: WorkspaceEdit, languageClient: LanguageClient): Promise<boolean> {
export async function applyWorkspaceEdit(workspaceEdit: LSWorkspaceEdit, languageClient: LanguageClient): Promise<boolean> {
const codeEdit = await languageClient.protocol2CodeConverter.asWorkspaceEdit(workspaceEdit);
if (codeEdit) {
return await workspace.applyEdit(codeEdit);
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 f386cc2

Please sign in to comment.