-
Notifications
You must be signed in to change notification settings - Fork 225
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
base: main
Are you sure you want to change the base?
Conversation
All changed packages have been documented.
|
2f0fc43
to
b592194
Compare
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
6a30951
to
1722c43
Compare
b2e150b
to
d1b7723
Compare
PreDefinedEmitterPickItems, | ||
} from "./emitter.js"; | ||
|
||
export async function doEmit( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems no need to export
if (!selectedEmitter) { | ||
logger.info("No emitter selected. Generating Cancelled.", [], { | ||
showOutput: false, | ||
showPopup: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false is the default value, you can just logger.info("...") to make your code shorter.
return; | ||
} | ||
|
||
logger.info("npm install...", [], { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm install? People (us or end users) will use the log to do troubleshooting, please help to make these logs more detail and understandable.
logger.info(`${dependenciesToInstall}`); | ||
if (dependenciesToInstall.length > 0) { | ||
vscode.window.showInformationMessage( | ||
`Need to manually upgrade following dependency packages: ${dependenciesToInstall.join("\\n")}. \nGenerating Cancelled`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no option to install them for user?
); | ||
return; | ||
} | ||
const outputDir = path.resolve(baseDir, selectedEmitter.emitterKind, selectedEmitter.language); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.resolve? shouldn't be joinPath?
}); | ||
|
||
const emitterKinds = getRegisterEmitterTypes(); | ||
const toEitTypeQuickPickItem = (kind: EmitterKind): any => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eit? typo?
devDependencies = "devDependencies", | ||
} | ||
|
||
export interface NpmPackageInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a NodePackage type in compiler you can use directly
import logger from "./log/logger.js"; | ||
import { ExecOutput, loadModule, spawnExecution, spawnExecutionEvents } from "./utils.js"; | ||
|
||
export enum InstallationAction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually we prefer to use union to enum. like: InstallationAction = "install" | "upgrade" | "skip" | "cancel". same for below
|
||
if (dependenciesResult.exitCode === 0) { | ||
// Remove all newline characters | ||
let dependenciesJsonStr = dependenciesResult.stdout.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i remember there is a --json arg, doesn't it help?
.split("\n") | ||
.forEach((line) => logger.info(line)); | ||
}; | ||
export const onStdioError = (str: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
People can't figure out what these two methods for just by name which looks more like an event name... Why not just use the spawnExecutionAndLogToOutput which would log the stdio/stderr which is just what you want to do here, isn't it?
); | ||
}; | ||
|
||
export async function getEntrypointTspFile(tspPath: string): Promise<string | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you need to search parent folder for the main.tsp too. you can refer to getMainFileForDocument in core\server\compiler-service.ts
try { | ||
const files = await readdir(baseDir); | ||
if (files && files.length === 1 && files[0].endsWith(".tsp")) { | ||
return path.resolve(baseDir, files[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to report error than pick a random file which wouldn't right in most case
await doEmit(context, tspProjectFile, codeType.emitterKind); | ||
} | ||
|
||
export async function compile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you dont need to export this
import vscode from "vscode"; | ||
import { EmitterKind } from "./emitter.js"; | ||
|
||
export interface EmitQuickPickItem extends vscode.QuickPickItem { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feels you dont need to define this type explicitly either.
Fix #5025
Integrate Code Generation in VSCode extension