Skip to content

Leverage LSP to do compile instead of CLI #7239

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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

Conversation

chunyu3
Copy link
Contributor

@chunyu3 chunyu3 commented May 6, 2025

Fix #6663

Now we are having many problems when triggering the compile from CLI and handling its output in our Output window like multiple loglevel, how to handle ```stderr``, coloring and so on.

So to resolve all these problems, let's trigger compile through LSP instead of CLI so that we can retrieve the result of compile directly which is more reliable and also easier to do post-processing.

Copy link
Contributor

github-actions bot commented May 6, 2025

All changed packages have been documented.

  • @typespec/compiler
  • typespec-vscode
Show changes

typespec-vscode - feature ✏️

Use language server to compile project instead of CLI

@typespec/compiler - feature ✏️

[LSP] Expose new compile project command

@azure-sdk
Copy link
Collaborator

azure-sdk commented May 6, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@chunyu3
Copy link
Contributor Author

chunyu3 commented May 6, 2025

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

finalMessage: string,
asyncAction: (task: TrackActionTask) => Promise<T>,
): Promise<T> {
const task = new DynamicServerTask(message, finalMessage, serverHost.log);
Copy link
Member

Choose a reason for hiding this comment

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

is this now logging all overt the place? This compile service is called a lot in the LSP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only logged when emit code. Other compiles such as compiling for authoring does not.

Copy link
Member

Choose a reason for hiding this comment

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

I guess its more can't this be defined in the server host construction instead of injected here for some irrelevant behavior of the compile service?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There will be only one ServerHost instance used across all scenarios, including authoring, hovering, and others. In these general scenarios, we do not log compile-time tracking information. Therefore, the trackAction will be undefined by default.

However, when handling the emit-code operation, we do need to log tracking data. In that case, we explicitly set trackActionand wrap the ServerHost in a new instance to ensure this logging does not interfere with other scenarios like authoring.

@chunyu3 chunyu3 requested a review from timotheeguerin May 7, 2025 01:24
@@ -112,17 +119,22 @@ export function createCompileService({
*/
async function compile(
document: TextDocument | TextDocumentIdentifier,
additionalOptions?: CompilerOptions,
bypassCache: boolean = false,
Copy link
Member

Choose a reason for hiding this comment

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

whats the purposse of bypassCache?

thoses options should also be an option bag not boolean positional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When there is a cache, and it is the same as before, compiling will complete after parse the tsp files and emitting will be cancelled.
So for emit-code request, we will bypassCache

@@ -53,3 +53,8 @@ export async function TraverseMainTspFileInWorkspace() {
.map((uri) => normalizeSlashes(uri.fsPath)),
);
}

export function GetVscodeUriFromPath(path: string) {
Copy link
Member

Choose a reason for hiding this comment

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

camelCase

isn't that what the fileService already gives you too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VscodeUri is encoded. fileService provide non-encoded one
e.g.
fileService: c:\dev\demoProject\main.tsp
vscodeuri: file:///c%3A/dev/demoProject/main.tsp

in lsp server cache, it will use vscodeUri as the key,

@chunyu3 chunyu3 requested a review from timotheeguerin May 9, 2025 10:11
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.

Leverage LSP to do compile instead of CLI
3 participants