From 24fc5eb1745b7657a975130273f2e272cde4dbef Mon Sep 17 00:00:00 2001 From: aaronvg Date: Fri, 10 Jan 2025 14:01:17 -0800 Subject: [PATCH 1/3] Fix windows vscode client generation --- .../src/lib/baml_project_manager.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 dd4496038..fa1e093a1 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 @@ -377,10 +377,11 @@ class Project { const out_dir = path.join(this.rootPath(), g.output_dir_relative_to_baml_src) - const tmpDir = path.join(path.dirname(g.output_dir), path.basename(g.output_dir) + '.tmp') - const backupDir = path.join(path.dirname(g.output_dir), path.basename(g.output_dir) + '.bak') + const tmpDir = path.join(out_dir + '.tmp') + const backupDir = path.join(out_dir + '.bak') await mkdir(tmpDir, { recursive: true }) + console.log(`tmpdir ${tmpDir}`) await Promise.all( g.files.map(async (f) => { const fpath = path.join(tmpDir, f.path_in_output_dir) @@ -393,6 +394,7 @@ class Project { await rm(backupDir, { recursive: true, force: true }) } if (existsSync(out_dir)) { + console.log('out dir exists') const contents = await readdir(out_dir, { withFileTypes: true }) const contentsWithSafeToRemove = await Promise.all( contents.map(async (c) => { @@ -403,7 +405,7 @@ class Project { return { path: c.name, safeToRemove: false } } - const handle = await open(path.join(g.output_dir, c.name)) + const handle = await open(path.join(out_dir, c.name)) try { const { bytesRead, buffer } = await handle.read(Buffer.alloc(1024), 0, 1024, 0) const firstNBytes = buffer.subarray(0, bytesRead).toString('utf8') @@ -420,7 +422,11 @@ class Project { `Output dir ${g.output_dir} contains this file(s) not generated by BAML: ${notSafeToRemove.join(', ')}`, ) } + try { await rename(out_dir, backupDir) + } catch (e) { + console.error(`Something happened backing up baml_client to the .bak directory. ${e}`) + } } await rename(tmpDir, out_dir) @@ -429,7 +435,6 @@ class Project { // 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(out_dir, f.path_in_output_dir) - console.log(`fpath ${fpath}`) const currentTime = new Date() const newTime = new Date(currentTime.getTime() + 100) utimes(fpath, newTime, newTime, (err) => { @@ -457,6 +462,7 @@ class Project { onSuccess(`BAML client generated! (took ${Math.round(endMillis - startMillis)}ms)`) } } catch (e) { + console.error(`Failed to generate BAML client: ${e}`) onError(`Failed to generate BAML client: ${e}`) } } From 7ec3759d0a27259986b50e98c2106f2b9367e4ba Mon Sep 17 00:00:00 2001 From: aaronvg Date: Fri, 10 Jan 2025 14:06:17 -0800 Subject: [PATCH 2/3] Fix hover on windows --- .../language-server/src/lib/baml_project_manager.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 fa1e093a1..5a6502217 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 @@ -212,11 +212,11 @@ class Project { this.current_runtime = undefined } - get_file(file_path: string) { + get_file(file_path: URI) { // Read the file content - const fileContent = readFileSync(file_path, 'utf8') + const fileContent = readFileSync(file_path.fsPath, 'utf8') - const doc = TextDocument.create(file_path, 'plaintext', 1, fileContent) + const doc = TextDocument.create(file_path.fsPath, 'plaintext', 1, fileContent) return doc } @@ -281,7 +281,8 @@ class Project { end: { line: match.end_line, character: match.end_character }, } - const hoverDoc = this.get_file(URI.file(match.uri).toString()) + + const hoverDoc = this.get_file(URI.file(match.uri)) if (hoverDoc) { const hoverText = hoverDoc.getText(range) From 2c0d80bc14c0dc612dc54ed57836caeec4272651 Mon Sep 17 00:00:00 2001 From: Aaron Villalpando Date: Fri, 10 Jan 2025 14:10:01 -0800 Subject: [PATCH 3/3] fix format --- .../packages/language-server/src/lib/baml_project_manager.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 5a6502217..4d75966e1 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 @@ -281,7 +281,6 @@ class Project { end: { line: match.end_line, character: match.end_character }, } - const hoverDoc = this.get_file(URI.file(match.uri)) if (hoverDoc) { @@ -424,7 +423,7 @@ class Project { ) } try { - await rename(out_dir, backupDir) + await rename(out_dir, backupDir) } catch (e) { console.error(`Something happened backing up baml_client to the .bak directory. ${e}`) }