Skip to content

Comments

TS: Add setting to prompt users about workspace tsdk#95566

Merged
mjbvz merged 2 commits intomicrosoft:masterfrom
DuncanWalter:ts-prompt-use-workspace-tsdk
Apr 22, 2020
Merged

TS: Add setting to prompt users about workspace tsdk#95566
mjbvz merged 2 commits intomicrosoft:masterfrom
DuncanWalter:ts-prompt-use-workspace-tsdk

Conversation

@DuncanWalter
Copy link
Contributor

This PR addresses #95250, #65546

Adds a setting to the typescript-language-features extension which enables prompting users to switch to the workspace tsdk specified in the workspace settings. The prompts can be permanently dismissed on a per-workspace basis. As a formality, also adds a hidden command that reenables the prompts (which I'd be happy to rip out- just seemed weird to have non-reversible internal state).

I'm all ears for any and all naming/wording improvements. One potential change I'm on the fence about is displaying the relative workspace path to the tsdk in the prompt.

I opted to make the VersionProvider class a disposable with an event emitter as opposed to making the client's update callback more complicated. I also decided to keep extensionContext access limited to the VersionManager. I attempted a couple other implementations, but ultimately found it difficult to prevent the VersionProvider and VersionManager from becoming entangled in a confusing way.

The prompt is triggered when all of:

  • the user has not opted out of the prompt in the workspace
  • the workspace configures a tsdk
  • the user or workspace sets the enablePromptUseWorkspaceTsdk setting
  • the workspace is not already using the workspace Tsdk
  • either the extension just activated or transitioned from a state where one of the above was untrue

Are there examples of any tests for similar features I should look at mimicking?

cc @mjbvz

@msftclas
Copy link

msftclas commented Apr 17, 2020

CLA assistant check
All CLA requirements met.

@DuncanWalter DuncanWalter force-pushed the ts-prompt-use-workspace-tsdk branch from 33084c7 to 5b0f687 Compare April 17, 2020 21:00
Copy link
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

Thank you for taking a look at this!

I'm having trouble following some of the logic and how all the events interact with each other. Here's a quick breakdown of the expected behavior for a few different cases:

User opens a workspace without a tsdk setting

No change.

User opens a workspace with a tsdk setting and enablePromptUseWorkspaceTsdk != true

No change.

User opens a workspace for the first time that has tsdk set and enablePromptUseWorkspaceTsdk = true

  • We start the normal server.
  • At this point, we also show a prompt to the user asking if they would like to switch to the workspace version.
  • If the user says no, we remember that and don't prompt them again.
  • If the user says yes, we perform the equivalent of manually selecting the workspace version using the Select TypeScript version command. This automatically restarts the TS Server with the workspace version

User opens a workspace and is using global TS version. Then tsdk or enablePromptUseWorkspaceTsdk is written into the workspace setting

Show the same prompt as above. (Make sure that using the Select TypeScript Version command does not trigger a prompt)

User opens a workspace that they previously configured to use the workspace version

The user should never be prompted to switch.

This seems to mostly match what the PR is doing but make sure to try out the edge case too.

For the code changes, I'd try to avoid touching the TypeScriptVersionProvider and keep the logic centralized to the version manager

@DuncanWalter DuncanWalter force-pushed the ts-prompt-use-workspace-tsdk branch from 5b0f687 to 187dbaf Compare April 18, 2020 14:07
@DuncanWalter DuncanWalter marked this pull request as ready for review April 20, 2020 13:48
Copy link
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

Looks good. Just a small change requested and then I think we should be good to merge

this._register(this._versionManager.onDidPickNewVersion(() => {
this.restartTsServer();
}));
this._register(this._versionManager.onEnteredPromptWorkspaceTsdkState(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this event is now only being used to call back into the version manager, so let's removed it and just have the version manager call promptUseWorkspaceTsdk


private updateForPickedVersion(pickedVersion: TypeScriptVersion) {
public async promptUseWorkspaceTsdk(): Promise<void> {
const workspaceVersion = this.versionProvider.localVersion;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please also make sure the user is not prompted if typescript is installed locally but typescript.tsdk is not set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It follows the desired behavior in local testing. The check to see whether the prompt should runs is checking for the tsdk setting in configuration here. The intent is that promptUseWorkspaceTsdk should never be called in situations where the user shouldn't be prompted. Confusingly, promptUseWorkspaceTsdk reads the local version from the versionProvider to get a reference to the instance of TypeScriptVersion. configuation.localTsdk is a string, which isn't enough to set the new TS version AFAIK

@DuncanWalter
Copy link
Contributor Author

Preemptively bumping this because I think I pushed most recently during the githooks disruption yesterday- not sure if it sent notifications out properly. No rush / not trying to nag

@mjbvz mjbvz added this to the April 2020 milestone Apr 22, 2020
@mjbvz mjbvz merged commit c7c2301 into microsoft:master Apr 22, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Apr 22, 2020

Thanks! This will be in the next vs code insiders build and is scheduled to go out with VS Code 1.45

Does this PR address the original issue you opened as well?

@DuncanWalter
Copy link
Contributor Author

It addresses the underlying problem, so I'll close the issue 👍

@DuncanWalter DuncanWalter deleted the ts-prompt-use-workspace-tsdk branch April 23, 2020 19:27
@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants