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

Enable Project Context status item for Razor files #7333

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

JoeRobich
Copy link
Member

Requests the virtual C# file path and uses that to get project context information.

image

When used with DevKit:
image

@JoeRobich JoeRobich requested a review from a team as a code owner July 11, 2024 23:57
@@ -58,6 +72,20 @@ export class ProjectContextService {
this._contextChangeEmitter.fire({ uri, context });
}

private async getVirtualCSharpUri(uri: vscode.Uri): Promise<vscode.Uri | undefined> {
const response = await vscode.commands.executeCommand<ProvideDynamicFileResponse>(
Copy link
Contributor

Choose a reason for hiding this comment

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

@davidwengier I'm not sure if there will be any problem using this endpoint or if there's something else that should be used to find the dynamic file URI

Copy link
Contributor

@davidwengier davidwengier Jul 12, 2024

Choose a reason for hiding this comment

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

I don't think it would cause any issues. In theory it could trigger Razor activation, but if this only gets called when a Razor document is open in the editor, that either has happened, or is about to anyway.

I guess the only risk here is that the uri in this method is different from the one Roslyn sends us, but points to the same physical file. Not sure what would happen in that case

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 it would get added to the document list with a wrong uri and either be fixed or show up in misc files

davidwengier
davidwengier previously approved these changes Jul 12, 2024
@@ -58,6 +72,20 @@ export class ProjectContextService {
this._contextChangeEmitter.fire({ uri, context });
}

private async getVirtualCSharpUri(uri: vscode.Uri): Promise<vscode.Uri | undefined> {
const response = await vscode.commands.executeCommand<ProvideDynamicFileResponse>(
Copy link
Contributor

@davidwengier davidwengier Jul 12, 2024

Choose a reason for hiding this comment

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

I don't think it would cause any issues. In theory it could trigger Razor activation, but if this only gets called when a Razor document is open in the editor, that either has happened, or is about to anyway.

I guess the only risk here is that the uri in this method is different from the one Roslyn sends us, but points to the same physical file. Not sure what would happen in that case

);

const responseUri = response.generatedFiles[0];
if (!responseUri) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need an explicit check for null too?

Copy link
Member Author

Choose a reason for hiding this comment

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

The false-y check should cover null, undefined, and i think '' as well.

@JoeRobich JoeRobich requested a review from a team as a code owner July 12, 2024 09:06
@@ -119,6 +119,8 @@ export class RazorDocumentSynchronizer {
}

private removeSynchronization(context: SynchronizationContext) {
context.dispose();
Copy link
Member Author

Choose a reason for hiding this comment

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

@davidwengier Does this seem right? What I was seeing in CI and locally was that the document and text document were up to date. So the context was removed. The token then got cancelled and the callbacks were rejected. This created an unhandled exception. I figure if we are removing the context, then we don't care about cancellation and can remove the callbacks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I see why the token would get cancelled, but clearing the rejections like this doesn't seem like it would be an issue.

@JoeRobich JoeRobich dismissed davidwengier’s stale review July 12, 2024 16:20

Could I get another review for the razorDocumentSynchronizer.ts changes?

@@ -119,6 +119,8 @@ export class RazorDocumentSynchronizer {
}

private removeSynchronization(context: SynchronizationContext) {
context.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I see why the token would get cancelled, but clearing the rejections like this doesn't seem like it would be an issue.

@@ -119,6 +119,8 @@ export class RazorDocumentSynchronizer {
}

private removeSynchronization(context: SynchronizationContext) {
context.dispose();

const documentKey = getUriPath(context.projectedDocument.uri);
const synchronizations = this.synchronizations[documentKey];
clearTimeout(context.timeoutId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Consider moving this inside context.Dispose() now that it exists?

Copy link
Member Author

@JoeRobich JoeRobich Jul 12, 2024

Choose a reason for hiding this comment

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

Since integration tests have been flaky for me, I will take your suggestions as a follow up and get this merged for snap.

Comment on lines +173 to +175
while (rejectionsForCancel.length > 0) {
rejectionsForCancel.pop();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think rejectionsForCancel.length = 0 works too

@JoeRobich JoeRobich merged commit a3d678e into main Jul 12, 2024
13 checks passed
JoeRobich added a commit that referenced this pull request Jul 12, 2024
@JoeRobich JoeRobich deleted the dev/jorobich/razor-project-context branch October 8, 2024 20:47
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.

4 participants