mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-05-07 13:54:42 +02:00
Internal optimizations
This commit is contained in:
@@ -699,9 +699,8 @@ export class ArticleHelper {
|
||||
* @returns
|
||||
*/
|
||||
public static getActiveFile() {
|
||||
const editors = window.visibleTextEditors;
|
||||
if (editors.length === 1) {
|
||||
const editor = editors[0];
|
||||
const editor = window.activeTextEditor;
|
||||
if (editor) {
|
||||
const filePath = parseWinPath(editor.document.uri.fsPath);
|
||||
if (isValidFile(filePath)) {
|
||||
return filePath;
|
||||
|
||||
@@ -21,6 +21,7 @@ import { unlinkAsync, rmdirAsync } from '../../utils';
|
||||
|
||||
export class PagesListener extends BaseListener {
|
||||
private static watchers: { [path: string]: FileSystemWatcher } = {};
|
||||
private static watchersPromises: { [path: string]: Promise<void> } = {};
|
||||
private static lastPages: Page[] = [];
|
||||
|
||||
/**
|
||||
@@ -158,29 +159,38 @@ export class PagesListener extends BaseListener {
|
||||
* @param file
|
||||
*/
|
||||
private static async watcherExec(file: Uri) {
|
||||
const ext = Extension.getInstance();
|
||||
Logger.info(`File watcher execution for: ${file.fsPath}`);
|
||||
const progressFile = async (file: Uri) => {
|
||||
const ext = Extension.getInstance();
|
||||
Logger.info(`File watcher execution for: ${file.fsPath}`);
|
||||
|
||||
const pageIdx = this.lastPages.findIndex((p) => p.fmFilePath === file.fsPath);
|
||||
if (pageIdx !== -1) {
|
||||
const stats = await workspace.fs.stat(file);
|
||||
const crntPage = this.lastPages[pageIdx];
|
||||
const updatedPage = await PagesParser.processPageContent(
|
||||
file.fsPath,
|
||||
stats.mtime,
|
||||
basename(file.fsPath),
|
||||
crntPage.fmFolder
|
||||
);
|
||||
if (updatedPage) {
|
||||
this.lastPages[pageIdx] = updatedPage;
|
||||
if (Dashboard.isOpen) {
|
||||
this.sendPageData(this.lastPages);
|
||||
const pageIdx = this.lastPages.findIndex((p) => p.fmFilePath === file.fsPath);
|
||||
if (pageIdx !== -1) {
|
||||
const stats = await workspace.fs.stat(file);
|
||||
const crntPage = this.lastPages[pageIdx];
|
||||
const updatedPage = await PagesParser.processPageContent(
|
||||
file.fsPath,
|
||||
stats.mtime,
|
||||
basename(file.fsPath),
|
||||
crntPage.fmFolder
|
||||
);
|
||||
if (updatedPage) {
|
||||
this.lastPages[pageIdx] = updatedPage;
|
||||
if (Dashboard.isOpen) {
|
||||
this.sendPageData(this.lastPages);
|
||||
}
|
||||
await ext.setState(ExtensionState.Dashboard.Pages.Cache, this.lastPages, 'workspace');
|
||||
}
|
||||
await ext.setState(ExtensionState.Dashboard.Pages.Cache, this.lastPages, 'workspace');
|
||||
} else {
|
||||
this.getPagesData(true);
|
||||
}
|
||||
} else {
|
||||
this.getPagesData(true);
|
||||
};
|
||||
|
||||
const watcherPromise = this.watchersPromises[file.fsPath];
|
||||
if (!watcherPromise) {
|
||||
this.watchersPromises[file.fsPath] = progressFile(file);
|
||||
}
|
||||
await this.watchersPromises[file.fsPath];
|
||||
delete this.watchersPromises[file.fsPath];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user