Skip to content

Commit

Permalink
Restart ts server config (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronvg authored Sep 4, 2024
1 parent 4d304c5 commit 628f236
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
12 changes: 12 additions & 0 deletions docs/docs/doc-snippets/vscode-settings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ Possible options: `always`, `never`.


If you choose `never`, you will have to run the `baml-cli generate` command manually.
</ParamField>

<ParamField
path="baml.restartTSServerOnSave"
type="boolean"
default={true}
>
Restarts the TypeScript Server in VSCode when the BAML extension generates the TypeScript baml_client files.
VSCode has some issues picking up newly added directories and files, so this is a workaround for that.

If it's not enabled, you may have to reload the TS server yourself to get it to recognize the new types.

</ParamField>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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),
envCommand: z.string().default('env'),
fileWatcher: z.boolean().default(false),
trace: z.object({
Expand All @@ -12,7 +13,6 @@ export const bamlConfigSchema = z
})
.partial()
type BamlConfig = z.infer<typeof bamlConfigSchema>
let config: BamlConfig | null = null

export const bamlConfig: { config: BamlConfig | null; cliVersion: string | null } = {
config: null,
Expand Down
8 changes: 5 additions & 3 deletions typescript/vscode-ext/packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@ export function startServer(options?: LSOptions): void {
})

function restartTSServer() {
connection.sendRequest('executeCommand', 'typescript.restartTsServer').catch((e) => {
console.error('Error restarting TS server: ' + e)
})
if (bamlConfig.config?.restartTSServerOnSave) {
connection.sendRequest('executeCommand', 'typescript.restartTsServer').catch((e) => {
console.error('Error restarting TS server: ' + e)
})
}
}

function getDocument(uri: string): TextDocument | undefined {
Expand Down
5 changes: 5 additions & 0 deletions typescript/vscode-ext/packages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
],
"description": "Generate code on save"
},
"baml.restartTSServerOnSave": {
"type": "boolean",
"default": true,
"description": "Restart the TypeScript server on save, to have it read the new generated types."
},
"baml.fileWatcher": {
"scope": "window",
"type": "boolean",
Expand Down

0 comments on commit 628f236

Please sign in to comment.