Skip to content

Commit cb5b588

Browse files
authored
Fix issue with Generate Doxygen Comment context menu (#9950)
1 parent adb9a41 commit cb5b588

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ export interface Client {
682682
handleConfigurationEditUICommand(viewColumn?: vscode.ViewColumn): void;
683683
handleAddToIncludePathCommand(path: string): void;
684684
handleGoToDirectiveInGroup(next: boolean): Promise<void>;
685-
handleGenerateDoxygenComment(codeActionArguments: DoxygenCodeActionCommandArguments | undefined): Promise<void>;
685+
handleGenerateDoxygenComment(args: DoxygenCodeActionCommandArguments | vscode.Uri | undefined): Promise<void>;
686686
handleCheckForCompiler(): Promise<void>;
687687
handleRunCodeAnalysisOnActiveFile(): Promise<void>;
688688
handleRunCodeAnalysisOnOpenFiles(): Promise<void>;
@@ -2727,7 +2727,7 @@ export class DefaultClient implements Client {
27272727
}
27282728
}
27292729

2730-
public async handleGenerateDoxygenComment(codeActionArguments: DoxygenCodeActionCommandArguments | undefined): Promise<void> {
2730+
public async handleGenerateDoxygenComment(args: DoxygenCodeActionCommandArguments | vscode.Uri | undefined): Promise<void> {
27312731
const editor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
27322732
if (!editor) {
27332733
return;
@@ -2741,12 +2741,15 @@ export class DefaultClient implements Client {
27412741
return;
27422742
}
27432743

2744-
const isCodeAction: boolean = codeActionArguments !== undefined;
2745-
const initCursorPosition: vscode.Position = codeActionArguments !== undefined ? new vscode.Position(codeActionArguments.initialCursor.line, codeActionArguments.initialCursor.character) : editor.selection.active;
2744+
let codeActionArguments: DoxygenCodeActionCommandArguments | undefined;
2745+
if (args !== undefined && !(args instanceof vscode.Uri)) {
2746+
codeActionArguments = args;
2747+
}
2748+
const initCursorPosition: vscode.Position = (codeActionArguments !== undefined) ? new vscode.Position(codeActionArguments.initialCursor.line, codeActionArguments.initialCursor.character) : editor.selection.active;
27462749
const params: GenerateDoxygenCommentParams = {
27472750
uri: editor.document.uri.toString(),
27482751
position: (codeActionArguments !== undefined) ? new vscode.Position(codeActionArguments.adjustedCursor.line, codeActionArguments.adjustedCursor.character) : editor.selection.active,
2749-
isCodeAction: isCodeAction,
2752+
isCodeAction: codeActionArguments !== undefined,
27502753
isCursorAboveSignatureLine: codeActionArguments?.isCursorAboveSignatureLine
27512754
};
27522755
await this.awaitUntilLanguageClientReady();
@@ -2770,7 +2773,7 @@ export class DefaultClient implements Client {
27702773
// The reason why we need to set different range is because if cursor is immediately above the signature line, we want the comments to be inserted at the line of cursor and to replace everything on the line.
27712774
// If the cursor is on the signature line or is inside the boby, the comment will be inserted on the same line of the signature and it shouldn't replace the content of the signature line.
27722775
if (cursorOnEmptyLineAboveSignature) {
2773-
if (isCodeAction) {
2776+
if (codeActionArguments !== undefined) {
27742777
// The reson why we cannot use finalInsertionLine is because the line number sent from the result is not correct.
27752778
// In most cases, the finalInsertionLine is the line of the signature line.
27762779
newRange = new vscode.Range(initCursorPosition.line, 0, initCursorPosition.line, maxColumn);
@@ -2785,7 +2788,7 @@ export class DefaultClient implements Client {
27852788
await vscode.workspace.applyEdit(workspaceEdit);
27862789
// Set the cursor position after @brief
27872790
let newPosition: vscode.Position;
2788-
if (cursorOnEmptyLineAboveSignature && isCodeAction) {
2791+
if (cursorOnEmptyLineAboveSignature && codeActionArguments !== undefined) {
27892792
newPosition = new vscode.Position(result.finalCursorPosition.line - 1, result.finalCursorPosition.character);
27902793
} else {
27912794
newPosition = new vscode.Position(result.finalCursorPosition.line, result.finalCursorPosition.character);
@@ -3074,7 +3077,7 @@ class NullClient implements Client {
30743077
handleConfigurationEditUICommand(viewColumn?: vscode.ViewColumn): void { }
30753078
handleAddToIncludePathCommand(path: string): void { }
30763079
handleGoToDirectiveInGroup(next: boolean): Promise<void> { return Promise.resolve(); }
3077-
handleGenerateDoxygenComment(codeActionArguments: DoxygenCodeActionCommandArguments | undefined): Promise<void> { return Promise.resolve(); }
3080+
handleGenerateDoxygenComment(args: DoxygenCodeActionCommandArguments | vscode.Uri | undefined): Promise<void> { return Promise.resolve(); }
30783081
handleCheckForCompiler(): Promise<void> { return Promise.resolve(); }
30793082
handleRunCodeAnalysisOnActiveFile(): Promise<void> { return Promise.resolve(); }
30803083
handleRunCodeAnalysisOnOpenFiles(): Promise<void> { return Promise.resolve(); }

0 commit comments

Comments
 (0)