fix(frontend): go editor nits

This commit is contained in:
Ruben Fiszel
2022-11-03 18:48:53 +01:00
parent 7410d9d32d
commit 6018e2ff11
3 changed files with 21 additions and 6 deletions
+16 -3
View File
@@ -32,7 +32,12 @@
import getMessageServiceOverride from 'vscode/service-override/messages'
import { StandaloneServices } from 'vscode/services'
import { DENO_INIT_CODE_CLEAR, PYTHON_INIT_CODE_CLEAR } from '$lib/script_helpers'
import {
DENO_INIT_CODE,
DENO_INIT_CODE_CLEAR,
GO_INIT_CODE,
PYTHON_INIT_CODE_CLEAR
} from '$lib/script_helpers'
import {
createHash as randomHash,
editorConfig,
@@ -109,6 +114,14 @@
}
}
export function insertAtLine(code: string, line: number): void {
if (editor) {
const range = { startLineNumber: line, startColumn: 1, endLineNumber: line, endColumn: 1 }
const op = { range: range, text: code, forceMoveMarkers: true }
editor.executeEdits('external', [op])
}
}
export function setCode(ncode: string): void {
code = ncode
if (editor) {
@@ -132,8 +145,8 @@
setCode(DENO_INIT_CODE_CLEAR)
} else if (lang == 'python') {
setCode(PYTHON_INIT_CODE_CLEAR)
} else {
setCode('')
} else if (lang == 'go') {
setCode(GO_INIT_CODE)
}
}
}
+2 -2
View File
@@ -130,7 +130,7 @@
editor.insertAtCursor(`wmill.get_variable("${path}")`)
} else if (lang == 'go') {
if (!editor.getCode().includes('wmill "github.com/windmill-labs/windmill-go-client"')) {
editor.insertAtBeginning('import wmill "github.com/windmill-labs/windmill-go-client"\n')
editor.insertAtLine('import wmill "github.com/windmill-labs/windmill-go-client"\n\n', 3)
}
editor.insertAtCursor(`v, _ := wmill.GetVariable("${path}")`)
}
@@ -174,7 +174,7 @@
editor.insertAtCursor(`wmill.get_resource("${path}")`)
} else if (lang == 'go') {
if (!editor.getCode().includes('wmill "github.com/windmill-labs/windmill-go-client"')) {
editor.insertAtBeginning('import wmill "github.com/windmill-labs/windmill-go-client"\n')
editor.insertAtLine('import wmill "github.com/windmill-labs/windmill-go-client"\n\n', 3)
}
editor.insertAtCursor(`r, _ := wmill.GetResource("${path}")`)
}
+3 -1
View File
@@ -64,7 +64,9 @@ import (
// wmill "github.com/windmill-labs/windmill-go-client"
)
func main(x string, nested struct{ Foo string \`json:"bar"\` }) (interface{}, error) {
// the main must return (interface{}, error)
func main(x string, nested struct{ Foo string \`json:"foo"\` }) (interface{}, error) {
fmt.Println("Hello, World")
fmt.Println(nested.Foo)
fmt.Println(quote.Opt())