feat: only add suggester if dataview is enabled

This commit is contained in:
Daniel Bauer
2024-12-14 12:20:07 +01:00
parent a1245356ad
commit f60f5654c1
3 changed files with 29 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
import { App, Plugin, PluginSettingTab, Setting, TFile } from "obsidian";
import { DataviewSuggester } from "./DataviewSuggester";
import { getAPI } from "obsidian-dataview";
interface DataviewAutocompleteSettings {
// mySetting: string;
@@ -16,10 +17,6 @@ export default class DataviewAutocompletePlugin extends Plugin {
async onload() {
await this.loadSettings();
// register suggester
this.suggester = new DataviewSuggester(this, 10, true, true);
this.registerEditorSuggest(this.suggester);
this.registerEvent(
// @ts-ignore
this.app.metadataCache.on("dataview:index-ready", () => {
@@ -36,6 +33,18 @@ export default class DataviewAutocompletePlugin extends Plugin {
},
),
);
this.app.workspace.onLayoutReady(() => {
// @ts-ignore
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() {}