@@ -32,41 +32,12 @@ import { AideQuickFix } from './quickActions/fix';
32
32
import { copySettings } from './utilities/copySettings' ;
33
33
34
34
35
+ export let SIDECAR_CLIENT : SideCarClient | null = null ;
36
+
37
+
35
38
36
39
export async function activate ( context : ExtensionContext ) {
37
40
// Project root here
38
- // start a stupid server here
39
- const server = http . createServer ( handleRequest ) ;
40
- let port = 42423 ; // Default chooses 42423, but if its not available then we
41
- // can still grab it by listenting to port 0
42
- server . listen ( port , ( ) => {
43
- console . log ( `Server for talking to sidecar is running at http://localhost:${ port } /` ) ;
44
- } )
45
- . on ( 'error' , ( err : NodeJS . ErrnoException ) => {
46
- if ( err . code === 'EADDRINUSE' ) {
47
- console . error ( `Port ${ port } is already in use, trying another port...` ) ;
48
- server . listen ( 0 , ( ) => {
49
- const serverAddress = server . address ( ) ;
50
- if ( serverAddress ) {
51
- const newAddress : AddressInfo = serverAddress as AddressInfo ;
52
- port = newAddress . port ;
53
- }
54
- console . log ( serverAddress ) ;
55
- console . log ( `Server for talking to sidecar is running at http://localhost:${ server . address ( ) } /` ) ;
56
- } ) ; // Use 0 to let the OS pick an available port
57
- } else {
58
- console . error ( `Failed to start server: ${ err . message } ` ) ;
59
- }
60
- } ) ;
61
-
62
- // Register a disposable to stop the server when the extension is deactivated
63
- context . subscriptions . push ( {
64
- dispose : ( ) => {
65
- if ( server ) {
66
- server . close ( ) ;
67
- }
68
- } ,
69
- } ) ;
70
41
const uniqueUserId = getUniqueId ( ) ;
71
42
const userId = getUserId ( ) ;
72
43
console . log ( 'User id:' + userId ) ;
@@ -166,6 +137,41 @@ export async function activate(context: ExtensionContext) {
166
137
// allow-any-unicode-next-line
167
138
// window.showInformationMessage(`Sidecar binary 🦀 started at ${sidecarUrl}`);
168
139
const sidecarClient = new SideCarClient ( sidecarUrl , modelConfiguration ) ;
140
+ SIDECAR_CLIENT = sidecarClient ;
141
+
142
+ // Server for the sidecar to talk to the editor
143
+ const server = http . createServer ( handleRequest ) ;
144
+ let port = 42423 ; // Default chooses 42423, but if its not available then we
145
+ // can still grab it by listenting to port 0
146
+ server . listen ( port , ( ) => {
147
+ console . log ( `Server for talking to sidecar is running at http://localhost:${ port } /` ) ;
148
+ } )
149
+ . on ( 'error' , ( err : NodeJS . ErrnoException ) => {
150
+ if ( err . code === 'EADDRINUSE' ) {
151
+ console . error ( `Port ${ port } is already in use, trying another port...` ) ;
152
+ server . listen ( 0 , ( ) => {
153
+ const serverAddress = server . address ( ) ;
154
+ if ( serverAddress ) {
155
+ const newAddress : AddressInfo = serverAddress as AddressInfo ;
156
+ port = newAddress . port ;
157
+ }
158
+ console . log ( serverAddress ) ;
159
+ console . log ( `Server for talking to sidecar is running at http://localhost:${ server . address ( ) } /` ) ;
160
+ } ) ; // Use 0 to let the OS pick an available port
161
+ } else {
162
+ console . error ( `Failed to start server: ${ err . message } ` ) ;
163
+ }
164
+ } ) ;
165
+
166
+ // Register a disposable to stop the server when the extension is deactivated
167
+ context . subscriptions . push ( {
168
+ dispose : ( ) => {
169
+ if ( server ) {
170
+ server . close ( ) ;
171
+ }
172
+ } ,
173
+ } ) ;
174
+
169
175
// we want to send the open tabs here to the sidecar
170
176
const openTextDocuments = await getRelevantFiles ( ) ;
171
177
openTextDocuments . forEach ( ( openTextDocument ) => {
@@ -254,26 +260,6 @@ export async function activate(context: ExtensionContext) {
254
260
) ;
255
261
context . subscriptions . push ( chatAgentProvider ) ;
256
262
257
- // Also track the documents when they were last opened
258
- // context.subscriptions.push(
259
- // workspace.onDidOpenTextDocument(async (doc) => {
260
- // const uri = doc.uri;
261
- // console.log('document open');
262
- // // TODO(skcd): we want to send the file open event to the sidecar client
263
- // if (shouldTrackFile(uri)) {
264
- // console.log('we are tracking uri', uri.scheme);
265
- // await sidecarClient.documentOpen(uri.fsPath, doc.getText(), doc.languageId);
266
- // }
267
- // });
268
-
269
- // // Listen for active editor change events (user navigating between files)
270
- // window.onDidChangeActiveTextEditor(async (editor) => {
271
- // activeFilesTracker.onDidChangeActiveTextEditor(editor);
272
- // // if we are going to change the active text editor, then we should tell
273
- // // the sidecar about it
274
- // await changedActiveDocument(editor, sidecarClient);
275
- // });
276
-
277
263
// Register feedback commands
278
264
context . subscriptions . push (
279
265
commands . registerCommand ( 'codestory.feedback' , async ( ) => {
0 commit comments