Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/hide-codegen-config-2025-0-15-9-4-57.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- typespec-vscode
---

remove vscode settings for code generation
98 changes: 0 additions & 98 deletions packages/typespec-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/typespec-vscode/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export const enum SettingName {
TspServerPath = "typespec.tsp-server.path",
InitTemplatesUrls = "typespec.initTemplatesUrls",
GenerateCodeEmitters = "typespec.generateCode.emitters",
}

export const enum CommandName {
Expand Down
61 changes: 51 additions & 10 deletions packages/typespec-vscode/src/vscode-cmd/emit-code/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import vscode from "vscode";
import logger from "../../log/logger.js";
import { SettingName } from "../../types.js";

export enum EmitterKind {
Schema = "openapi",
Expand Down Expand Up @@ -34,6 +33,54 @@ export const PreDefinedEmitterPickItems: Record<string, vscode.QuickPickItem> =
},
};

// TODO: remove this when we can load default emitters from the compiler
const PreDefinedEmitters: ReadonlyArray<Emitter> = [
{
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) {
Expand All @@ -60,26 +107,20 @@ function getEmitter(kind: EmitterKind, emitter: Emitter): Emitter | undefined {
}

export function getRegisterEmitters(kind: EmitterKind): ReadonlyArray<Emitter> {
const extensionConfig = vscode.workspace.getConfiguration();
const emitters: ReadonlyArray<Emitter> =
extensionConfig.get(SettingName.GenerateCodeEmitters) ?? [];
const emitters: ReadonlyArray<Emitter> = PreDefinedEmitters;
return emitters
.filter((emitter) => emitter.kind === kind)
.map((emitter) => getEmitter(kind, emitter))
.filter((emitter) => emitter !== undefined) as Emitter[];
}

export function getRegisterEmitterTypes(): ReadonlyArray<EmitterKind> {
const extensionConfig = vscode.workspace.getConfiguration();
const emitters: ReadonlyArray<Emitter> =
extensionConfig.get(SettingName.GenerateCodeEmitters) ?? [];
const emitters: ReadonlyArray<Emitter> = PreDefinedEmitters;
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<Emitter> =
extensionConfig.get(SettingName.GenerateCodeEmitters) ?? [];
const emitters: ReadonlyArray<Emitter> = PreDefinedEmitters;
return emitters.find(
(emitter) => emitter.package === packageName || emitter.package.startsWith(packageName + "@"),
);
Expand Down
Loading