From fa16709c913e2af1e60c569d554fc193489ab3ab Mon Sep 17 00:00:00 2001 From: RodgeFu Date: Wed, 15 Jan 2025 08:54:36 +0800 Subject: [PATCH 1/3] remove code generation settings for now --- packages/typespec-vscode/package.json | 98 ------------------- packages/typespec-vscode/src/types.ts | 1 - .../src/vscode-cmd/emit-code/emitter.ts | 61 ++++++++++-- 3 files changed, 51 insertions(+), 109 deletions(-) diff --git a/packages/typespec-vscode/package.json b/packages/typespec-vscode/package.json index ac437f9cab6..4942a3fdc27 100644 --- a/packages/typespec-vscode/package.json +++ b/packages/typespec-vscode/package.json @@ -108,104 +108,6 @@ ], "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.generateCode.emitters": { - "scope": "window", - "type": "array", - "items": { - "type": "object", - "properties": { - "language": { - "type": "string", - "enum": [ - ".NET", - "Java", - "JavaScript", - "Python", - "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" - }, - "sourceRepo": { - "type": "string", - "description": "Define the source repository of the emitter package." - }, - "requisites": { - "type": "array", - "items": { - "type": "string" - }, - "description": "Define the requisites of the emitter package." - }, - "kind": { - "type": "string", - "enum": [ - "client", - "server", - "openapi" - ], - "description": "Define the emitter kind." - } - } - }, - "default": [ - { - "language": ".NET", - "package": "@typespec/http-client-csharp", - "sourceRepo": "https://github.com/microsoft/typespec/tree/main/packages/http-client-csharp", - "requisites": [ - ".NET 8.0 SDK" - ], - "kind": "client" - }, - { - "language": "Java", - "package": "@typespec/http-client-java", - "sourceRepo": "https://github.com/microsoft/typespec/tree/main/packages/http-client-java", - "requisites": [ - "Java 17 or above", - "Maven" - ], - "kind": "client" - }, - { - "language": "JavaScript", - "package": "@azure-tools/typespec-ts", - "sourceRepo": "https://github.com/Azure/autorest.typescript/tree/main/packages/typespec-ts", - "kind": "client" - }, - { - "language": "Python", - "package": "@typespec/http-client-python", - "sourceRepo": "https://github.com/microsoft/typespec/tree/main/packages/http-client-python", - "kind": "client" - }, - { - "language": ".NET", - "package": "@typespec/http-server-csharp", - "sourceRepo": "https://github.com/microsoft/typespec/tree/main/packages/http-server-csharp", - "kind": "server" - }, - { - "language": "JavaScript", - "package": "@typespec/http-server-javascript", - "sourceRepo": "https://github.com/microsoft/typespec/tree/main/packages/http-server-javascript", - "kind": "server" - }, - { - "language": "OpenAPI3", - "package": "@typespec/openapi3", - "sourceRepo": "https://github.com/microsoft/typespec/tree/main/packages/openapi3", - "kind": "openapi" - } - ] } } } diff --git a/packages/typespec-vscode/src/types.ts b/packages/typespec-vscode/src/types.ts index 9abd25fb264..fdf3d58ed76 100644 --- a/packages/typespec-vscode/src/types.ts +++ b/packages/typespec-vscode/src/types.ts @@ -1,7 +1,6 @@ export const enum SettingName { TspServerPath = "typespec.tsp-server.path", InitTemplatesUrls = "typespec.initTemplatesUrls", - GenerateCodeEmitters = "typespec.generateCode.emitters", } export const enum CommandName { diff --git a/packages/typespec-vscode/src/vscode-cmd/emit-code/emitter.ts b/packages/typespec-vscode/src/vscode-cmd/emit-code/emitter.ts index 3fe1fb41370..28bc5a312bb 100644 --- a/packages/typespec-vscode/src/vscode-cmd/emit-code/emitter.ts +++ b/packages/typespec-vscode/src/vscode-cmd/emit-code/emitter.ts @@ -1,6 +1,5 @@ import vscode from "vscode"; import logger from "../../log/logger.js"; -import { SettingName } from "../../types.js"; export enum EmitterKind { Schema = "openapi", @@ -34,6 +33,54 @@ export const PreDefinedEmitterPickItems: Record = }, }; +// TODO: remove this when we can load default emitters from the compiler +const PreDefiniedEmitters: ReadonlyArray = [ + { + language: ".NET", + package: "@typespec/http-client-csharp", + sourceRepo: "https://github.com/microsoft/typespec/tree/main/packages/http-client-csharp", + requisites: [".NET 8.0 SDK"], + kind: EmitterKind.Client, + }, + { + language: "Java", + package: "@typespec/http-client-java", + sourceRepo: "https://github.com/microsoft/typespec/tree/main/packages/http-client-java", + requisites: ["Java 17 or above", "Maven"], + kind: EmitterKind.Client, + }, + { + language: "JavaScript", + package: "@azure-tools/typespec-ts", + sourceRepo: "https://github.com/Azure/autorest.typescript/tree/main/packages/typespec-ts", + kind: EmitterKind.Client, + }, + { + language: "Python", + package: "@typespec/http-client-python", + sourceRepo: "https://github.com/microsoft/typespec/tree/main/packages/http-client-python", + kind: EmitterKind.Client, + }, + { + language: ".NET", + package: "@typespec/http-server-csharp", + sourceRepo: "https://github.com/microsoft/typespec/tree/main/packages/http-server-csharp", + kind: EmitterKind.Server, + }, + { + language: "JavaScript", + package: "@typespec/http-server-javascript", + sourceRepo: "https://github.com/microsoft/typespec/tree/main/packages/http-server-javascript", + kind: EmitterKind.Server, + }, + { + language: "OpenAPI3", + package: "@typespec/openapi3", + sourceRepo: "https://github.com/microsoft/typespec/tree/main/packages/openapi3", + kind: EmitterKind.Schema, + }, +]; + function getEmitter(kind: EmitterKind, emitter: Emitter): Emitter | undefined { let packageFullName: string = emitter.package; if (!packageFullName) { @@ -60,9 +107,7 @@ function getEmitter(kind: EmitterKind, emitter: Emitter): Emitter | undefined { } export function getRegisterEmitters(kind: EmitterKind): ReadonlyArray { - const extensionConfig = vscode.workspace.getConfiguration(); - const emitters: ReadonlyArray = - extensionConfig.get(SettingName.GenerateCodeEmitters) ?? []; + const emitters: ReadonlyArray = PreDefiniedEmitters; return emitters .filter((emitter) => emitter.kind === kind) .map((emitter) => getEmitter(kind, emitter)) @@ -70,16 +115,12 @@ export function getRegisterEmitters(kind: EmitterKind): ReadonlyArray { } export function getRegisterEmitterTypes(): ReadonlyArray { - const extensionConfig = vscode.workspace.getConfiguration(); - const emitters: ReadonlyArray = - extensionConfig.get(SettingName.GenerateCodeEmitters) ?? []; + const emitters: ReadonlyArray = PreDefiniedEmitters; return Array.from(new Set(emitters.map((emitter) => emitter.kind))); } export function getRegisterEmittersByPackage(packageName: string): Emitter | undefined { - const extensionConfig = vscode.workspace.getConfiguration(); - const emitters: ReadonlyArray = - extensionConfig.get(SettingName.GenerateCodeEmitters) ?? []; + const emitters: ReadonlyArray = PreDefiniedEmitters; return emitters.find( (emitter) => emitter.package === packageName || emitter.package.startsWith(packageName + "@"), ); From e55bf5bffaf1e6edddb1cc3fc6c9788cff720c53 Mon Sep 17 00:00:00 2001 From: RodgeFu Date: Wed, 15 Jan 2025 09:05:07 +0800 Subject: [PATCH 2/3] add changelog --- .chronus/changes/hide-codegen-config-2025-0-15-9-4-57.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/hide-codegen-config-2025-0-15-9-4-57.md diff --git a/.chronus/changes/hide-codegen-config-2025-0-15-9-4-57.md b/.chronus/changes/hide-codegen-config-2025-0-15-9-4-57.md new file mode 100644 index 00000000000..8c051f42086 --- /dev/null +++ b/.chronus/changes/hide-codegen-config-2025-0-15-9-4-57.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - typespec-vscode +--- + +remove vscode settings for code generation \ No newline at end of file From 34411329a703745f33bb202778c9d2550d8ba598 Mon Sep 17 00:00:00 2001 From: RodgeFu Date: Wed, 15 Jan 2025 09:09:28 +0800 Subject: [PATCH 3/3] fix typo --- .../typespec-vscode/src/vscode-cmd/emit-code/emitter.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/typespec-vscode/src/vscode-cmd/emit-code/emitter.ts b/packages/typespec-vscode/src/vscode-cmd/emit-code/emitter.ts index 28bc5a312bb..a7f82222867 100644 --- a/packages/typespec-vscode/src/vscode-cmd/emit-code/emitter.ts +++ b/packages/typespec-vscode/src/vscode-cmd/emit-code/emitter.ts @@ -34,7 +34,7 @@ export const PreDefinedEmitterPickItems: Record = }; // TODO: remove this when we can load default emitters from the compiler -const PreDefiniedEmitters: ReadonlyArray = [ +const PreDefinedEmitters: ReadonlyArray = [ { language: ".NET", package: "@typespec/http-client-csharp", @@ -107,7 +107,7 @@ function getEmitter(kind: EmitterKind, emitter: Emitter): Emitter | undefined { } export function getRegisterEmitters(kind: EmitterKind): ReadonlyArray { - const emitters: ReadonlyArray = PreDefiniedEmitters; + const emitters: ReadonlyArray = PreDefinedEmitters; return emitters .filter((emitter) => emitter.kind === kind) .map((emitter) => getEmitter(kind, emitter)) @@ -115,12 +115,12 @@ export function getRegisterEmitters(kind: EmitterKind): ReadonlyArray { } export function getRegisterEmitterTypes(): ReadonlyArray { - const emitters: ReadonlyArray = PreDefiniedEmitters; + const emitters: ReadonlyArray = PreDefinedEmitters; return Array.from(new Set(emitters.map((emitter) => emitter.kind))); } export function getRegisterEmittersByPackage(packageName: string): Emitter | undefined { - const emitters: ReadonlyArray = PreDefiniedEmitters; + const emitters: ReadonlyArray = PreDefinedEmitters; return emitters.find( (emitter) => emitter.package === packageName || emitter.package.startsWith(packageName + "@"), );