diff --git a/typescript/vscode-ext/packages/language-server/src/bamlConfig.ts b/typescript/vscode-ext/packages/language-server/src/bamlConfig.ts index 197da23a2..82127298c 100644 --- a/typescript/vscode-ext/packages/language-server/src/bamlConfig.ts +++ b/typescript/vscode-ext/packages/language-server/src/bamlConfig.ts @@ -3,7 +3,7 @@ export const bamlConfigSchema = z .object({ cliPath: z.optional(z.string().nullable()).default(null), generateCodeOnSave: z.enum(['never', 'always']).default('always'), - restartTSServerOnSave: z.boolean().default(true), + restartTSServerOnSave: z.boolean().default(false), envCommand: z.string().default('env'), fileWatcher: z.boolean().default(false), trace: z.object({ diff --git a/typescript/vscode-ext/packages/language-server/src/lib/baml_project_manager.ts b/typescript/vscode-ext/packages/language-server/src/lib/baml_project_manager.ts index d9ee2fc55..5ccae611c 100644 --- a/typescript/vscode-ext/packages/language-server/src/lib/baml_project_manager.ts +++ b/typescript/vscode-ext/packages/language-server/src/lib/baml_project_manager.ts @@ -6,7 +6,7 @@ import { TextDocument } from 'vscode-languageserver-textdocument' import { CompletionList, CompletionItem } from 'vscode-languageserver' import { exec } from 'child_process' -import { existsSync, readFileSync } from 'fs' +import { existsSync, readFileSync, utimes } from 'fs' import { URI } from 'vscode-uri' import { findTopLevelParent, gatherFiles } from '../file/fileUtils' @@ -417,6 +417,27 @@ class Project { await rename(g.output_dir, backupDir) } await rename(tmpDir, g.output_dir) + + try { + // some filewatchers don't trigger unless the file is touched. Creating the new dir alone doesn't work. + // if we remove this, TS will still have the old types, and nextjs will not hot-reload. + g.files.map((f) => { + const fpath = path.join(g.output_dir, f.path_in_output_dir) + const currentTime = new Date() + const newTime = new Date(currentTime.getTime() + 100) + utimes(fpath, newTime, newTime, (err) => { + if (err) { + console.log(`Error setting file times: ${err.message}`) + } + }) + }) + } catch (e) { + if (e instanceof Error) { + console.error(`Error setting file times: ${e.message}`) + } else { + console.error(`Error setting file times:`) + } + } await rm(backupDir, { recursive: true, force: true }) return g diff --git a/typescript/vscode-ext/packages/package.json b/typescript/vscode-ext/packages/package.json index 56a74b7c3..4502dfc16 100644 --- a/typescript/vscode-ext/packages/package.json +++ b/typescript/vscode-ext/packages/package.json @@ -49,8 +49,8 @@ }, "baml.restartTSServerOnSave": { "type": "boolean", - "default": true, - "description": "Restart the TypeScript server on save, to have it read the new generated types." + "default": false, + "description": "Restart the TypeScript server when generating baml_client code, in case it's not reading the new generated types." }, "baml.fileWatcher": { "scope": "window",