mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-10 14:15:29 +00:00
fix: index not building on plugin enabling
This commit is contained in:
23
src/main.ts
23
src/main.ts
@@ -1,6 +1,6 @@
|
|||||||
import { App, Plugin, PluginSettingTab, Setting, TFile } from "obsidian";
|
import { App, Plugin, PluginSettingTab, Setting, TFile } from "obsidian";
|
||||||
import { DataviewSuggester } from "./DataviewSuggester";
|
import { DataviewSuggester } from "./DataviewSuggester";
|
||||||
import { getAPI } from "obsidian-dataview";
|
import { getAPI, isPluginEnabled } from "obsidian-dataview";
|
||||||
import { SettingsTab } from "./SettingsTab";
|
import { SettingsTab } from "./SettingsTab";
|
||||||
|
|
||||||
interface DataviewAutocompleteSettings {
|
interface DataviewAutocompleteSettings {
|
||||||
@@ -15,18 +15,19 @@ const DEFAULT_SETTINGS: DataviewAutocompleteSettings = {
|
|||||||
|
|
||||||
export default class DataviewAutocompletePlugin extends Plugin {
|
export default class DataviewAutocompletePlugin extends Plugin {
|
||||||
settings: DataviewAutocompleteSettings;
|
settings: DataviewAutocompleteSettings;
|
||||||
suggester: DataviewSuggester | undefined;
|
suggester: DataviewSuggester;
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
this.addSettingTab(new SettingsTab(this.app, this));
|
this.addSettingTab(new SettingsTab(this.app, this));
|
||||||
|
|
||||||
|
this.suggester = new DataviewSuggester(this, 10, true, true);
|
||||||
|
this.registerEditorSuggest(this.suggester);
|
||||||
|
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.app.metadataCache.on("dataview:index-ready", () => {
|
this.app.metadataCache.on("dataview:index-ready", () => {
|
||||||
if (this.suggester !== undefined) {
|
|
||||||
this.suggester.onDataviewIndexReady();
|
this.suggester.onDataviewIndexReady();
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -35,24 +36,14 @@ export default class DataviewAutocompletePlugin extends Plugin {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
"dataview:metadata-change",
|
"dataview:metadata-change",
|
||||||
(type: string, file: TFile, oldPath?: string) => {
|
(type: string, file: TFile, oldPath?: string) => {
|
||||||
if (this.suggester !== undefined) {
|
|
||||||
this.suggester.onDataviewMetadataChange(type, file, oldPath);
|
this.suggester.onDataviewMetadataChange(type, file, oldPath);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.app.workspace.onLayoutReady(() => {
|
if (isPluginEnabled(this.app) && getAPI(this.app)?.index.initialized) {
|
||||||
// @ts-ignore
|
this.suggester.onDataviewIndexReady();
|
||||||
if (!Object.keys(this.app.plugins.plugins).includes("dataview")) {
|
|
||||||
console.warn("Dataview plugin not installed. Dataview Autocompletion plugin will not work.");
|
|
||||||
} else {
|
|
||||||
// register suggester, requires dataview to be loaded first.
|
|
||||||
console.log("Registering dataview autocompletion suggester");
|
|
||||||
this.suggester = new DataviewSuggester(this, 10, true, true);
|
|
||||||
this.registerEditorSuggest(this.suggester);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onunload() {}
|
onunload() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user