Skip to content

Conversation

mzhongl524
Copy link
Member

Fix: #6062

Setting custom entrypoint file for tsp project

@mzhongl524 mzhongl524 added the ide Issues for VS, VSCode, Monaco, etc. label Jul 16, 2025
@mzhongl524 mzhongl524 marked this pull request as draft July 16, 2025 08:07
Copy link
Contributor

github-actions bot commented Jul 16, 2025

All changed packages have been documented.

  • @typespec/compiler
  • typespec-vscode
Show changes

@typespec/compiler - feature [✏️](https://github.com/mzhongl524/typespec/edit/custom-entrypoint-file-for-tsp-project/.chronus/changes/custom-entrypoint-file-for-tsp-project-2025-6-24-6-57-40 copy.md?pr=//pull/7929)

[LSP] Allow configuring which file names to use as entrypoints

typespec-vscode - feature ✏️

Allow configuring which file names to use as entrypoints

@azure-sdk
Copy link
Collaborator

azure-sdk commented Jul 16, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@timotheeguerin
Copy link
Member

@mzhongl524 pleas try to submit the PR as a draft(Dropdown on the create Pr button) not converting it to a draft otherwise it still request review from everybody immediately.

@mzhongl524 mzhongl524 marked this pull request as ready for review July 21, 2025 09:20
Copy link
Member

Choose a reason for hiding this comment

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

file name is inconsistent with the file name its testing

import { resolveEntrypointFile } from "../../src/server/entrypoint-resolver.js";
import type { ServerLog } from "../../src/server/types.js";

describe("compiler: server: resolveEntrypointFile", () => {
Copy link
Member

Choose a reason for hiding this comment

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

remove top level describe

}

// If there is no configuration, null is passed in vscode while undefined is passed in the compiler.
if (
Copy link
Member

Choose a reason for hiding this comment

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

I thought we agreed that this should be deleted and entrpoints should just default to main.tsp above with the package.json being the outerbound regardless

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, we did that change but then realize it breaks the behavior that if user sets nothing but have main defined in package.json instead, it should have higher priority than main.tsp file. so made some change there. thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Which does seem expected to me. Can you show a file structure where you think the user wouldn't want that?

Copy link
Contributor

@RodgeFu RodgeFu Aug 31, 2025

Choose a reason for hiding this comment

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

something like below. the entrypoint should be resolved as 'abc.tsp' instead of 'main.tsp' if user doesn't set the entrypoint explicitly in vscode.

-- main.tsp
 - abc.tsp
 - package.json <-- in the package.json, set the main to 'abc.tsp'

Copy link
Member

Choose a reason for hiding this comment

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

Here I would expect abc to be the entrypoint. The package.json marks the boundary anyway where packages are installed. They main.tsp most likely is not working.
Package.json is the closest we currently have to make something as a project

Copy link
Contributor

@RodgeFu RodgeFu Sep 1, 2025

Choose a reason for hiding this comment

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

yes, so we need to check the "main.tsp" after the package.json part when the entrypoints are not set explicitly, otherwise if we default to ["main.tsp"] and search for it before the package.json part, the "main.tsp" will be returned (line 34 above) instead of the "abc.tsp".

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't that just work if the algorithm is

while dir:
If has tsp main in package.json
Return
If has file in entrypoints(default to main.tsp)
Return
Dir = parent dir

Copy link
Contributor

Choose a reason for hiding this comment

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

But I think if user set the entrypoints in the vscode settings explicitly, it should have higher priority than the tsp main in package.json, so the priority is like

  1. explicit settings of entrypoint
  2. tsp main in package.json
  3. default 'main.tsp' (when nothing set above)

Copy link
Member

Choose a reason for hiding this comment

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

I disagree. If you hit this as said above it most likely will break as dependencies are below.
Packagejson mark the package boundary it doesn't make sense imo it would work outside of it

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean the search should stop at the package.json level? I agree with that. The pri i mentioned above is in the same dir level, it's something like below in my mind:

while(valid dir || no package.json)
{
check entrypoints explicitly set, return if found
check tsp main in package.json, return if found
check default 'main.tsp' if entrypoints not set explicitly, if found, save as potential entrypoint to be returned
dir = parent dir
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ide Issues for VS, VSCode, Monaco, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extension: Generate from TypeSpec does not work with client.tsp as entrypoint file
4 participants