mirror of
https://github.com/shoedler/crossbow.git
synced 2026-07-22 07:40:26 +00:00
Updates logging
This commit is contained in:
parent
32441ae14c
commit
ead73191a7
5 changed files with 21 additions and 17 deletions
1
DEV.md
1
DEV.md
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
* [x] General UX Improvement
|
||||
* [ ] Add "Goto Source" action on suggestions
|
||||
* [ ] Fix occurrences hint not being updated when new occurrences are found
|
||||
|
||||
## Refactors
|
||||
|
||||
|
|
|
|||
16
main.ts
16
main.ts
|
|
@ -2,7 +2,6 @@ import { CrossbowView } from 'view/view';
|
|||
import { registerCrossbowIcons } from 'icons';
|
||||
import { CacheItem, Editor, MarkdownView, Plugin, TFile, EditorPosition, CachedMetadata } from 'obsidian';
|
||||
import { CrossbowSettingTab } from './settings';
|
||||
import { crossbowLogger } from './util';
|
||||
import './editorExtension';
|
||||
|
||||
export interface CrossbowPluginSettings {
|
||||
|
|
@ -10,6 +9,8 @@ export interface CrossbowPluginSettings {
|
|||
suggestReferencesInSameFile: boolean;
|
||||
ignoreSuggestionsWhichStartWithLowercaseLetter: boolean;
|
||||
suggestedReferencesMinimumWordLength: number;
|
||||
|
||||
useLogging: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS: CrossbowPluginSettings = {
|
||||
|
|
@ -17,6 +18,7 @@ const DEFAULT_SETTINGS: CrossbowPluginSettings = {
|
|||
suggestReferencesInSameFile: false,
|
||||
ignoreSuggestionsWhichStartWithLowercaseLetter: true,
|
||||
suggestedReferencesMinimumWordLength: 3,
|
||||
useLogging: false,
|
||||
}
|
||||
|
||||
export interface CrossbowCacheEntity {
|
||||
|
|
@ -90,14 +92,14 @@ export default class CrossbowPlugin extends Plugin {
|
|||
this.registerEvent(this.app.workspace.on('file-open', this.onFileOpen));
|
||||
this.registerEvent(this.app.metadataCache.on('changed', this.onMetadataChange));
|
||||
|
||||
crossbowLogger.debugLog('Crossbow is ready.');
|
||||
this.debugLog('Crossbow is ready.');
|
||||
}
|
||||
|
||||
public onunload = () => {
|
||||
Object.assign(this.crossbowCache, {});
|
||||
|
||||
this.getCrossbowView().unload()
|
||||
crossbowLogger.debugLog('Unloaded Crossbow.');
|
||||
this.debugLog('Unloaded Crossbow.');
|
||||
}
|
||||
|
||||
public loadSettings = async () => this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
|
|
@ -106,9 +108,11 @@ export default class CrossbowPlugin extends Plugin {
|
|||
|
||||
public saveSettings = async () => await this.saveData(this.settings);
|
||||
|
||||
public debugLog = (message: string) => this.settings.useLogging && console.log(`🏹: ${message}`);
|
||||
|
||||
private onMetadataChange = (file: TFile, data: string, cache: CachedMetadata) => {
|
||||
this.updateCrossbowCacheEntitiesOfFile(file, cache);
|
||||
crossbowLogger.debugLog(`Metadata cache updated for ${file.basename}.`);
|
||||
this.debugLog(`Metadata cache updated for ${file.basename}.`);
|
||||
|
||||
if (this.updateTimeout)
|
||||
clearTimeout(this.updateTimeout)
|
||||
|
|
@ -122,7 +126,7 @@ export default class CrossbowPlugin extends Plugin {
|
|||
const prevCurrentFile = this._currentFile;
|
||||
|
||||
this.setActiveEditorAndFile()
|
||||
crossbowLogger.debugLog('File opened.');
|
||||
this.debugLog('File opened.');
|
||||
|
||||
if (this.updateTimeout)
|
||||
clearTimeout(this.updateTimeout)
|
||||
|
|
@ -227,6 +231,6 @@ export default class CrossbowPlugin extends Plugin {
|
|||
this._currentFile = leaf.view.file;
|
||||
}
|
||||
else
|
||||
crossbowLogger.warn('Unable to determine current editor.');
|
||||
console.warn('🏹: Unable to determine current editor.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,13 @@ export class CrossbowSettingTab extends PluginSettingTab {
|
|||
else
|
||||
await this.updateSettingValue('suggestedReferencesMinimumWordLength', parseInt(value, 10));
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Enable logging')
|
||||
.setDesc('If checked, debug logs will be printed to the console')
|
||||
.addToggle(toggle => toggle
|
||||
.setValue(this.plugin.settings.useLogging)
|
||||
.onChange(async value => await this.updateSettingValue('useLogging', value)));
|
||||
}
|
||||
|
||||
private updateSettingValue = async <K extends keyof CrossbowPluginSettings>(key: K, value: CrossbowPluginSettings[K]) => {
|
||||
|
|
|
|||
7
util.ts
7
util.ts
|
|
@ -114,10 +114,3 @@ export function stripMarkdown(md: string, options?: StripMarkdownOptions) {
|
|||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
const crossbowLogPrefix = '🏹: ';
|
||||
|
||||
export const crossbowLogger = {
|
||||
debugLog: (message: string) => process.env.NODE_ENV === 'development' && console.log(`${crossbowLogPrefix}${message}`),
|
||||
warn: (message: string) => console.warn(`${crossbowLogPrefix}${message}`),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ItemView,
|
||||
WorkspaceLeaf,
|
||||
} from 'obsidian';
|
||||
import { crossbowLogger } from '../util';
|
||||
import { TreeItem, TreeItemLeaf } from './treeItem';
|
||||
|
||||
type LeafTreeItem = TreeItemLeaf<CrossbowCacheMatch>
|
||||
|
|
@ -78,7 +77,7 @@ export class CrossbowView extends ItemView {
|
|||
}
|
||||
|
||||
public updateSuggestions = (suggestions: CrossbowSuggestion[], fileHasChanged: boolean) => {
|
||||
crossbowLogger.debugLog(`${fileHasChanged ? "Clearing & adding" : "Updating"} suggestions`);
|
||||
this.crossbow.debugLog(`${fileHasChanged ? "Clearing & adding" : "Updating"} suggestions`);
|
||||
|
||||
const occurrenceHash = (o: EditorPosition) => o.line + ":" + o.ch;
|
||||
const matchHash = (o: CrossbowCacheMatch) => o.file.path;
|
||||
|
|
@ -211,8 +210,8 @@ export class CrossbowView extends ItemView {
|
|||
});
|
||||
|
||||
// Go to source action
|
||||
matchItem.addButton("Source", 'lucide-search', () => {
|
||||
crossbowLogger.warn("Go To Source is not yet implemented");
|
||||
matchItem.addButton("Go To Source", 'lucide-search', () => {
|
||||
console.warn("🏹: 'Go To Source' is not yet implemented");
|
||||
});
|
||||
|
||||
occurrenceTreeItem.addChild(matchItem);
|
||||
|
|
|
|||
Loading…
Reference in a new issue