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 8d72f68
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 125 deletions.
104 changes: 35 additions & 69 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,14 +233,14 @@
"menus": {
"explorer/context": [
{
"command": "typespec.emit",
"command": "typespec.generate",
"when": "explorerResourceIsFolder || resourceLangId == typespec",
"group": "code_generation"
}
],
"editor/context": [
{
"command": "typespec.emit",
"command": "typespec.generate",
"when": "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";
78 changes: 41 additions & 37 deletions packages/typespec-vscode/src/emit/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function doEmit(
) {
if (!mainTspFile || !(await isFile(mainTspFile))) {
logger.info(
"Invalid typespec project. There is no main tsp file in the project. Emit canceled.",
"Invalid typespec project. There is no main tsp file in the project. Generating Cancelled.",
[],
{ showOutput: false, showPopup: true, progress: overallProgress },
);
Expand All @@ -50,16 +50,16 @@ export async function doEmit(
const all = [...registerEmitters].map((e) => toQuickPickItem(e));

const selectedEmitter = await vscode.window.showQuickPick<EmitQuickPickItem>(all, {
title: "Select the Language",
title: "Select a Language",
canPickMany: false,
placeHolder: "Pick a Language",
ignoreFocusOut: true,
});

if (!selectedEmitter) {
logger.info("No emitters selected. Emit canceled.", [], {
logger.info("No emitter selected. Generating Cancelled.", [], {
showOutput: false,
showPopup: true,
showPopup: false,
progress: overallProgress,
});
return;
Expand All @@ -77,7 +77,7 @@ export async function doEmit(
)
.then((selection) => {
if (selection === "OK") {
logger.info("Emit canceled.", [], {
logger.info("Generating Cancelled.", [], {
showOutput: false,
showPopup: true,
progress: overallProgress,
Expand Down Expand Up @@ -113,20 +113,20 @@ export async function doEmit(
const selected = await vscode.window.showQuickPick(Object.values(options), {
canPickMany: false,
ignoreFocusOut: true,
placeHolder: `Package '${selectedEmitter.package}' needs to be upgraded for emitting`,
title: `TypeSpec Emit...`,
placeHolder: `Package '${selectedEmitter.package}' needs to be upgraded for generating`,
title: `TypeSpec Generating...`,
});
if (selected === options.ok) {
packagesToInstall.push(`${selectedEmitter.package}@${version}`);
} else if (selected === options.ignore) {
logger.info(`Ignore upgrading emitter ${selectedEmitter.package} for emitting`, [], {
logger.info(`Ignore upgrading emitter ${selectedEmitter.package} for generating`, [], {
showOutput: false,
showPopup: false,
progress: overallProgress,
});
} else {
logger.info(
`Need to manually install the package ${selectedEmitter.package}@${version}. Emit canceled.`,
`Need to manually install the package ${selectedEmitter.package}@${version}. Generating Cancelled.`,
[],
{
showOutput: false,
Expand Down Expand Up @@ -157,14 +157,14 @@ export async function doEmit(
const selected = await vscode.window.showQuickPick(Object.values(options), {
canPickMany: false,
ignoreFocusOut: true,
placeHolder: `Package '${dependency}' needs to be upgraded for emitting`,
title: `TypeSpec Emit...`,
placeHolder: `Package '${dependency}' needs to be upgraded for generating`,
title: `TypeSpec Generate...`,
});
if (selected === options.ok) {
packagesToInstall.push(dependency);
} else {
logger.info(
`Need to manually install the dependency package ${dependency}@latest. Emit canceled.`,
`Need to manually install the dependency package ${dependency}@latest. Generating Cancelled.`,
[],
{
showOutput: false,
Expand Down Expand Up @@ -210,19 +210,23 @@ export async function doEmit(
}

/* emit */
logger.info("Emit code ...", [], {
logger.info("Generating ...", [], {
showOutput: false,
showPopup: false,
progress: overallProgress,
});

const cli = await resolveTypeSpecCli(baseDir);
if (!cli) {
logger.error("Cannot find TypeSpec CLI. Please install @typespec/compiler. Cancel emit.", [], {
showOutput: true,
showPopup: true,
progress: overallProgress,
});
logger.error(
"Cannot find TypeSpec CLI. Please install @typespec/compiler. Generating Cancelled.",
[],
{
showOutput: true,
showPopup: true,
progress: overallProgress,
},
);
return;
}
const outputDir = path.resolve(baseDir, selectedEmitter.emitterKind, selectedEmitter.language);
Expand All @@ -242,7 +246,7 @@ export async function doEmit(
const compileResult = await compile(cli, mainTspFile, selectedEmitter.package, options);
if (compileResult.exitCode !== 0) {
logger.error(
`Failed to generate ${selectedEmitter.language} ${selectedEmitter.emitterKind} code.`,
`Failed to generate ${selectedEmitter.emitterKind} code for ${selectedEmitter.language}.`,
[],
{
showOutput: true,
Expand All @@ -252,7 +256,7 @@ export async function doEmit(
);
} else {
logger.info(
`complete generating ${selectedEmitter.language} ${selectedEmitter.emitterKind} code.`,
`Generating ${selectedEmitter.emitterKind} code for ${selectedEmitter.language}...Succeeded`,
[],
{
showOutput: true,
Expand All @@ -263,7 +267,7 @@ export async function doEmit(
}
} catch (err) {
logger.error(
`Exception occurred when generating ${selectedEmitter.language} ${selectedEmitter.emitterKind} code.`,
`Exception occurred when generating ${selectedEmitter.emitterKind} code for ${selectedEmitter.language}.`,
[err],
{
showOutput: true,
Expand All @@ -286,7 +290,7 @@ export async function emitCode(
const targetPathes = await TraverseMainTspFileInWorkspace();
logger.info(`Found ${targetPathes.length} ${StartFileName} files`);
if (targetPathes.length === 0) {
logger.info("No main tsp file found. Emit canceled.", [], {
logger.info("No main tsp file found. Generating Cancelled.", [], {
showOutput: false,
showPopup: true,
progress: overallProgress,
Expand All @@ -307,13 +311,13 @@ export async function emitCode(
toProjectPickItem(filePath),
);
const selectedProjectFile = await vscode.window.showQuickPick(typespecProjectQuickPickItems, {
title: "Select TypeSpec Project",
title: "Select a TypeSpec Project",
canPickMany: false,
placeHolder: "Pick a project",
ignoreFocusOut: true,
});
if (!selectedProjectFile) {
logger.info("No project selected. Emit canceled.", [], {
logger.info("No project selected. Generating Cancelled.", [], {
showOutput: false,
showPopup: true,
progress: overallProgress,
Expand All @@ -340,34 +344,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.", [], {
logger.info("No emitters selected. Generating Cancelled.", [], {
showOutput: false,
showPopup: true,
showPopup: false,
progress: overallProgress,
});
return;
Expand Down
Loading

0 comments on commit 8d72f68

Please sign in to comment.