Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lean support #186

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The result is shown only after the execution is finished. It is not possible to
![Video that shows how the plugin works.](https://github.com/twibiral/obsidian-execute-code/blob/master/images/execute_code_example.gif?raw=true)


The following [languages are supported](#supported-programming-languages): C, CPP, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lua, CSharp, Prolog, Rust, Python, R, Wolfram Mathematica, Haskell, Scala, Shell & Powershell.
The following [languages are supported](#supported-programming-languages): C, CPP, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lean, Lua, CSharp, Prolog, Rust, Python, R, Wolfram Mathematica, Haskell, Scala, Shell & Powershell.


Python and Rust support embedded plots. All languages support ["magic" commands](#magic-commands) that help you to access paths in obsidian or show images in your notes.
Expand Down Expand Up @@ -134,6 +134,19 @@ print('Hello, World!')
```
</details>

<details>
<summary>Lean</summary>

- Requirements: install lean and config lean path.

```lean
def main : IO Unit :=
IO.println s!"Hello, World!"

#eval main
```
</details>

<details>
<summary>C++</summary>

Expand Down
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import ExecutorManagerView, {
import runAllCodeBlocks from './runAllCodeBlocks';

export const languageAliases = ["javascript", "typescript", "bash", "csharp", "wolfram", "nb", "wl", "hs", "py"] as const;
export const canonicalLanguages = ["js", "ts", "cs", "lua", "python", "cpp",
export const canonicalLanguages = ["js", "ts", "cs", "lean", "lua", "python", "cpp",
"prolog", "shell", "groovy", "r", "go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "c"] as const;
export const supportedLanguages = [...languageAliases, ...canonicalLanguages] as const;

Expand Down Expand Up @@ -297,6 +297,13 @@ export default class ExecuteCodePlugin extends Plugin {
this.runCodeInShell(transformedCode, out, button, this.settings.tsPath, this.settings.tsArgs, "ts", language, file);
});

} else if (language === "lean") {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
this.runCodeInShell(transformedCode, out, button, this.settings.leanPath, this.settings.leanArgs, "lean", language, file);
});

} else if (language === "lua") {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
Expand Down
8 changes: 8 additions & 0 deletions src/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface ExecutorSettings {
tsPath: string;
tsArgs: string;
tsInject: string;
leanPath: string;
leanArgs: string;
leanInject: string;
luaPath: string;
luaArgs: string;
luaInject: string;
Expand Down Expand Up @@ -86,6 +89,7 @@ export interface ExecutorSettings {
jsInteractive: boolean;
tsInteractive: boolean;
csInteractive: boolean;
leanInteractive: boolean;
luaInteractive: boolean;
pythonInteractive: boolean;
cppInteractive: boolean;
Expand Down Expand Up @@ -121,6 +125,9 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
tsPath: "ts-node",
tsArgs: "",
tsInject: "",
leanPath: "lean",
leanArgs: "",
leanInject: "",
luaPath: "lua",
luaArgs: "",
luaInject: "",
Expand Down Expand Up @@ -192,6 +199,7 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
jsInteractive: true,
tsInteractive: false,
csInteractive: false,
leanInteractive: false,
luaInteractive: false,
pythonInteractive: true,
cppInteractive: false,
Expand Down
4 changes: 4 additions & 0 deletions src/settings/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import makeHaskellSettings from "./per-lang/makeHaskellSettings";
import makeJavaSettings from "./per-lang/makeJavaSettings";
import makeJsSettings from "./per-lang/makeJsSettings";
import makeKotlinSettings from "./per-lang/makeKotlinSettings";
import makeLeanSettings from "./per-lang/makeLeanSettings";
import makeLuaSettings from "./per-lang/makeLuaSettings";
import makeMathematicaSettings from "./per-lang/makeMathematicaSettings";
import makePowershellSettings from "./per-lang/makePowershellSettings";
Expand Down Expand Up @@ -117,6 +118,9 @@ export class SettingsTab extends PluginSettingTab {
// ========== TypeScript ==========
makeTsSettings(this, this.makeContainerFor("ts"));

// ========== Lean ==========
makeLeanSettings(this, this.makeContainerFor("lean"));

// ========== Lua ==========
makeLuaSettings(this, this.makeContainerFor("lua"));

Expand Down
3 changes: 2 additions & 1 deletion src/settings/languageDisplayName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const DISPLAY_NAMES: Record<LanguageId, string> = {
java: "Java",
js: "Javascript",
kotlin: "Kotlin",
lean: "Lean",
lua: "Lua",
mathematica: "Mathematica",
powershell: "Powershell",
Expand All @@ -20,4 +21,4 @@ export const DISPLAY_NAMES: Record<LanguageId, string> = {
ts: "Typescript",
scala: "Scala",
c: "C"
} as const;
} as const;
26 changes: 26 additions & 0 deletions src/settings/per-lang/makeLeanSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Setting } from "obsidian";
import { SettingsTab } from "../SettingsTab";

export default (tab: SettingsTab, containerEl: HTMLElement) => {
containerEl.createEl('h3', { text: 'Lean Settings' });
new Setting(containerEl)
.setName('lean path')
.addText(text => text
.setValue(tab.plugin.settings.leanPath)
.onChange(async (value) => {
const sanitized = tab.sanitizePath(value);
tab.plugin.settings.leanPath = sanitized;
console.log('lean path set to: ' + sanitized);
await tab.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Lean arguments')
.addText(text => text
.setValue(tab.plugin.settings.leanArgs)
.onChange(async (value) => {
tab.plugin.settings.leanArgs = value;
console.log('Lean args set to: ' + value);
await tab.plugin.saveSettings();
}));
tab.makeInjectSetting(containerEl, "lean");
}