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

Commit 404621e

Browse files
authored
Merge pull request #631 from codestoryai/features/grab-the-references
[ide] grab the references
2 parents d8b3cc7 + 70ffdf0 commit 404621e

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 { SidecarGoToReferencesRequest, SidecarGoToRefernecesResponse } from './types';
8+
import { shouldTrackFile } from '../utilities/openTabs';
9+
10+
export async function goToReferences(request: SidecarGoToReferencesRequest): Promise<SidecarGoToRefernecesResponse> {
11+
const locations: vscode.LocationLink[] = await vscode.commands.executeCommand(
12+
'vscode.executeReferenceProvider',
13+
request.fs_file_path,
14+
request.position,
15+
);
16+
const implementations = await Promise.all(locations.map(async (location) => {
17+
const uri = location.targetUri;
18+
const range = location.targetRange;
19+
if (shouldTrackFile(uri)) {
20+
console.log('we are trakcing this uri');
21+
console.log(uri);
22+
}
23+
return {
24+
fs_file_path: uri.fsPath,
25+
range: {
26+
startPosition: {
27+
line: range.start.line,
28+
character: range.start.character,
29+
},
30+
endPosition: {
31+
line: range.end.line,
32+
character: range.end.character,
33+
},
34+
}
35+
};
36+
}));
37+
return {
38+
reference_locations: implementations,
39+
};
40+
}

extensions/codestory/src/server/requestHandler.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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 { SidecarApplyEditsRequest, SidecarDiagnosticsRequest, SidecarGoToDefinitionRequest, SidecarGoToImplementationRequest, SidecarOpenFileToolRequest, SidecarQuickFixInvocationRequest, SidecarQuickFixRequest } from './types';
6+
import { SidecarApplyEditsRequest, SidecarDiagnosticsRequest, SidecarGoToDefinitionRequest, SidecarGoToImplementationRequest, SidecarGoToReferencesRequest, SidecarOpenFileToolRequest, SidecarQuickFixInvocationRequest, SidecarQuickFixRequest } from './types';
77
import { Position, Range } from 'vscode';
88
import { getDiagnosticsFromEditor } from './diagnostics';
99
import { openFileEditor } from './openFile';
@@ -12,6 +12,7 @@ import { SIDECAR_CLIENT } from '../extension';
1212
import { goToImplementation } from './goToImplementation';
1313
import { quickFixInvocation, quickFixList } from './quickFix';
1414
import { applyEdits } from './applyEdits';
15+
import { goToReferences } from './goToReferences';
1516

1617
// Helper function to read the request body
1718
function readRequestBody(req: http.IncomingMessage): Promise<string> {
@@ -95,6 +96,13 @@ export async function handleRequest(req: http.IncomingMessage, res: http.ServerR
9596
const response = await applyEdits(request);
9697
res.writeHead(200, { 'Content-Type': 'application/json' });
9798
res.end(JSON.stringify(response));
99+
} else if (req.method === 'POST' && req.url === '/go_to_references') {
100+
console.log('go-to-references');
101+
const body = await readRequestBody(req);
102+
const request: SidecarGoToReferencesRequest = JSON.parse(body);
103+
const response = await goToReferences(request);
104+
res.writeHead(200, { 'Content-Type': 'application/json' });
105+
res.end(JSON.stringify(response));
98106
} else {
99107
console.log('HC request');
100108
res.writeHead(200, { 'Content-Type': 'application/json' });

extensions/codestory/src/server/types.ts

+12
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ export type SidecarGoToImplementationResponse = {
6868
implementation_locations: FileAndRange[];
6969
};
7070

71+
export type SidecarGoToReferencesRequest = {
72+
fs_file_path: string;
73+
position: {
74+
line: number;
75+
character: number;
76+
};
77+
};
78+
79+
export type SidecarGoToRefernecesResponse = {
80+
reference_locations: FileAndRange[];
81+
};
82+
7183
export type SidecarQuickFixRequest = {
7284
fs_file_path: string;
7385
request_id: string;

0 commit comments

Comments
 (0)