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 e8adaf2f6..d9ee2fc55 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 @@ -666,8 +666,13 @@ class BamlProjectManager { }) } - getProjectById(id: URI): Project { - return this.get_project(uriToRootPath(id)) + getProjectById(id: URI): Project | undefined { + try { + return this.get_project(uriToRootPath(id)) + } catch (e) { + console.error(`Error getting project by id: ${e}`) + return undefined + } } } diff --git a/typescript/vscode-ext/packages/language-server/src/server.ts b/typescript/vscode-ext/packages/language-server/src/server.ts index 185e7f0fe..1520d0057 100644 --- a/typescript/vscode-ext/packages/language-server/src/server.ts +++ b/typescript/vscode-ext/packages/language-server/src/server.ts @@ -113,8 +113,13 @@ export function startServer(options?: LSOptions): void { } }) - console.log = connection.console.log.bind(connection.console) - console.error = connection.console.error.bind(connection.console) + // hellovai 🤷‍♂️: I have no idea why remove this prevents Output Panel + // from not showing up. But it does still keep logs, so I guess this works. + // Adding the snippets back in, will make the Output Panel will show up in + // a very annoying way whenever we have syntax errors in the BAML files. + // + // console.log = connection.console.log.bind(connection.console) + // console.error = connection.console.error.bind(connection.console) console.log('Starting Baml Language Server...') @@ -343,7 +348,6 @@ export function startServer(options?: LSOptions): void { documents.onDidChangeContent(async (change: { document: TextDocument }) => { const textDocument = change.document - await bamlProjectManager.upsert_file(URI.parse(textDocument.uri), textDocument.getText()) }) @@ -360,6 +364,9 @@ export function startServer(options?: LSOptions): void { } const proj = bamlProjectManager.getProjectById(documentUri) + if (!proj) { + return + } try { const error = proj.checkVersionOnSave() @@ -447,6 +454,9 @@ export function startServer(options?: LSOptions): void { const splitWord = completionWord.split('{{') completionWord = splitWord[splitWord.length - 1] const proj = bamlProjectManager.getProjectById(URI.parse(doc.uri)) + if (!proj) { + return undefined + } const res = proj.verifyCompletionRequest(doc, params.position) if (res) { if (completionWord === '_.') { diff --git a/typescript/vscode-ext/packages/vscode/src/plugins/language-server/index.ts b/typescript/vscode-ext/packages/vscode/src/plugins/language-server/index.ts index 4f788d847..a6036c094 100644 --- a/typescript/vscode-ext/packages/vscode/src/plugins/language-server/index.ts +++ b/typescript/vscode-ext/packages/vscode/src/plugins/language-server/index.ts @@ -157,7 +157,7 @@ const activateClient = ( // need to append line for the show to work for some reason. // dont delete this. client.outputChannel.appendLine('\n') - client.outputChannel.show() + client.outputChannel.show(true) }) client.onNotification('baml/message', (message: BAMLMessage) => { client.outputChannel.appendLine('baml/message' + JSON.stringify(message, null, 2))