Skip to content

Commit

Permalink
fix(vscode-extension): improve console output when tsp-server not fou…
Browse files Browse the repository at this point in the history
…nd (#5428)

- print more messages when resolving tsp-server executable
- improve configuration setting description

fix #5080

---------

Co-authored-by: Mingzhe Huang (from Dev Box) <[email protected]>
  • Loading branch information
archerzz and Mingzhe Huang (from Dev Box) authored Jan 10, 2025
1 parent b221ef7 commit 5e26257
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- typespec-vscode
---

improve console output when tsp-server not found
2 changes: 1 addition & 1 deletion packages/typespec-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 9 additions & 3 deletions packages/typespec-vscode/src/tsp-executable-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -74,13 +74,19 @@ 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({
Expand Down

0 comments on commit 5e26257

Please sign in to comment.