Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Code from TypeSpec in VSCode #5312

Open
wants to merge 82 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
ca3249a
emit sdk
chunyu3 Nov 18, 2024
b8468b6
add emitter configuration in extension setting
chunyu3 Nov 20, 2024
f0c4b89
add output dir configuration and options configuration
chunyu3 Nov 22, 2024
4691431
remove unused code
chunyu3 Nov 22, 2024
539bee9
update emitter configuration
chunyu3 Nov 24, 2024
7779481
resolve tsp command
chunyu3 Nov 26, 2024
05bbef7
define promised exec
chunyu3 Nov 26, 2024
41a8796
remove doEmit to emit.ts
chunyu3 Dec 2, 2024
31ee9e2
change to single language generation each run
chunyu3 Dec 3, 2024
6d604d8
select language box
chunyu3 Dec 6, 2024
406e7f9
remove unused code
chunyu3 Dec 6, 2024
a143f0a
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 6, 2024
a93c8b8
add validation of typespec project selection input box
chunyu3 Dec 8, 2024
4ba9a3a
transfer logs from spawn
chunyu3 Dec 8, 2024
ca87267
transport log out when execute command
chunyu3 Dec 9, 2024
a14b47e
validate the typespec project
chunyu3 Dec 9, 2024
5534466
remove executeCommand
chunyu3 Dec 9, 2024
92790d6
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 10, 2024
3a9886c
update pnpm-lock
chunyu3 Dec 10, 2024
7fec5be
add change log
chunyu3 Dec 10, 2024
bddc07b
resolve lint
chunyu3 Dec 10, 2024
8c36463
set package name instead of output dir
chunyu3 Dec 10, 2024
3b820b8
add emit code command
chunyu3 Dec 11, 2024
b3d794b
integrate server code and openapi generation
chunyu3 Dec 12, 2024
c5e28e1
remove unused interface
chunyu3 Dec 12, 2024
8b5ec56
refine the label text
chunyu3 Dec 12, 2024
3c333d9
add icon for start file
chunyu3 Dec 12, 2024
dfcc1fb
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 16, 2024
64af9ad
check dependency and resolve dependency conflict
chunyu3 Dec 17, 2024
416a8ce
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 17, 2024
21536fe
format
chunyu3 Dec 17, 2024
b592c14
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 17, 2024
c883353
remove unused code
chunyu3 Dec 17, 2024
6931980
refine text
chunyu3 Dec 18, 2024
0c8c284
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 18, 2024
86372ee
change the package install options
chunyu3 Dec 18, 2024
b121717
resolve comments
chunyu3 Dec 18, 2024
758ff38
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 18, 2024
7129527
remove options parameter
chunyu3 Dec 18, 2024
e96e073
refine text
chunyu3 Dec 18, 2024
9105874
remove dependency auto-install
chunyu3 Dec 18, 2024
6f49c5f
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 19, 2024
bae77bb
Merge branch 'generateSDK' of https://github.com/chunyu3/typespec int…
chunyu3 Dec 19, 2024
f70e9d0
resolve comments
chunyu3 Dec 19, 2024
e836b52
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 20, 2024
97d57de
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 23, 2024
8dc67ec
resolve comments
chunyu3 Dec 24, 2024
ee763ab
add progress for long running operations
chunyu3 Dec 24, 2024
792ec1c
remove emit to vscode-cmd folder
chunyu3 Dec 24, 2024
95dcef6
Merge branch 'main' into generateSDK
chunyu3 Dec 24, 2024
99c9ad0
refine the logger call
chunyu3 Dec 24, 2024
b2e27ca
submit comment every time
chunyu3 Dec 24, 2024
3b52923
revert try-it comment update
chunyu3 Dec 24, 2024
82b1a42
only pop-up project selection window when there are more than one tsp…
chunyu3 Dec 25, 2024
db5d908
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Dec 26, 2024
77452a0
refine text
chunyu3 Dec 27, 2024
0e2ab0f
support check multiple dependency type
chunyu3 Dec 29, 2024
d353b46
change to use spawnExecutionAndLogToOutput
chunyu3 Dec 29, 2024
0bf3f40
retrive entrypoint file from package.json and parent directory
chunyu3 Dec 29, 2024
9d7c0b1
implement package install or upgrade page
chunyu3 Dec 30, 2024
88eb4a4
log refine
chunyu3 Dec 30, 2024
7cec0fb
disable log pretty
chunyu3 Dec 30, 2024
8af049c
add progress bar for calculating packages to install
chunyu3 Dec 30, 2024
7a96a1c
parse the spawn output and display in correct way
chunyu3 Jan 2, 2025
b0fb151
typo
chunyu3 Jan 2, 2025
d528575
refine te
chunyu3 Jan 2, 2025
ea9c4f1
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Jan 3, 2025
cdbcc8c
add icon for dark themes
chunyu3 Jan 3, 2025
882f14c
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Jan 7, 2025
3973ad3
update the title of page
chunyu3 Jan 7, 2025
ba6b54a
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Jan 8, 2025
e066e81
log nice error message
chunyu3 Jan 8, 2025
303bf9d
remove duplicate error log
chunyu3 Jan 8, 2025
86d7822
Merge branch 'main' into generateSDK
chunyu3 Jan 8, 2025
168d116
add more-detail button in each quick pick item
chunyu3 Jan 8, 2025
128aab5
Merge branch 'generateSDK' of https://github.com/chunyu3/typespec int…
chunyu3 Jan 8, 2025
ab13f86
add button for more-details in install packages pick item
chunyu3 Jan 8, 2025
dd365b4
only add more-details button when it has srcRepo defined
chunyu3 Jan 8, 2025
01c693f
read and update tspconfig.yam
chunyu3 Jan 9, 2025
609928b
Merge branch 'main' of https://github.com/microsoft/typespec into gen…
chunyu3 Jan 9, 2025
69fe0bd
add changelog
chunyu3 Jan 9, 2025
9bcc6fc
simplify the config yaml update logic
chunyu3 Jan 9, 2025
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/generateSDK-2024-11-10-10-45-35.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this wait until I'm back before merging so we can discuss a little more what we want. I do not think this is a good feature to add in this form. The argument for not requiring to learn commands to generate is I feel invalid as you still need to know the language and install anything to get the rest working.

If this instead was just providing a way to add some known emitters and configure them to the tspconfig I think this would be much much better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @timotheeguerin .
Emitters will be registered in the VSCode extension settings. We pre-defined default emtters (both client emitters, server emitters for all languages, and the schema emitter also). We will provide a way for customer to register their customized emitter in future.

We will hold this PR merge and we discuss more after you back. Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timotheeguerin , thanks for looking at the PR in holiday and Merry Christmas!
Below is the spec for the feature (Those user cases with name "Generate XXX from TypeSpec") which should be able to give you more context and the user experience we want to provide. Any feedback is welcome, and we can discuss more when you are back. thanks.
https://microsoft.sharepoint.com/:w:/t/AzureDeveloperExperience/EXfInUWxaOpNpXVtcQOAt4cBoVwvu3tZe3Od__r9vdc8qQ?e=cmyNb0

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- typespec-vscode
---

integrate client SDK generation
8 changes: 8 additions & 0 deletions packages/typespec-vscode/icons/client.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/typespec-vscode/icons/dotnet.svg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some icons don't work well in dark theme.
image
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the most icons. except java for dark themes.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/typespec-vscode/icons/java.svg
chunyu3 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/typespec-vscode/icons/javascript.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/typespec-vscode/icons/openapi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/typespec-vscode/icons/openapi3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/typespec-vscode/icons/python.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/typespec-vscode/icons/server.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 119 additions & 0 deletions packages/typespec-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,104 @@
],
"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/[email protected]\n\nExample (without version): @typespec/http-client-csharp"
},
"sourceRepo": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user may not have repo and may want to show other information. How about name it "description" instead of "sourceRepo"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use sourceRepo in several place, not just library description.

"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": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RodgeFu, looks like we are baking a list of known 1P emitters in the extension packages. We have discussed this being built-in template driven. I would also like to re-review design of the Generate Code flow. I have comments on what's listed in the design doc on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check my comment in the doc. thx.

{
"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 Expand Up @@ -141,6 +239,11 @@
"title": "Show Output Channel",
"category": "TypeSpec"
},
{
"command": "typespec.generateCode",
"title": "Generate from TypeSpec",
"category": "TypeSpec"
},
{
"command": "typespec.createProject",
"title": "Create TypeSpec Project",
Expand All @@ -152,6 +255,22 @@
"category": "TypeSpec"
}
],
"menus": {
"explorer/context": [
{
"command": "typespec.generateCode",
"when": "explorerResourceIsFolder || resourceLangId == typespec",
"group": "code_generation"
}
],
"editor/context": [
{
"command": "typespec.generateCode",
"when": "resourceLangId == typespec",
"group": "code_generation"
}
]
},
"semanticTokenScopes": [
{
"scopes": {
Expand Down
1 change: 1 addition & 0 deletions packages/typespec-vscode/src/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const StartFileName = "main.tsp";
chunyu3 marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions packages/typespec-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
SettingName,
} from "./types.js";
import { createTypeSpecProject } from "./vscode-cmd/create-tsp-project.js";
import { emitCode } from "./vscode-cmd/emit-code/emit-code.js";
import { installCompilerGlobally } from "./vscode-cmd/install-tsp-compiler.js";

let client: TspLanguageClient | undefined;
Expand Down Expand Up @@ -44,6 +45,20 @@ export async function activate(context: ExtensionContext) {
}),
);

/* emit command. */
context.subscriptions.push(
commands.registerCommand(CommandName.GenerateCode, async (uri: vscode.Uri) => {
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Window,
title: "Generate from TypeSpec...",
cancellable: false,
},
async () => await emitCode(context, uri),
);
}),
);

context.subscriptions.push(
commands.registerCommand(
CommandName.RestartServer,
Expand Down
Loading
Loading