Compare commits

...

7 Commits

Author SHA1 Message Date
pyranota
e166349da5 Merge branch 'main' into feat-go-resources 2025-05-29 23:24:54 +02:00
pyranota
ba419c41c0 Merge branch 'main' into feat-go-resources 2025-05-29 20:19:07 +02:00
pyranota
ba6c30aa81 Merge branch 'main' into feat-go-resources 2025-05-29 17:47:54 +02:00
pyranota
fda11ab25a Merge branch 'main' into feat-go-resources 2025-05-29 15:44:59 +02:00
pyranota
85b63dd9e6 update wasm cli 2025-05-29 13:07:00 +00:00
pyranota
d577192aad Merge branch 'main' into feat-go-resources 2025-05-29 15:03:35 +02:00
pyranota
863992ed0b feat(go): Resource Types 2025-05-29 14:53:20 +02:00
6 changed files with 873 additions and 45 deletions

View File

@@ -7,7 +7,7 @@ use gosyn::{
use itertools::Itertools;
use regex::Regex;
use windmill_parser::{Arg, MainArgSignature, ObjectProperty, Typ};
use windmill_parser::{to_snake_case, Arg, MainArgSignature, ObjectProperty, Typ};
lazy_static::lazy_static! {
pub static ref REQUIRE_PARSE: Regex = Regex::new(r"//require (.*)\n").unwrap();
@@ -99,7 +99,7 @@ fn parse_go_typ(typ: &Expression) -> (Option<String>, Typ) {
"int64" => Typ::Int,
"string" => Typ::Str(None),
"bool" => Typ::Bool,
_ => Typ::Unknown,
_ => Typ::Resource(to_snake_case(name.as_ref())),
},
),
Expression::TypeSlice(slice_type) => {
@@ -163,6 +163,55 @@ mod tests {
use super::*;
#[test]
fn test_parse_go_sig_resources() -> anyhow::Result<()> {
let code = r#"
package main
import "fmt"
type MyResource struct {
A string `json:"a"`
B *int64 `json:"b,omitempty"`
C []string `json:"c,omitempty"`
}
func main(x int, a MyResource) {
fmt.Println("hello world")
}
"#;
assert_eq!(
parse_go_sig(code)?,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![
Arg {
otyp: Some("int".to_string()),
name: "x".to_string(),
typ: Typ::Int,
has_default: false,
default: None,
oidx: None
},
Arg {
otyp: Some("MyResource".to_string()),
name: "a".to_string(),
typ: Typ::Resource("my_resource".into()),
default: None,
has_default: false,
oidx: None
},
],
no_main_func: Some(false),
has_preprocessor: None
}
);
Ok(())
}
#[test]
fn test_parse_go_sig() -> anyhow::Result<()> {
let code = r#"

File diff suppressed because it is too large Load Diff

View File

@@ -81,12 +81,12 @@
"dependencies": {
"@aws-crypto/sha256-js": "^4.0.0",
"@codingame/monaco-vscode-configuration-service-override": "~16.1.1",
"@codingame/monaco-vscode-editor-api": "~16.1.1",
"@codingame/monaco-vscode-standalone-css-language-features": "~16.1.1",
"@codingame/monaco-vscode-standalone-html-language-features": "^16.1.1",
"@codingame/monaco-vscode-standalone-json-language-features": "~16.1.1",
"@codingame/monaco-vscode-standalone-languages": "~16.1.1",
"@codingame/monaco-vscode-standalone-typescript-language-features": "~16.1.1",
"@codingame/monaco-vscode-editor-api": "~16.1.1",
"@json2csv/plainjs": "^7.0.6",
"@leeoniya/ufuzzy": "^1.0.8",
"@popperjs/core": "^2.11.6",
@@ -124,6 +124,8 @@
"p-limit": "^6.1.0",
"panzoom": "^9.4.3",
"pdfjs-dist": "4.8.69",
"quicktype": "^23.2.6",
"quicktype-core": "^23.2.6",
"quill": "^1.3.7",
"rehype-github-alerts": "^3.0.0",
"rehype-raw": "^7.0.0",

View File

@@ -283,6 +283,13 @@
}
}
export function insertAtCurrentLine(code: string): void {
if (editor) {
console.log();
insertAtLine(code, editor.getPosition()?.lineNumber ?? 0);
}
}
export function arrowDown(): void {
if (editor) {
let pos = editor.getPosition()

View File

@@ -24,6 +24,7 @@
import { getScriptByPath, scriptLangToEditorLang } from '$lib/scripts'
import Toggle from './Toggle.svelte'
import {
DiffIcon,
DollarSign,
@@ -46,6 +47,12 @@
import ResourceEditorDrawer from './ResourceEditorDrawer.svelte'
import type { EditorBarUi } from './custom_ui'
import EditorSettings from './EditorSettings.svelte'
import {
quicktype,
InputData,
JSONSchemaInput,
FetchingJSONSchemaStore
} from "quicktype-core";
export let lang: SupportedLanguage | 'bunnative' | undefined
export let editor: Editor | undefined
@@ -136,7 +143,8 @@
$: showResourceTypePicker =
['typescript', 'javascript'].includes(scriptLangToEditorLang(lang)) ||
lang === 'python3' ||
lang === 'php'
lang === 'php' ||
lang === 'go'
let codeViewer: Drawer
let codeObj: { language: SupportedLanguage; content: string } | undefined = undefined
@@ -207,6 +215,26 @@
return rec(schema.properties, true)
}
async function quicktypeJSONSchema(targetLanguage, typeName, jsonSchemaString) {
const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());
// We could add multiple schemas for multiple types,
// but here we're just making one type from JSON schema.
await schemaInput.addSource({ name: typeName, schema: jsonSchemaString });
const inputData = new InputData();
inputData.addInput(schemaInput);
return await quicktype({
inputData,
lang: targetLanguage,
rendererOptions: {
"just-types": "Plain types only"
}
});
}
async function resourceTypePickCallback(name: string) {
if (!editor) return
const resourceType = await ResourceService.getResourceType({
@@ -228,6 +256,11 @@
editor.insertAtCursor(`if (!class_exists('${rtName}')) {\nclass ${rtName} {\n${phpSchema}\n`)
editor.backspace()
editor.insertAtCursor('}')
} else if (lang === 'go') {
const { lines: lines } = await quicktypeJSONSchema("go", name, JSON.stringify(resourceType.schema));
editor.insertAtCurrentLine(lines.join("\n"))
} else {
const tsSchema = compile(resourceType.schema as any)
editor.insertAtCursor(`type ${toCamel(capitalize(name))} = ${tsSchema}`)