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 dart support #174

Merged
merged 6 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),


## [1.5.0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, @twibiral is the one to update the changelog when it is time for the next release. I'm not sure what the correct procedure is or what he would prefer re: this commit, but I wanted to make sure you were aware of that :) sorry!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chlohal is right, I would prefer if you could remove this @andremeireles. The version number is finalized before a new version is released and added to the CHANGELOG by a script

Copy link
Contributor Author

@andremeireles andremeireles Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, great.
I think it is now ready to be merged.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

### Added
- Support for Dart

## [1.4.0]
### Added
- Notebook mode for R (Thanks to @chlohal)
Expand Down
14 changes: 13 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): 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): CPP, Dart, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, 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 @@ -58,6 +58,18 @@ Console.WriteLine("Hello, World!");
```
</details>

<details>
<summary>Dart</summary>

- Requirements: dart sdk is installed and the correct path is set in the settings.

```dart
void main() {
print("Hello World");
}
```
</details>

<details>
<summary>Python</summary>

Expand Down
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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",
"prolog", "shell", "groovy", "r", "go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala"] as const;
"prolog", "shell", "groovy", "r", "go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "dart"] as const;
export const supportedLanguages = [...languageAliases, ...canonicalLanguages] as const;


Expand Down Expand Up @@ -304,6 +304,13 @@ export default class ExecuteCodePlugin extends Plugin {
this.runCodeInShell(transformedCode, out, button, this.settings.luaPath, this.settings.luaArgs, "lua", language, file);
});

} else if (language === "dart") {
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.dartPath, this.settings.dartArgs, "dart", language, file);
});

} else if (language === "cs") {
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 @@ -18,6 +18,9 @@ export interface ExecutorSettings {
luaPath: string;
luaArgs: string;
luaInject: string;
dartPath: string;
dartArgs: string;
dartInject: string;
csPath: string;
csArgs: string;
csInject: string;
Expand Down Expand Up @@ -83,6 +86,7 @@ export interface ExecutorSettings {
tsInteractive: boolean;
csInteractive: boolean;
luaInteractive: boolean;
dartInteractive: boolean;
pythonInteractive: boolean;
cppInteractive: boolean;
prologInteractive: boolean;
Expand Down Expand Up @@ -119,6 +123,9 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
luaPath: "lua",
luaArgs: "",
luaInject: "",
dartPath: "dart",
dartArgs: "",
dartInject: "",
csPath: "dotnet-script",
csArgs: "",
csInject: "",
Expand Down Expand Up @@ -184,6 +191,7 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
tsInteractive: false,
csInteractive: false,
luaInteractive: false,
dartInteractive: false,
pythonInteractive: true,
cppInteractive: false,
prologInteractive: 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 makeJavaSettings from "./per-lang/makeJavaSettings";
import makeJsSettings from "./per-lang/makeJsSettings";
import makeKotlinSettings from "./per-lang/makeKotlinSettings";
import makeLuaSettings from "./per-lang/makeLuaSettings";
import makeDartSettings from "./per-lang/makeDartSettings";
import makeMathematicaSettings from "./per-lang/makeMathematicaSettings";
import makePowershellSettings from "./per-lang/makePowershellSettings";
import makePrologSettings from "./per-lang/makePrologSettings";
Expand Down Expand Up @@ -119,6 +120,9 @@ export class SettingsTab extends PluginSettingTab {
// ========== Lua ==========
makeLuaSettings(this, this.makeContainerFor("lua"));

// ========== Dart ==========
makeDartSettings(this, this.makeContainerFor("dart"));

// ========== CSharp ==========
makeCsSettings(this, this.makeContainerFor("cs"));

Expand Down
3 changes: 2 additions & 1 deletion src/settings/languageDisplayName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LanguageId } from "src/main";
export const DISPLAY_NAMES: Record<LanguageId, string> = {
cpp: "C++",
cs: "C#",
dart: "Dart",
go: "Golang",
groovy: "Groovy",
haskell: "Haskell",
Expand All @@ -19,4 +20,4 @@ export const DISPLAY_NAMES: Record<LanguageId, string> = {
shell: "Shell",
ts: "Typescript",
scala: "Scala"
} as const;
} as const;
26 changes: 26 additions & 0 deletions src/settings/per-lang/makeDartSettings.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: 'Dart Settings' });
new Setting(containerEl)
.setName('dart path')
.addText(text => text
.setValue(tab.plugin.settings.dartPath)
.onChange(async (value) => {
const sanitized = tab.sanitizePath(value);
tab.plugin.settings.dartPath = sanitized;
console.log('dart path set to: ' + sanitized);
await tab.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Dart arguments')
.addText(text => text
.setValue(tab.plugin.settings.dartArgs)
.onChange(async (value) => {
tab.plugin.settings.dartArgs = value;
console.log('Dart args set to: ' + value);
await tab.plugin.saveSettings();
}));
tab.makeInjectSetting(containerEl, "dart");
}