From cf872e2a5d890b263f65b0be3acee4b7f1e417e4 Mon Sep 17 00:00:00 2001 From: "Mingzhe Huang (from Dev Box)" Date: Mon, 23 Dec 2024 14:03:44 +0800 Subject: [PATCH 1/2] fix(vscode-extension): improve console output when tsp-server not found - print more messages when resolving tsp-server executable - improve configuration setting description fix #5080 --- ...-fix-tsp-server-resolution-error-2024-11-23-14-5-54.md | 7 +++++++ packages/typespec-vscode/package.json | 2 +- packages/typespec-vscode/src/tsp-executable-resolver.ts | 8 +++++--- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .chronus/changes/typespec-vscode-fix-tsp-server-resolution-error-2024-11-23-14-5-54.md diff --git a/.chronus/changes/typespec-vscode-fix-tsp-server-resolution-error-2024-11-23-14-5-54.md b/.chronus/changes/typespec-vscode-fix-tsp-server-resolution-error-2024-11-23-14-5-54.md new file mode 100644 index 0000000000..8a37b0d5a6 --- /dev/null +++ b/.chronus/changes/typespec-vscode-fix-tsp-server-resolution-error-2024-11-23-14-5-54.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - typespec-vscode +--- + +improve console output when tsp-server not found \ No newline at end of file diff --git a/packages/typespec-vscode/package.json b/packages/typespec-vscode/package.json index 52fc4e906b..a0e1feb1bc 100644 --- a/packages/typespec-vscode/package.json +++ b/packages/typespec-vscode/package.json @@ -71,7 +71,7 @@ "typespec.tsp-server.path": { "type": "string", "default": "", - "description": "Path to `tsp-server` command that runs the TypeSpec language server.\n\nIf not specified, then `tsp-server` found on PATH is used.\n\nExample (User): /usr/local/bin/tsp-server\nExample (Workspace): ${workspaceFolder}/node_modules/@typespec/compiler", + "description": "Path to 'tsp-server' command that runs the TypeSpec language server. If not specified, then 'tsp-server' will be resolved in following sequence:\n\n1. from workspace node_modules folder\nExample: ${workspaceFolder}/node_modules/@typespec/compiler\n\n2. from PATH environment variable\nExample: /usr/local/bin/tsp-server", "scope": "machine-overridable" }, "typespec.initTemplatesUrls": { diff --git a/packages/typespec-vscode/src/tsp-executable-resolver.ts b/packages/typespec-vscode/src/tsp-executable-resolver.ts index 934f3b8007..e6c8614289 100644 --- a/packages/typespec-vscode/src/tsp-executable-resolver.ts +++ b/packages/typespec-vscode/src/tsp-executable-resolver.ts @@ -63,7 +63,7 @@ export async function resolveTypeSpecServer(context: ExtensionContext): Promise< options.env.NODE_OPTIONS = nodeOptions; } - // In production, first try VS Code configuration, which allows a global machine + // In production, first try VS Code extension configuration, which allows a global machine // location that is not on PATH, or a workspace-specific installation. let serverPath: string | undefined = workspace.getConfiguration().get(SettingName.TspServerPath); if (serverPath && typeof serverPath !== "string") { @@ -74,13 +74,15 @@ export async function resolveTypeSpecServer(context: ExtensionContext): Promise< // Default to tsp-server on PATH, which would come from `npm install -g // @typespec/compiler` in a vanilla setup. if (serverPath) { - logger.debug(`Server path loaded from VS Code configuration: ${serverPath}`); + logger.info(`Server path loaded from TypeSpec extension configuration: ${serverPath}`); } else { + logger.info("Server path not configured in TypeSpec extension configuration, trying to resolve locally within current workspace."); serverPath = await resolveLocalCompiler(workspaceFolder); } + if (!serverPath) { const executable = process.platform === "win32" ? "tsp-server.cmd" : "tsp-server"; - logger.debug(`Can't resolve server path, try to use default value ${executable}.`); + logger.warning(`Can't resolve server path from either TypeSpec extension configuration or workspace, try to use default value ${executable}.`); return useShellInExec({ command: executable, args, options }); } const variableResolver = new VSCodeVariableResolver({ From 871da2b0f604875195bb04c7a99b534e9d00f381 Mon Sep 17 00:00:00 2001 From: "Mingzhe Huang (from Dev Box)" Date: Mon, 23 Dec 2024 14:10:52 +0800 Subject: [PATCH 2/2] fix style --- packages/typespec-vscode/src/tsp-executable-resolver.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/typespec-vscode/src/tsp-executable-resolver.ts b/packages/typespec-vscode/src/tsp-executable-resolver.ts index e6c8614289..fcba487cfd 100644 --- a/packages/typespec-vscode/src/tsp-executable-resolver.ts +++ b/packages/typespec-vscode/src/tsp-executable-resolver.ts @@ -76,13 +76,17 @@ export async function resolveTypeSpecServer(context: ExtensionContext): Promise< if (serverPath) { logger.info(`Server path loaded from TypeSpec extension configuration: ${serverPath}`); } else { - logger.info("Server path not configured in TypeSpec extension configuration, trying to resolve locally within current workspace."); + logger.info( + "Server path not configured in TypeSpec extension configuration, trying to resolve locally within current workspace.", + ); serverPath = await resolveLocalCompiler(workspaceFolder); } if (!serverPath) { const executable = process.platform === "win32" ? "tsp-server.cmd" : "tsp-server"; - logger.warning(`Can't resolve server path from either TypeSpec extension configuration or workspace, try to use default value ${executable}.`); + logger.warning( + `Can't resolve server path from either TypeSpec extension configuration or workspace, try to use default value ${executable}.`, + ); return useShellInExec({ command: executable, args, options }); } const variableResolver = new VSCodeVariableResolver({