From 4a072d1eb92ddd3d0fafa5ee28454b17250acdbc Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 20 Dec 2023 18:31:46 +0100 Subject: [PATCH] improve ata --- frontend/src/lib/ata/index.ts | 5 +- frontend/src/lib/components/Editor.svelte | 83 +++++++++++++++++++---- 2 files changed, 71 insertions(+), 17 deletions(-) diff --git a/frontend/src/lib/ata/index.ts b/frontend/src/lib/ata/index.ts index 817a93a306..47b243a5a1 100644 --- a/frontend/src/lib/ata/index.ts +++ b/frontend/src/lib/ata/index.ts @@ -8,6 +8,7 @@ import { import { mapModuleNameToModule } from './edgeCases' export interface ATABootstrapConfig { + root: string /** A object you pass in to get callbacks */ delegate: { /** The callback which gets called when ATA decides a file needs to be written to your VFS */ @@ -73,11 +74,9 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => { } async function resolveDeps(initialSourceFile: string, depth: number) { if (depth > 2) { - console.log('STOP HERE', depth) return - } else { - console.log('L', depth) } + const depsToGet = config .depsParser(initialSourceFile) .map((d: string) => { diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte index 7a5ac42f57..23718cbbcb 100644 --- a/frontend/src/lib/components/Editor.svelte +++ b/frontend/src/lib/components/Editor.svelte @@ -694,17 +694,7 @@ if (useWebsockets) { if (lang == 'typescript' && scriptLang === 'deno') { ata = undefined - let token = $lspTokenStore - if (!token) { - let expiration = new Date() - expiration.setHours(expiration.getHours() + 72) - const newToken = await UserService.createToken({ - requestBody: { label: 'Ephemeral lsp token', expiration: expiration.toISOString() } - }) - $lspTokenStore = newToken - token = newToken - } - let root = hostname + '/api/scripts_u/tokened_raw/' + $workspaceStore + '/' + token + let root = await genRoot(hostname) const importMap = { imports: { 'file:///': root + '/' @@ -766,7 +756,6 @@ ) } else if (lang === 'javascript') { const stdLib = { content: libStdContent, filePath: 'es6.d.ts' } - if (scriptLang == 'bun') { languages.typescript.javascriptDefaults.setExtraLibs([stdLib]) } else { @@ -781,11 +770,13 @@ await vscode.workspace.fs.writeFile(uri, new TextEncoder().encode(code)) } await initWasm() + const root = await genRoot(hostname) ata = setupTypeAcquisition({ projectName: 'Windmill', depsParser: (c) => { return parseDeps(c) }, + root, logger: console, delegate: { receivedFile: addLibraryToRuntime, @@ -1009,13 +1000,63 @@ hovers: false }) + languages.typescript.typescriptDefaults.setCompilerOptions({ + target: languages.typescript.ScriptTarget.Latest, + allowNonTsExtensions: true, + noSemanticValidation: false, + noSyntaxValidation: false, + checkJs: true, + allowJs: true, + noUnusedLocals: true, + strict: true, + noLib: false, + moduleResolution: languages.typescript.ModuleResolutionKind.NodeJs + }) + + languages.typescript.javascriptDefaults.setModeConfiguration({ + completionItems: true, + hovers: true, + documentSymbols: true, + definitions: true, + references: true, + documentHighlights: true, + rename: true, + diagnostics: true, + documentRangeFormattingEdits: true, + signatureHelp: true, + onTypeFormattingEdits: true, + codeActions: true, + inlayHints: true + }) + + languages.typescript.javascriptDefaults.setDiagnosticsOptions({ + noSemanticValidation: false, + noSyntaxValidation: false, + noSuggestionDiagnostics: false, + diagnosticCodesToIgnore: [] + }) + languages.typescript.javascriptDefaults.setCompilerOptions({ target: languages.typescript.ScriptTarget.Latest, allowNonTsExtensions: true, noSemanticValidation: false, - noLib: true, + noSyntaxValidation: false, + checkJs: true, + allowJs: true, + noUnusedParameters: true, + noUnusedLocals: true, + strict: true, + noLib: false, moduleResolution: languages.typescript.ModuleResolutionKind.NodeJs }) + + // languages.typescript.javascriptDefaults.setCompilerOptions({ + // target: languages.typescript.ScriptTarget.Latest, + // allowNonTsExtensions: true, + // noSemanticValidation: false, + // noLib: false, + // moduleResolution: languages.typescript.ModuleResolutionKind.NodeJs + // }) // languages.typescript.typescriptDefaults.setModeConfiguration({ // completionItems: true, // definitions: true, @@ -1052,7 +1093,6 @@ let ataModel: NodeJS.Timeout | undefined = undefined editor.onDidChangeModelContent((event) => { - console.log('foo') timeoutModel && clearTimeout(timeoutModel) timeoutModel = setTimeout(() => { let ncode = getCode() @@ -1147,6 +1187,21 @@ copilotCompletor && copilotCompletor.dispose() sqlTypeCompletor && sqlTypeCompletor.dispose() }) + + async function genRoot(hostname: string) { + let token = $lspTokenStore + if (!token) { + let expiration = new Date() + expiration.setHours(expiration.getHours() + 72) + const newToken = await UserService.createToken({ + requestBody: { label: 'Ephemeral lsp token', expiration: expiration.toISOString() } + }) + $lspTokenStore = newToken + token = newToken + } + let root = hostname + '/api/scripts_u/tokened_raw/' + $workspaceStore + '/' + token + return root + }