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

Init logic bundle the compiler logic instead of shelling out to some random client #6086

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

timotheeguerin
Copy link
Member

@timotheeguerin timotheeguerin commented Feb 20, 2025

Initial move to fix #6068
Move the logic to init a typespec project to be bundled in vscode instead of shelling to the LSP.

  • Changes done:
    • detatch a little more the init logic from the compiler
    • copy the compiler templates and load them directly in vscode

@@ -314,7 +269,8 @@ async function tspInstall(
const TIMEOUT = 600000; // set timeout to 10 minutes which should be enough for tsp install for a new project
try {
const result = await createPromiseWithCancelAndTimeout(
client.runCliCommand(["install"], directory),
// client.runCliCommand(["install"], directory),
Promise.resolve(undefined), // todo: implement tsp install
Copy link
Member Author

Choose a reason for hiding this comment

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

todo: deal with tsp install

@azure-sdk
Copy link
Collaborator

azure-sdk commented Feb 20, 2025

❌ There is undocummented changes. Run chronus add to add a changeset or click here.

The following packages have changes but are not documented.

  • @typespec/compiler
  • typespec-vscode
Show changes

);
return false;
}
// if (!result) {
Copy link
Member Author

Choose a reason for hiding this comment

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

todo when was this even getting here previously

Copy link
Contributor

Choose a reason for hiding this comment

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

client.initProject would return false when fails for some reason. This is not needed if calling the function directly.

@timotheeguerin timotheeguerin mentioned this pull request Feb 20, 2025
return false;
}
}
// TODO: Why is this here again?
Copy link
Contributor

Choose a reason for hiding this comment

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

call validate in compiler to do further validation (check json schema). you can check validateTemplate in init.ts.

if (info.sourceType === "compiler") {
// no need to validate template from compiler
return true;
}

const compilerVersion = client.initializeResult?.serverInfo?.version;
const compilerVersion = vscode.extensions.getExtension("typespec.typespec")?.packageJSON.version;
Copy link
Contributor

Choose a reason for hiding this comment

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

what if it's a hotfix release that compiler doesn't have the version.

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure I get what you mean. Believe i was just trying to get the version of the extension here. But also like a lot of this is is more of POC than the final product as its now stuck on permission error(not sure if its due to my vscode or we should use other apis for writing files) and with 1.0 coming not sure I'll have time to finish this

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big issue, what I mean is that the vscode extension's version is used as compiler version here, which is fine in most case but when the vscode extension has a hotfix release (i.e. 0.xx.1) but compiler doesn't, the version got here may not exist for compiler (i.e. compile doesn't have 0.xx.1 version).
I think it should be fine to be used here to compare version internally considering the patch version is always larger. But it's better to (maybe cut the patch #) when showing the version to end user which will be confusing if we are showing some non-existing compiler version to them.

I will give it a try to see whether I get the permission error. will let you know. thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I gave it a try and didn't get any permission issue, but I found the files generated by writePackageJson(), writeConfig(), writeMain(), writeGitignore() are actually written to VSCode folder because they are using cwd (which is VSCode folder in this case) to write files when only a file name is given. After I pass the config.directory to them and parse absolute path to write files in these method. These files can be generated properly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah that would probably explain the permission issue on osx.
Thanks for finding this.

template: value,
})),
);
}
logger.info("Loading init templates from config...");
Copy link
Contributor

Choose a reason for hiding this comment

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

this log is for the next step.

@@ -0,0 +1,2 @@
export { NodeSystemHost } from "../core/node-system-host.js";
export { scaffoldNewProject } from "../init/scaffold.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

i think you also need to export validateTemplate method or template schema for vscode to do all the template validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typespec Vscode extension should bundle the init logic
3 participants