Implement updateLastModifyTime function and status bar item
- Added a new function updateLastModifyTime in askCodeUtil.ts to update the last modification time of files. - The function ignores hidden files and directories (those starting with '.'). - The function creates the directory if it does not exist before writing the file. - Added a new status bar item for AskCode in statusBarView.ts. - The status bar item checks the indexing status every 10 seconds and updates its tooltip and command accordingly.
This commit is contained in:
parent
5ebeec5f82
commit
6b96d911f0
@ -10,6 +10,7 @@ import { isValidApiKey } from '../handler/historyMessagesBase';
|
||||
|
||||
import { logger } from '../util/logger';
|
||||
import { CommandRun } from '../util/commonUtil';
|
||||
import { updateIndexingStatus, updateLastModifyTime } from '../util/askCodeUtil';
|
||||
|
||||
let indexProcess: CommandRun | null = null;
|
||||
|
||||
@ -236,11 +237,15 @@ export function registerAskCodeIndexStartCommand(context: vscode.ExtensionContex
|
||||
const pythonPath = config.pythonPath;
|
||||
const supportedFileTypes = config.supportedFileTypes;
|
||||
|
||||
updateIndexingStatus("started");
|
||||
|
||||
if (!pythonVirtualEnv) {
|
||||
await installAskCode(pythonPath, supportedFileTypes);
|
||||
} else {
|
||||
await indexCode(pythonVirtualEnv, supportedFileTypes);
|
||||
}
|
||||
|
||||
updateIndexingStatus("stopped");
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
@ -332,6 +337,7 @@ async function indexCode(pythonVirtualEnv, supportedFileTypes) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateLastModifyTime();
|
||||
logger.channel()?.info(`index finished.`);
|
||||
vscode.window.showInformationMessage('Indexing finished.');
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import { regDevChatView, regTopicView } from './contributes/views';
|
||||
import ExtensionContextHolder from './util/extensionContext';
|
||||
import { logger } from './util/logger';
|
||||
import { LoggerChannelVscode } from './util/logger_vscode';
|
||||
import { createStatusBarItem } from './panel/statusBarView';
|
||||
import { createStatusBarItem, createAskCodeStatusBarItem } from './panel/statusBarView';
|
||||
import { UiUtilWrapper } from './util/uiUtil';
|
||||
import { UiUtilVscode } from './util/uiUtil_vscode';
|
||||
|
||||
@ -49,6 +49,7 @@ function activate(context: vscode.ExtensionContext) {
|
||||
registerStatusBarItemClickCommand(context);
|
||||
|
||||
createStatusBarItem(context);
|
||||
createAskCodeStatusBarItem(context);
|
||||
|
||||
regTopicDeleteCommand(context);
|
||||
regAddTopicCommand(context);
|
||||
|
@ -1,12 +1,12 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { dependencyCheck } from './statusBarViewBase';
|
||||
import { logger } from '@/util/logger';
|
||||
import { isIndexingStopped, isNeedIndexingCode } from '../util/askCodeUtil';
|
||||
|
||||
|
||||
export function createStatusBarItem(context: vscode.ExtensionContext): vscode.StatusBarItem {
|
||||
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
|
||||
|
||||
|
||||
// Set the status bar item properties
|
||||
statusBarItem.text = `$(warning)DevChat`;
|
||||
statusBarItem.tooltip = 'DevChat is checking ..., please wait';
|
||||
@ -66,4 +66,33 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
||||
|
||||
context.subscriptions.push(statusBarItem);
|
||||
return statusBarItem;
|
||||
}
|
||||
|
||||
export function createAskCodeStatusBarItem(context: vscode.ExtensionContext): vscode.StatusBarItem {
|
||||
const askCodeBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
|
||||
|
||||
askCodeBarItem.text = `AskCode`;
|
||||
askCodeBarItem.tooltip = `Wait for check status for /ask-code`;
|
||||
askCodeBarItem.command = undefined;
|
||||
|
||||
setInterval(async () => {
|
||||
if (isIndexingStopped()) {
|
||||
if (isNeedIndexingCode()) {
|
||||
askCodeBarItem.tooltip = `Click to index code for /ask-code`;
|
||||
askCodeBarItem.command = 'DevChat.AskCodeIndexStart';
|
||||
} else {
|
||||
askCodeBarItem.tooltip = `No need to index code for /ask-code`;
|
||||
askCodeBarItem.command = undefined;
|
||||
}
|
||||
|
||||
} else {
|
||||
askCodeBarItem.tooltip = `Click to stop indexing code for /ask-code`;
|
||||
askCodeBarItem.command = 'DevChat.AskCodeIndexStop';
|
||||
}
|
||||
}, 10000);
|
||||
|
||||
askCodeBarItem.show();
|
||||
context.subscriptions.push(askCodeBarItem);
|
||||
|
||||
return askCodeBarItem;
|
||||
}
|
68
src/util/askCodeUtil.ts
Normal file
68
src/util/askCodeUtil.ts
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
Util for askCode
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { UiUtilWrapper } from './uiUtil';
|
||||
|
||||
let indexingStatus = 'stopped'; // 'started' | 'indexing' | 'stopped'
|
||||
|
||||
export function updateLastModifyTime() {
|
||||
const workspaceFolder = UiUtilWrapper.workspaceFoldersFirstPath();
|
||||
if (!workspaceFolder) {
|
||||
return;
|
||||
}
|
||||
|
||||
let files = fs.readdirSync(workspaceFolder).filter(file => !file.startsWith('.'));
|
||||
|
||||
let lastModifyTime = {};
|
||||
for (let file of files) {
|
||||
let stats = fs.statSync(path.join(workspaceFolder, file));
|
||||
lastModifyTime[file] = stats.mtime.toUTCString();
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(workspaceFolder, '.chat', '.lastModifyTime.json'), JSON.stringify(lastModifyTime));
|
||||
}
|
||||
|
||||
export function isNeedIndexingCode() {
|
||||
const workspaceFolder = UiUtilWrapper.workspaceFoldersFirstPath();
|
||||
if (!workspaceFolder) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let lastModifyTimeFile = path.join(workspaceFolder, '.chat', '.lastModifyTime.json');
|
||||
if (!fs.existsSync(lastModifyTimeFile)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let files = fs.readdirSync(workspaceFolder).filter(file => !file.startsWith('.'));
|
||||
|
||||
// load lastModifyTime from .chat/.lastModifyTime.json
|
||||
let lastModifyTime = {};
|
||||
if (fs.existsSync(lastModifyTimeFile)) {
|
||||
lastModifyTime = JSON.parse(fs.readFileSync(lastModifyTimeFile, 'utf-8'));
|
||||
}
|
||||
|
||||
for (let file of files) {
|
||||
let stats = fs.statSync(path.join(workspaceFolder, file));
|
||||
if (!lastModifyTime[file] || stats.mtime.toUTCString() !== lastModifyTime[file]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Object.keys(lastModifyTime).length !== files.length) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function updateIndexingStatus(status: string) {
|
||||
if (status === "started") {
|
||||
updateLastModifyTime();
|
||||
}
|
||||
indexingStatus = status;
|
||||
}
|
||||
|
||||
export function isIndexingStopped() {
|
||||
return indexingStatus === 'stopped';
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user