Skip to content

Commit

Permalink
fix: ts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Jan 12, 2023
1 parent cb7349a commit 7f9e5a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 15 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { App, Editor, EditorPosition, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { App, Editor, EditorPosition, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, FileSystemAdapter } from 'obsidian';
import { exec } from 'child_process';
import { existsSync, writeFileSync } from 'fs';
import { resolve } from 'path';

const DEFAULT_OUTPUT_LIMIT = 1000;

function getVaultRoot(app: App) {
return (app.vault.adapter as FileSystemAdapter).getBasePath();
}

interface Codeblock {
lang: string,
code: string,
Expand All @@ -18,8 +22,8 @@ function getCodeblockForCursor(editor: Editor): Codeblock | null {
const cljRe = /^```(clojure|clojurescript)$\s([\s\S]*?)^```$/gmd;
const cljCodeblocks = Array.from(src.matchAll(cljRe));
const cursorOffset = editor.posToOffset(cursor);
const insideMatch = offset => match => match.indices[0][0] <= offset && offset <= match.indices[0][1];
const match = cljCodeblocks.find(insideMatch(cursorOffset));
const insideMatch = (offset: any) => (match: any) => match.indices[0][0] <= offset && offset <= match.indices[0][1];
const match: any = cljCodeblocks.find(insideMatch(cursorOffset));

if (match) {
return {
Expand Down Expand Up @@ -63,7 +67,7 @@ function resolvePluginFolder(vaultPath: string, settings: PluginSettings) {
}

function writeVaultBindingsNs(app: App, view: MarkdownView, settings: PluginSettings) {
const vaultPath = app.vault.adapter.getBasePath();
const vaultPath = getVaultRoot(this.app);
const pluginFolder = resolvePluginFolder(vaultPath, settings);
const bindingsNsPath = `${pluginFolder}/gen/vault_bindings.cljc`;

Expand All @@ -82,7 +86,7 @@ function writeVaultBindingsNs(app: App, view: MarkdownView, settings: PluginSett
}

function writeDefaultBbEdn(app: App, settings: PluginSettings) {
const vaultPath = app.vault.adapter.getBasePath();
const vaultPath = getVaultRoot(this.app);
const pluginFolder = resolvePluginFolder(vaultPath, settings);
const bbEdnPath = `${pluginFolder}/bb.edn`;
const nbbEdnPath = `${pluginFolder}/nbb.edn`;
Expand Down Expand Up @@ -179,7 +183,7 @@ export default class BabashkaPlugin extends Plugin {
if (codeblock) {
writeVaultBindingsNs(this.app, view, this.settings);
writeDefaultBbEdn(this.app, this.settings);
const vaultPath = this.app.vault.adapter.getBasePath();
const vaultPath = getVaultRoot(this.app);
executeCodeblock(codeblock, "inside", vaultPath, editor, this.settings);
} else {
new Notice('No clojure(script) codeblock found');
Expand All @@ -195,7 +199,7 @@ export default class BabashkaPlugin extends Plugin {
if (codeblock) {
writeVaultBindingsNs(this.app, view, this.settings);
writeDefaultBbEdn(this.app, this.settings);
const vaultPath = this.app.vault.adapter.getBasePath();
const vaultPath = getVaultRoot(this.app);
executeCodeblock(codeblock, "outside", vaultPath, editor, this.settings);
} else {
new Notice('No clojure(script) codeblock found');
Expand Down Expand Up @@ -232,9 +236,9 @@ class SettingTab extends PluginSettingTab {
.setDesc(desc)
.addText(text => text
.setPlaceholder(placeholder)
.setValue(this.plugin.settings[k])
.setValue(this.plugin.settings[k] as string)
.onChange(async (value) => {
this.plugin.settings[k] = value;
(this.plugin.settings as any)[k] = value;
await this.plugin.saveSettings();
}));
}
Expand All @@ -245,9 +249,9 @@ class SettingTab extends PluginSettingTab {
.setName(name)
.setDesc(desc)
.addToggle(toggle => toggle
.setValue(this.plugin.settings[k])
.setValue(this.plugin.settings[k] as boolean)
.onChange(async (value) => {
this.plugin.settings[k] = value;
(this.plugin.settings as any)[k] = value;
await this.plugin.saveSettings();
}));
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"DOM",
"ES5",
"ES6",
"ES7"
"ES7",
"ES2021"
]
},
"include": [
Expand Down

0 comments on commit 7f9e5a7

Please sign in to comment.