diff --git a/packages/typespec-vscode/package.json b/packages/typespec-vscode/package.json index d1c8f91131..7e4b68966f 100644 --- a/packages/typespec-vscode/package.json +++ b/packages/typespec-vscode/package.json @@ -109,7 +109,7 @@ "default": "off", "description": "Define whether/how the TypeSpec language server should send traces to client. For the traces to show properly in vscode Output, make sure 'Log Level' is also set to 'Trace' so that they won't be filtered at client side, which can be set through 'Developer: Set Log Level...' command." }, - "typespec.client.emitter": { + "typespec.emitters": { "scope": "window", "type": "array", "items": { @@ -122,99 +122,65 @@ "Java", "JavaScript", "Python", - "Go" + "Go", + "OpenAPI3", + "ProtoBuf", + "JsonSchema" ], "description": "Define the language the emitter will emit." }, "package": { "type": "string", "description": "Define the emitter package.\n\nExample (with version): @typespec/http-client-csharp@1.0.0\n\nExample (without version): @typespec/http-client-csharp" + }, + "kind": { + "type": "string", + "enum": [ + "client", + "server", + "schema" + ], + "description": "Define the emitter kind." } } }, "default": [ { "language": "DotNet", - "package": "@typespec/http-client-csharp" + "package": "@typespec/http-client-csharp", + "kind": "client" }, { "language": "Java", - "package": "@typespec/http-client-java" + "package": "@typespec/http-client-java", + "kind": "client" }, { "language": "JavaScript", - "package": "@azure-tools/typespec-ts" + "package": "@azure-tools/typespec-ts", + "kind": "client" }, { "language": "Python", - "package": "@typespec/http-client-python" - } - ], - "description": "Define the emitter for a language client sdk generation." - }, - "typespec.server.emitter": { - "scope": "window", - "type": "array", - "items": { - "type": "object", - "properties": { - "language": { - "type": "string", - "enum": [ - "DotNet", - "Java", - "JavaScript", - "Python", - "Go" - ], - "description": "Define the language for the emitter." - }, - "package": { - "type": "string", - "description": "Define the emitter package.\n\nExample (with version): @typespec/http-server-csharp@1.0.0\n\nExample (without version): @typespec/http-server-csharp" - } - } - }, - "default": [ + "package": "@typespec/http-client-python", + "kind": "client" + }, { "language": "DotNet", - "package": "@typespec/http-server-csharp" + "package": "@typespec/http-server-csharp", + "kind": "server" }, { "language": "JavaScript", - "package": "@typespec/http-server-javascript" - } - ], - "description": "Define the emitter for server code generation." - }, - "typespec.schema.emitter": { - "scope": "window", - "type": "array", - "items": { - "type": "object", - "properties": { - "language": { - "type": "string", - "enum": [ - "OpenAPI3", - "ProtoBuf", - "JsonSchema" - ], - "description": "Define the language for the emitter." - }, - "package": { - "type": "string", - "description": "Define the emitter package.\n\nExample (with version): @typespec/openapi3@1.0.0\n\nExample (without version): @typespec/openapi3" - } - } - }, - "default": [ + "package": "@typespec/http-server-javascript", + "kind": "server" + }, { "language": "OpenAPI3", - "package": "@typespec/openapi3" + "package": "@typespec/openapi3", + "kind": "schema" } - ], - "description": "Define the emitter for a schema." + ] } } } @@ -249,8 +215,8 @@ "category": "TypeSpec" }, { - "command": "typespec.emit", - "title": "TypeSpec: Emit Code", + "command": "typespec.generate", + "title": "Generate from TypeSpec", "category": "TypeSpec" }, { @@ -267,7 +233,7 @@ "menus": { "explorer/context": [ { - "command": "typespec.emit", + "command": "typespec.generate", "when": "explorerResourceIsFolder || resourceLangId == typespec", "group": "code_generation" } diff --git a/packages/typespec-vscode/src/const.ts b/packages/typespec-vscode/src/const.ts index 9216ab4e34..e7b898f945 100644 --- a/packages/typespec-vscode/src/const.ts +++ b/packages/typespec-vscode/src/const.ts @@ -1,9 +1 @@ -import { SettingName } from "./types.js"; - -export const EmitterSettingName: Record = { - client: SettingName.ClientEmitter, - server: SettingName.ServerEmitter, - schema: SettingName.SchemaEmitter, -}; - export const StartFileName = "main.tsp"; diff --git a/packages/typespec-vscode/src/emit/emit.ts b/packages/typespec-vscode/src/emit/emit.ts index f55776b28e..8df6883466 100644 --- a/packages/typespec-vscode/src/emit/emit.ts +++ b/packages/typespec-vscode/src/emit/emit.ts @@ -340,26 +340,26 @@ export async function emitCode( const codesToEmit = [ { - label: "Client SDK", - detail: "Generate client SDK library from typespec.", + label: "Protocol Schema", + detail: "Generating Protocol schema (OpenAPI for example) from TypeSpec", + iconPath: Uri.file(context.asAbsolutePath(`./icons/schema.svg`)), + emitterKind: EmitterKind.Schema, + }, + { + label: "Client Code", + detail: "Generating Client Code from TypeSpec.", iconPath: Uri.file(context.asAbsolutePath(`./icons/sdk.svg`)), emitterKind: EmitterKind.Client, }, { - label: "Server Stub", - detail: "Generate server codes from typespec", + label: " Server Stub", + detail: "Generating Server Stub from TypeSpec", iconPath: Uri.file(context.asAbsolutePath(`./icons/serverstub.svg`)), emitterKind: EmitterKind.Server, }, - { - label: "Protocol Schema", - detail: "Generate protocol schema (e.g. OpenAPI, Protobuf) from typespec", - iconPath: Uri.file(context.asAbsolutePath(`./icons/schema.svg`)), - emitterKind: EmitterKind.Schema, - }, ]; const codeType = await vscode.window.showQuickPick(codesToEmit, { - title: "Emit Code", + title: "Select an Emitter Type", canPickMany: false, placeHolder: "Select an option", ignoreFocusOut: true, @@ -367,7 +367,7 @@ export async function emitCode( if (!codeType) { logger.info("No emitters selected. Emit canceled.", [], { showOutput: false, - showPopup: true, + showPopup: false, progress: overallProgress, }); return; diff --git a/packages/typespec-vscode/src/emit/emitter.ts b/packages/typespec-vscode/src/emit/emitter.ts index 555bd03157..bb6a760327 100644 --- a/packages/typespec-vscode/src/emit/emitter.ts +++ b/packages/typespec-vscode/src/emit/emitter.ts @@ -1,5 +1,5 @@ import vscode from "vscode"; -import { EmitterSettingName } from "../const.js"; +import { SettingName } from "../types.js"; export enum EmitterKind { Schema = "schema", @@ -35,8 +35,8 @@ function getEmitter(kind: EmitterKind, emitter: Emitter): Emitter { } export function getRegisterEmitters(kind: EmitterKind): ReadonlyArray { - const emitters: ReadonlyArray = - extensionConfig.get(EmitterSettingName[kind] ?? "") ?? []; - - return emitters.map((emitter) => getEmitter(kind, emitter)); + const emitters: ReadonlyArray = extensionConfig.get(SettingName.Emitters) ?? []; + return emitters + .filter((emitter) => emitter.kind === kind) + .map((emitter) => getEmitter(kind, emitter)); } diff --git a/packages/typespec-vscode/src/extension.ts b/packages/typespec-vscode/src/extension.ts index d14b3a02fe..f5882c3324 100644 --- a/packages/typespec-vscode/src/extension.ts +++ b/packages/typespec-vscode/src/extension.ts @@ -47,11 +47,11 @@ export async function activate(context: ExtensionContext) { /* emit command. */ context.subscriptions.push( - commands.registerCommand(CommandName.EmitCode, async (uri: vscode.Uri) => { + commands.registerCommand(CommandName.Generate, async (uri: vscode.Uri) => { await vscode.window.withProgress( { location: vscode.ProgressLocation.Window, - title: "Emit Code...", + title: "Generate from TypeSpec...", cancellable: false, }, async (progress) => await emitCode(context, uri, progress), diff --git a/packages/typespec-vscode/src/types.ts b/packages/typespec-vscode/src/types.ts index 3300121ff0..6c748d6be8 100644 --- a/packages/typespec-vscode/src/types.ts +++ b/packages/typespec-vscode/src/types.ts @@ -1,9 +1,7 @@ export const enum SettingName { TspServerPath = "typespec.tsp-server.path", InitTemplatesUrls = "typespec.initTemplatesUrls", - ClientEmitter = "typespec.client.emitter", - ServerEmitter = "typespec.server.emitter", - SchemaEmitter = "typespec.schema.emitter", + Emitters = "typespec.emitters", } export const enum CommandName { @@ -12,7 +10,7 @@ export const enum CommandName { InstallGlobalCompilerCli = "typespec.installGlobalCompilerCli", CreateProject = "typespec.createProject", OpenUrl = "typespec.openUrl", - EmitCode = "typespec.emit", + Generate = "typespec.generate", } export interface InstallGlobalCliCommandArgs {