Skip to content

Commit

Permalink
Improve code actions by using "java/getChangeSignatureInfo". (#3845)
Browse files Browse the repository at this point in the history
- Use the custom request to get signature information to populate the necessary UI elements

Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza authored Nov 19, 2024
1 parent 4bf5287 commit db41286
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,27 @@ export namespace GetRefactorEditRequest {
export const type = new RequestType<GetRefactorEditParams, RefactorWorkspaceEdit, void>('java/getRefactorEdit');
}

export namespace GetChangeSignatureInfoRequest {
export const type = new RequestType<CodeActionParams, ChangeSignatureInfo, void>('java/getChangeSignatureInfo');
}

export interface SelectionInfo {
name: string;
length: number;
offset: number;
params?: string[];
}

export interface ChangeSignatureInfo {
methodIdentifier: string;
modifier: string;
returnType: string;
methodName: string;
parameters: any;
exceptions: any;
errorMessage: string;
}

export interface InferSelectionParams {
command: string;
context: CodeActionParams;
Expand Down
9 changes: 7 additions & 2 deletions src/refactorAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { commands, ExtensionContext, Position, QuickPickItem, TextDocument, Uri,
import { FormattingOptions, WorkspaceEdit, RenameFile, DeleteFile, TextDocumentEdit, CodeActionParams, SymbolInformation } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';
import { Commands as javaCommands } from './commands';
import { GetRefactorEditRequest, MoveRequest, RefactorWorkspaceEdit, RenamePosition, GetMoveDestinationsRequest, SearchSymbols, SelectionInfo, InferSelectionRequest } from './protocol';
import { GetRefactorEditRequest, MoveRequest, RefactorWorkspaceEdit, RenamePosition, GetMoveDestinationsRequest, SearchSymbols, SelectionInfo, InferSelectionRequest, GetChangeSignatureInfoRequest, ChangeSignatureInfo } from './protocol';
import { ChangeSignaturePanel } from './refactoring/changeSignaturePanel';
import { getExtractInterfaceArguments, revealExtractedInterface } from './refactoring/extractInterface';

Expand Down Expand Up @@ -112,7 +112,12 @@ function registerApplyRefactorCommand(languageClient: LanguageClient, context: E
}
commandArguments.push(...args);
} else if (command === 'changeSignature') {
ChangeSignaturePanel.render(context.extensionUri, languageClient, command, params, formattingOptions, commandInfo);
const changeSignatureInfo: ChangeSignatureInfo = await languageClient.sendRequest(GetChangeSignatureInfoRequest.type, params);
if (changeSignatureInfo.errorMessage !== undefined) {
window.showWarningMessage(changeSignatureInfo.errorMessage);
return;
}
ChangeSignaturePanel.render(context.extensionUri, languageClient, command, params, formattingOptions, changeSignatureInfo);
return;
}

Expand Down

0 comments on commit db41286

Please sign in to comment.