Skip to content

Commit a6eff82

Browse files
authored
Add internal formatting support for Copy Declaration/Definition (#12055)
* Add text formatting for CopyDD * fix lint issues * Plumb up editor settings msg * add vcFormat param * Add formatParams to CDD + rollback changes * fix lint issue * update defaults * Reafctor formatParams correctly for vcFormat and .editor_config * populate editorConfigSettings * minor fix * minor fix
1 parent 751fd74 commit a6eff82

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ interface PublishRefactorDiagnosticsParams {
294294
}
295295

296296
export interface CreateDeclarationOrDefinitionParams extends SelectionParams {
297+
formatParams: FormatParams;
297298
copyToClipboard: boolean;
298299
}
299300

@@ -3438,8 +3439,11 @@ export class DefaultClient implements Client {
34383439
public async handleCreateDeclarationOrDefinition(isCopyToClipboard: boolean, codeActionRange?: Range): Promise<void> {
34393440
let range: vscode.Range | undefined;
34403441
let uri: vscode.Uri | undefined;
3441-
34423442
const editor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
3443+
3444+
const editorSettings: OtherSettings = new OtherSettings(uri);
3445+
const cppSettings: CppSettings = new CppSettings(uri);
3446+
34433447
if (editor) {
34443448
uri = editor.document.uri;
34453449
if (codeActionRange !== undefined) {
@@ -3457,10 +3461,55 @@ export class DefaultClient implements Client {
34573461
}
34583462
}
34593463

3460-
if (uri === undefined || range === undefined) {
3464+
if (uri === undefined || range === undefined || editor === undefined) {
34613465
return;
34623466
}
34633467

3468+
let formatParams: FormatParams | undefined;
3469+
if (cppSettings.useVcFormat(editor.document))
3470+
{
3471+
const editorConfigSettings: any = getEditorConfigSettings(uri.fsPath);
3472+
formatParams = {
3473+
editorConfigSettings: editorConfigSettings,
3474+
useVcFormat: true,
3475+
insertSpaces: editorConfigSettings.indent_style !== undefined ? editorConfigSettings.indent_style === "space" ? true : false : true,
3476+
tabSize: editorConfigSettings.tab_width !== undefined ? editorConfigSettings.tab_width : 4,
3477+
character: "",
3478+
range: {
3479+
start: {
3480+
character: 0,
3481+
line: 0
3482+
},
3483+
end: {
3484+
character: 0,
3485+
line: 0
3486+
}
3487+
},
3488+
onChanges: false,
3489+
uri: ''
3490+
};
3491+
} else {
3492+
formatParams = {
3493+
editorConfigSettings: {},
3494+
useVcFormat: false,
3495+
insertSpaces: editorSettings.editorInsertSpaces !== undefined ? editorSettings.editorInsertSpaces : true,
3496+
tabSize: editorSettings.editorTabSize !== undefined ? editorSettings.editorTabSize : 4,
3497+
character: "",
3498+
range: {
3499+
start: {
3500+
character: 0,
3501+
line: 0
3502+
},
3503+
end: {
3504+
character: 0,
3505+
line: 0
3506+
}
3507+
},
3508+
onChanges: false,
3509+
uri: ''
3510+
};
3511+
}
3512+
34643513
const params: CreateDeclarationOrDefinitionParams = {
34653514
uri: uri.toString(),
34663515
range: {
@@ -3473,6 +3522,7 @@ export class DefaultClient implements Client {
34733522
line: range.end.line
34743523
}
34753524
},
3525+
formatParams: formatParams,
34763526
copyToClipboard: isCopyToClipboard
34773527
};
34783528

@@ -3496,7 +3546,6 @@ export class DefaultClient implements Client {
34963546
return;
34973547
}
34983548

3499-
// Handle copy to clipboard.
35003549
if (result.clipboardText && params.copyToClipboard) {
35013550
return vscode.env.clipboard.writeText(result.clipboardText);
35023551
}

0 commit comments

Comments
 (0)