Skip to content

Commit

Permalink
feat: add CSharp support
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaogaojian committed Sep 22, 2022
1 parent c11cb9b commit a530991
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ define [global code injections](#global-code-injection-and-reusing-code-blocks).
```

- Lua
- Requirements: install lua and config system path
- Requirements: install lua and config lua path
```lua
print('hello world')
print('Hello, World!')
```

- CSharp
- Requirements: install dotnet core sdk and `dotnet tool install -g dotnet-script`, then config dotnet-script fullpath.
```cs
Console.WriteLine("Hello, World!");
```

- Python
Expand Down
6 changes: 6 additions & 0 deletions src/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;
csPath: string;
csArgs: string;
csInject: string;
pythonPath: string;
pythonArgs: string;
pythonEmbedPlots: boolean;
Expand Down Expand Up @@ -78,6 +81,9 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
luaPath: "lua",
luaArgs: "",
luaInject: "",
csPath: "dotnet-script",
csArgs: "",
csInject: "",
pythonPath: "python",
pythonArgs: "",
pythonEmbedPlots: true,
Expand Down
23 changes: 23 additions & 0 deletions src/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,29 @@ export class SettingsTab extends PluginSettingTab {
}));
this.makeInjectSetting("lua", "Lua");

// ========== CSharp ==========
containerEl.createEl('h3', {text: 'CSharp Settings'});
new Setting(containerEl)
.setName('dotnet path')
.addText(text => text
.setValue(this.plugin.settings.csPath)
.onChange(async (value) => {
const sanitized = this.sanitizePath(value);
this.plugin.settings.csPath = sanitized;
console.log('dotnet path set to: ' + sanitized);
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('CSharp arguments')
.addText(text => text
.setValue(this.plugin.settings.csArgs)
.onChange(async (value) => {
this.plugin.settings.csArgs = value;
console.log('CSharp args set to: ' + value);
await this.plugin.saveSettings();
}));
this.makeInjectSetting("cs", "CSharp");

// ========== Java ==========
containerEl.createEl('h3', {text: 'Java Settings'});
new Setting(containerEl)
Expand Down
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
// @ts-ignore
import * as prolog from "tau-prolog";

export const supportedLanguages = ["js", "javascript", "ts", "typescript", "lua", "python", "cpp", "prolog", "shell", "bash", "groovy", "r", "go", "rust",
export const supportedLanguages = ["js", "javascript", "ts", "typescript", "cs", "csharp", "lua", "python", "cpp", "prolog", "shell", "bash", "groovy", "r", "go", "rust",
"java", "powershell", "kotlin"] as const;
const languagePrefixes = ["run", "pre", "post"];

Expand Down Expand Up @@ -345,6 +345,13 @@ export default class ExecuteCodePlugin extends Plugin {
console.debug(`runCodeInShell ${this.settings.luaPath} ${this.settings.luaArgs} ${"lua"}`)
this.runCodeInShell(transformedCode, out, button, this.settings.luaPath, this.settings.luaArgs, "lua");
});
} else if (language.contains("language-cs")) {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
let transformedCode = await this.injectCode(srcCode, "lua");
console.log(`runCodeInShell ${this.settings.csPath} ${this.settings.csArgs} ${"cs"}`)
this.runCodeInShell(transformedCode, out, button, this.settings.csPath, this.settings.csArgs, "csx");
});
}
}

Expand Down

0 comments on commit a530991

Please sign in to comment.