diff --git a/src/DoiProcessing.ts b/src/DoiProcessing.ts index 24814f2..1ac9cdc 100644 --- a/src/DoiProcessing.ts +++ b/src/DoiProcessing.ts @@ -14,6 +14,7 @@ export class DoiProcessing{ private static instance: DoiProcessing|null = null; private timedVisitedFiles: { timeStamp: string, filePath: string }[] = []; + private timedCaretPositions: { timeStamp: string, filePath: string, startOffset:string, endOffset: string }[] = []; public constructor(projectPath:string,ws:WebSocket|null){ this.projectPath=projectPath; @@ -40,6 +41,7 @@ export class DoiProcessing{ private monitorWorkSpaceBehavior(){ // Listening for file opening events in VSCode vscode.workspace.onDidOpenTextDocument(this.newVisitedFile.bind(this)); + vscode.window.onDidChangeTextEditorSelection(this.newCaretPosition.bind(this)); } @@ -48,6 +50,48 @@ export class DoiProcessing{ return this.timedVisitedFiles; } + public getVisitedElements():{timeStamp:string,filePath:string,startOffset:string,endOffset:string}[]{ + return this.timedCaretPositions; + } + + private newCaretPosition(event: vscode.TextEditorSelectionChangeEvent): void { + const activeEditor = vscode.window.activeTextEditor; + if (!activeEditor) { + return; + } + + const filePath = activeEditor.document.uri.fsPath; + const selection = event.selections[0]; // If handling multiple selections, you may need to adjust this + const startOffset = activeEditor.document.offsetAt(selection.start); + const endOffset = activeEditor.document.offsetAt(selection.end); + + this.updateCaretPositions(filePath, startOffset, endOffset); + } + + private updateCaretPositions(filePath: string, startOffset: number, endOffset: number): void { + const currentTime = new Date().getTime().toString(); + //const currentTimeInString = new Date().getTime().toString(); + if(this.timedCaretPositions.length>1){ + const currentTimeInNumber = parseFloat(currentTime); + const lastTime = parseFloat(this.timedCaretPositions[this.timedCaretPositions.length-1].timeStamp); + if(currentTimeInNumber-lastTime<1000){ + this.timedCaretPositions.pop(); + } + + if(this.timedCaretPositions.length===100){ + this.timedCaretPositions.pop(); + } + } + + const startOffsetAsString: string = String(startOffset); + const endOffsetAsString: string = String(endOffset); + this.timedCaretPositions.push({ timeStamp: currentTime, filePath: filePath.replace(/\\/g, '/'), startOffset:startOffsetAsString, endOffset:endOffsetAsString }); + + // Optionally, send this information over WebSocket or process it further + + } + + private newVisitedFile(document: vscode.TextDocument): void { const filePath = document.uri.fsPath; diff --git a/src/FileChangeManager.ts b/src/FileChangeManager.ts index c57e683..66780df 100644 --- a/src/FileChangeManager.ts +++ b/src/FileChangeManager.ts @@ -307,7 +307,7 @@ export class FileChangeManager { console.error(`Error in srcML output for file ${inputFilePath}:`, stderr); reject(new Error(stderr)); } else { - console.log(`Converted to XML: ${inputFilePath}`); + //console.log(`Converted to XML: ${inputFilePath}`); resolve(stdout); // stdout contains the XML content } }); @@ -337,7 +337,7 @@ export class FileChangeManager { console.error(`Error sending XML for file ${filePath}:`, error); reject(error); // Stop sending if an error occurs } else { - console.log(`Sent XML for file ${filePath}`); + //console.log(`Sent XML for file ${filePath}`); resolve(); } }); diff --git a/src/extension.ts b/src/extension.ts index d50683d..cd16b90 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -15,7 +15,7 @@ import { DoiProcessing } from './DoiProcessing'; //const readFileAsync = promisify(fs.readFile); -const port = 8887; +const port = 9000; @@ -149,8 +149,7 @@ export function activate(context: vscode.ExtensionContext) { const doiData = { recentVisitedFiles:doiProcessing.getVisitedFiles(), - recentSearches:[], - recentElements:[] + recentElements:doiProcessing.getVisitedElements() }; ws.send(JSON.stringify({