Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3ab767b

Browse files
committed
[sidecar] generate quick list for errors
1 parent 3d512de commit 3ab767b

File tree

4 files changed

+98
-2
lines changed

4 files changed

+98
-2
lines changed

extensions/codestory/src/extension.ts

+44-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
import { commands, ExtensionContext, interactive, window, workspace, languages, modelSelection, env, csevents } from 'vscode';
5+
import { commands, ExtensionContext, interactive, window, workspace, languages, modelSelection, env, csevents, Uri, Position } from 'vscode';
66
import * as os from 'os';
77
import * as http from 'http';
88

@@ -302,4 +302,47 @@ export async function activate(context: ExtensionContext) {
302302
);
303303
}
304304
});
305+
306+
307+
// TODO(skcd): I promise to clean this up better, I am trying to see if things still
308+
// work if I wait here and check the diagnostics and if its working
309+
// await new Promise(resolve => setTimeout(resolve, 20000));
310+
// // over here we will execute the code action provider
311+
// try {
312+
// const textDocumentUri = Uri.file('/Users/skcd/scratch/sidecar/sidecar/src/agentic/symbol/helpers.rs');
313+
// // opens the text document as required
314+
// await workspace.openTextDocument(textDocumentUri);
315+
// const range = new vscode.Range(new Position(3, 24), new Position(3, 25));
316+
// const codeActions: vscode.CodeAction[] = await commands.executeCommand(
317+
// 'vscode.executeCodeActionProvider',
318+
// textDocumentUri,
319+
// range,
320+
// );
321+
// console.log('code actions worked');
322+
// // lets see what happens over here
323+
// console.log(codeActions);
324+
// const firstCodeActionCommand = codeActions[1].command;
325+
// const firstCodeArguments = codeActions[1].command?.arguments;
326+
// try {
327+
// if (firstCodeActionCommand !== undefined && firstCodeArguments !== undefined) {
328+
// // console.log(firstCodeAction.command);
329+
// // console.log(firstCodeAction.arguments);
330+
// console.log(firstCodeArguments[0]);
331+
// const firstArgument = firstCodeArguments[0][0].arguments;
332+
// console.log(firstArgument);
333+
// const result = await commands.executeCommand('rust-analyzer.resolveCodeAction', firstArgument);
334+
// // const result = await commands.executeCommand(firstCodeActionCommand.command, ...firstCodeArguments);
335+
// console.log('sub results from result');
336+
// console.log(result);
337+
// } else {
338+
// console.log('missing command');
339+
// }
340+
// } catch (exception) {
341+
// console.log(exception);
342+
// }
343+
// // await commands.executeCommand(codeActions[0].command, ...codeActions[1].arguments);
344+
// } catch (exception) {
345+
// console.log('code action execution error');
346+
// console.error(exception);
347+
// }
305348
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { SidecarQuickFixRequest, SidecarQuickFixResponse } from './types';
8+
9+
// TODO(skcd): This is not complete yet, we have to invoke the request
10+
// multiple times and then invoke the request and save the changes
11+
export async function quickFixList(request: SidecarQuickFixRequest): Promise<SidecarQuickFixResponse> {
12+
const textDocumentUri = vscode.Uri.file(request.fs_file_path);
13+
await vscode.workspace.openTextDocument(textDocumentUri);
14+
const codeActions: vscode.CodeAction[] = await vscode.commands.executeCommand(
15+
'vscode.executeCodeActionProvider',
16+
textDocumentUri,
17+
request.range,
18+
);
19+
// Over here try to get all the code actions which we need to execute
20+
const titles = codeActions.map((codeAction) => {
21+
return codeAction.title;
22+
});
23+
return {
24+
options: titles,
25+
};
26+
}

extensions/codestory/src/server/requestHandler.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55
import * as http from 'http';
6-
import { SidecarDiagnosticsRequest, SidecarGoToDefinitionRequest, SidecarGoToImplementationRequest, SidecarOpenFileToolRequest } from './types';
6+
import { SidecarDiagnosticsRequest, SidecarGoToDefinitionRequest, SidecarGoToImplementationRequest, SidecarOpenFileToolRequest, SidecarQuickFixRequest } from './types';
77
import { Position, Range } from 'vscode';
88
import { getDiagnosticsFromEditor } from './diagnostics';
99
import { openFileEditor } from './openFile';
1010
import { goToDefinition } from './goToDefinition';
1111
import { SIDECAR_CLIENT } from '../extension';
1212
import { goToImplementation } from './goToImplementation';
13+
import { quickFixList } from './quickFix';
1314

1415
// Helper function to read the request body
1516
function readRequestBody(req: http.IncomingMessage): Promise<string> {
@@ -72,6 +73,13 @@ export async function handleRequest(req: http.IncomingMessage, res: http.ServerR
7273
const response = await goToImplementation(request);
7374
res.writeHead(200, { 'Content-Type': 'application/json' });
7475
res.end(JSON.stringify(response));
76+
} else if (req.method === 'POST' && req.url === '/invoke_quick_fix') {
77+
console.log('quick-fix');
78+
const body = await readRequestBody(req);
79+
const request: SidecarQuickFixRequest = JSON.parse(body);
80+
const response = await quickFixList(request);
81+
res.writeHead(200, { 'Content-Type': 'application/json' });
82+
res.end(JSON.stringify(response));
7583
} else {
7684
console.log('HC request');
7785
res.writeHead(200, { 'Content-Type': 'application/json' });

extensions/codestory/src/server/types.ts

+19
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,22 @@ export type SidecarGoToImplementationRequest = {
6767
export type SidecarGoToImplementationResponse = {
6868
implementation_locations: FileAndRange[];
6969
};
70+
71+
export type SidecarQuickFixRequest = {
72+
fs_file_path: string;
73+
range: {
74+
startPosition: {
75+
line: number;
76+
character: number;
77+
};
78+
endPosition: {
79+
line: number;
80+
character: number;
81+
};
82+
};
83+
};
84+
85+
// Keeping it simple for now
86+
export type SidecarQuickFixResponse = {
87+
options: string[];
88+
};

0 commit comments

Comments
 (0)