fix: reset with minimal code (#1982)

This commit is contained in:
HugoCasa
2023-08-02 09:16:36 +02:00
committed by GitHub
parent b2f23fbaa1
commit c031b9f352
3 changed files with 18 additions and 22 deletions
-20
View File
@@ -34,12 +34,6 @@
langToExt,
updateOptions
} from '$lib/editorUtils'
import {
BASH_INIT_CODE,
DENO_INIT_CODE_CLEAR,
GO_INIT_CODE,
PYTHON_INIT_CODE_CLEAR
} from '$lib/script_helpers'
import type { Disposable } from 'vscode'
import type { DocumentUri, MessageTransports } from 'vscode-languageclient'
import { dirtyStore } from './common/confirmationModal/dirtyStore'
@@ -200,20 +194,6 @@
}
}
export async function clearContent() {
if (editor) {
if (lang == 'typescript') {
setCode(DENO_INIT_CODE_CLEAR)
} else if (lang == 'python') {
setCode(PYTHON_INIT_CODE_CLEAR)
} else if (lang == 'go') {
setCode(GO_INIT_CODE)
} else if (lang == 'shell') {
setCode(BASH_INIT_CODE)
}
}
}
let command: Disposable | undefined = undefined
let dbSchemaCompletor: Disposable | undefined = undefined
+2 -2
View File
@@ -39,7 +39,7 @@
import ScriptVersionHistory from './ScriptVersionHistory.svelte'
import { ScriptGen } from './codeGen'
import type DiffEditor from './DiffEditor.svelte'
import { initialCode } from '$lib/script_helpers'
import { getResetCode } from '$lib/script_helpers'
import type { Script } from '$lib/gen'
export let lang: SupportedLanguage
@@ -180,7 +180,7 @@
function clearContent() {
if (editor) {
const resetCode = initialCode(lang, kind as Script.kind, template)
const resetCode = getResetCode(lang, kind as Script.kind, template)
editor.setCode(resetCode)
}
}
+16
View File
@@ -349,3 +349,19 @@ export function initialCode(
}
}
}
export function getResetCode(
language: SupportedLanguage,
kind: Script.kind | undefined,
subkind: 'pgsql' | 'mysql' | 'flow' | 'script' | 'fetch' | 'docker' | 'powershell' | undefined
) {
if (language === 'deno') {
return DENO_INIT_CODE_CLEAR
} else if (language === 'python3') {
return PYTHON_INIT_CODE_CLEAR
} else if (language === 'bun') {
return BUN_INIT_CODE_CLEAR
} else {
return initialCode(language, kind, subkind)
}
}