Skip to content

Commit

Permalink
refine text
Browse files Browse the repository at this point in the history
  • Loading branch information
chunyu3 committed Dec 18, 2024
1 parent 7129527 commit 27dfd6d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 99 deletions.
102 changes: 34 additions & 68 deletions packages/typespec-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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/[email protected]\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/[email protected]\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/[email protected]\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."
]
}
}
}
Expand Down Expand Up @@ -249,8 +215,8 @@
"category": "TypeSpec"
},
{
"command": "typespec.emit",
"title": "TypeSpec: Emit Code",
"command": "typespec.generate",
"title": "Generate from TypeSpec",
"category": "TypeSpec"
},
{
Expand All @@ -267,7 +233,7 @@
"menus": {
"explorer/context": [
{
"command": "typespec.emit",
"command": "typespec.generate",
"when": "explorerResourceIsFolder || resourceLangId == typespec",
"group": "code_generation"
}
Expand Down
8 changes: 0 additions & 8 deletions packages/typespec-vscode/src/const.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
import { SettingName } from "./types.js";

export const EmitterSettingName: Record<string, string> = {
client: SettingName.ClientEmitter,
server: SettingName.ServerEmitter,
schema: SettingName.SchemaEmitter,
};

export const StartFileName = "main.tsp";
24 changes: 12 additions & 12 deletions packages/typespec-vscode/src/emit/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,34 +340,34 @@ 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: "<PREVIEW> 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<EmitTypeQuickPickItem>(codesToEmit, {
title: "Emit Code",
title: "Select an Emitter Type",
canPickMany: false,
placeHolder: "Select an option",
ignoreFocusOut: true,
});
if (!codeType) {
logger.info("No emitters selected. Emit canceled.", [], {
showOutput: false,
showPopup: true,
showPopup: false,
progress: overallProgress,
});
return;
Expand Down
10 changes: 5 additions & 5 deletions packages/typespec-vscode/src/emit/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vscode from "vscode";
import { EmitterSettingName } from "../const.js";
import { SettingName } from "../types.js";

export enum EmitterKind {
Schema = "schema",
Expand Down Expand Up @@ -35,8 +35,8 @@ function getEmitter(kind: EmitterKind, emitter: Emitter): Emitter {
}

export function getRegisterEmitters(kind: EmitterKind): ReadonlyArray<Emitter> {
const emitters: ReadonlyArray<Emitter> =
extensionConfig.get(EmitterSettingName[kind] ?? "") ?? [];

return emitters.map((emitter) => getEmitter(kind, emitter));
const emitters: ReadonlyArray<Emitter> = extensionConfig.get(SettingName.Emitters) ?? [];
return emitters
.filter((emitter) => emitter.kind === kind)
.map((emitter) => getEmitter(kind, emitter));
}
4 changes: 2 additions & 2 deletions packages/typespec-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 2 additions & 4 deletions packages/typespec-vscode/src/types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 27dfd6d

Please sign in to comment.