Skip to content

Stop pushing QL pack as top level folder to avoid confusing the user#2310

Merged
elenatanasoiu merged 10 commits intomainfrom
yer-a-workspace-query
Apr 14, 2023
Merged

Stop pushing QL pack as top level folder to avoid confusing the user#2310
elenatanasoiu merged 10 commits intomainfrom
yer-a-workspace-query

Conversation

@elenatanasoiu
Copy link
Copy Markdown
Contributor

@elenatanasoiu elenatanasoiu commented Apr 13, 2023

Came out of #2250 (comment)

In the original flow for creating skeleton packs, we were starting out
by choosing a database (e.g. github/codeql) and having the extension
create the QL pack for us.

At that point, we were storing the QL pack together with the database in
the extension storage because we weren't interested in committing it to
the repo.

This means we weren't able to see it in the file explorer so in order to
make it visible, we made a decision to push it as a top-level folder in the
workspace.

Hindsight is 20/20.

Let's change this original flow by just creating the folder in the
in the repo instead of the extension storage (which will make it
visible in the file explorer) and stop pushing it as an extra top level folder
in the workspace.

This makes it consistent with what we're doing for the skeleton query
wizard where we start by:

  • picking a language
  • creating a QL pack in the repo
  • downloading a database to the extension storage

For this original flow we:

  • still download the database to the extension storage
  • we're now creating the QL pack in the repo

Bonus: For both flows we're not pushing the QL pack as a top folder
so it won't show up twice if you use the skeleton wizard flow, as Shati
discovered.

So that we can re-use it in the QLPackGenerator.
In the original flow for creating skeleton packs, we were starting out
by choosing a database (e.g. github/codeql) and having the extension
create the QL pack for us.

At that point, we were storing the QL pack together with the database in
the extension storage because we weren't interested in committing it to
the repo.

This means we weren't able to see it in the file explorer so in order to
make it visible, we decided to push it as a top-level folder in the
workspace.

Hindsight is 20/20.

Let's change this original flow by just creating the folder in the
workspace storage instead of the extension storage (which will make it
visible in the file explorer) and stop pushing it as an extra top level
folder in the workspace.

NB: For this flow, we exit early in the `createSkeletonPacks` method if
the folder already exists so we don't need to check this again.
@elenatanasoiu elenatanasoiu requested a review from a team as a code owner April 13, 2023 09:34
@elenatanasoiu elenatanasoiu requested a review from a team April 13, 2023 09:44
Comment thread extensions/ql-vscode/src/helpers.ts Outdated
Comment thread extensions/ql-vscode/src/helpers.ts Outdated
Copy link
Copy Markdown
Contributor

@shati-patel shati-patel 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! Though I think there's still some confusion around naming (left comments inline). Let me know if they don't make sense! 🙃

💭 Rough overview of my understanding of the 3 kinds of "storage":

  1. The folders that you have open in your workspace (shown in the sidebar)
  2. A folder generated/managed by the extension, which stores databases and general "state" about a particular workspace. There's a different folder per workspace.
    • This is what we typically call "workspace storage".
    • Looks something like User\workspaceStorage\e261f5bb3c3fc94ac91b18302744f6ad\GitHub.vscode-codeql\...
  3. A folder generated/managed by the extension, which stores the CodeQL CLI executable and various other "global" things.
    • This is what we typically call "global storage".
    • Looks something like User\globalStorage\github.vscode-codeql\...

This PR is about adding QL packs to 1, rather than 2, which is why "workspace storage" is a slightly confusing name! 🗳️

Comment thread extensions/ql-vscode/src/helpers.ts Outdated
Comment thread extensions/ql-vscode/src/local-databases.ts Outdated
@elenatanasoiu elenatanasoiu force-pushed the yer-a-workspace-query branch from c8d6611 to dbcbaa5 Compare April 13, 2023 14:49
@elenatanasoiu elenatanasoiu force-pushed the yer-a-workspace-query branch from dbcbaa5 to 669c724 Compare April 13, 2023 14:59
Copy link
Copy Markdown
Contributor

@shati-patel shati-patel left a comment

Choose a reason for hiding this comment

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

Cool! 😎 Just a note from testing: now that we no longer add codeql-custom-queries-xxx as a top-level folder, we get into a clash with the previous "skeleton pack generator" ☠️ 😄

E.g. When running Create Query in the codespaces-codeql repo, it successfully creates codeql-custom-queries-xxx as a subfolder of my first workspace folder, and then adds a database.
After the database gets added, I get the message

We've noticed you don't have a CodeQL pack available to analyze this database. Can we set up a query pack for you?

which would try to create another pack.

Can we turn off this prompt, or change isFolderAlreadyInWorkspace to also check for subfolders?

@elenatanasoiu elenatanasoiu force-pushed the yer-a-workspace-query branch from 669c724 to b6eaf93 Compare April 13, 2023 15:58
@elenatanasoiu
Copy link
Copy Markdown
Contributor Author

elenatanasoiu commented Apr 13, 2023

E.g. When running Create Query in the codespaces-codeql repo, it successfully creates codeql-custom-queries-xxx as a subfolder of my first workspace folder, and then adds a database.
After the database gets added, I get the message

We've noticed you don't have a CodeQL pack available to analyze this database. Can we set up a query pack for you?
which would try to create another pack.

That's weird. When I tested this I didn't get that behaviour. This line should stop it from trying to generate again. 🤔

I'll do some more testing on this. Thanks!

@elenatanasoiu
Copy link
Copy Markdown
Contributor Author

Oh I see what you mean by subfolders 👍

@adityasharad
Copy link
Copy Markdown
Contributor

Are you planning to make the choice of workspace folder configurable in future, or unconditionally create the pack within the first workspace folder?

Comment thread extensions/ql-vscode/src/helpers.ts Outdated
@elenatanasoiu
Copy link
Copy Markdown
Contributor Author

Are you planning to make the choice of workspace folder configurable in future, or unconditionally create the pack within the first workspace folder?

@adityasharad Not at the moment. The main target is people that are using the Codespace template. Once we get to implementing the new Queries panel in the extension, we can revisit. Do you think it's something we should consider earlier?

@adityasharad
Copy link
Copy Markdown
Contributor

Are you planning to make the choice of workspace folder configurable in future, or unconditionally create the pack within the first workspace folder?

@adityasharad Not at the moment. The main target is people that are using the Codespace template. Once we get to implementing the new Queries panel in the extension, we can revisit. Do you think it's something we should consider earlier?

In an arbitrary workspace I would find it somewhat confusing as a user to have a new pack quietly written to my first workspace folder; for the Codespaces template we have more control and know exactly what the first folder is so it makes sense. Should not hold up this PR, but I think it's worth considering a follow-up of having the unconditional first-folder insertion only in the template workspace, and a user choice of folder in other workspaces.

When running Create Query in the codespaces-codeql repo, it successfully
creates codeql-custom-queries-xxx as a subfolder of the first workspace
folder, and then adds a database.  After the database gets added, we get
prompted with this message:

```
We've noticed you don't have a CodeQL pack available to analyze this
database. Can we set up a query pack for you?
```

which would try to create another QL pack.

Since we're no longer pushing QL packs as top level folders in the
workspace when we use the new "Create Query" flow, we also need to adapt
the original flow to take into account subfolders.

Just as a reminder, the original flow is:
- Be in the codespace template
- Download a database from GitHub
- The extension will offer to create a QL pack for the database

The new flow:
- Run the "Create Query" command
- Choose a language
- Create a QL pack
- Download a database for it

In the new flow the last step of downloading a database would trigger
the extension to offer to create a QL pack.

Let's fix this by detecting subfolders as well and exiting early.
We've made an exception to fetch the parent folder when we're
in the vscode-codeql-starter workspace.

We'd like to make this more specific so that it doesn't interfere
with other repos.
@elenatanasoiu
Copy link
Copy Markdown
Contributor Author

Thanks for your input everyone! This PR is ready for review again.

I have some time to look into being able to configure the workspace folder. Discussed this with Shati, we want to prompt non-codespace users for a workspace folder and then save it as config.

Copy link
Copy Markdown
Contributor

@shati-patel shati-patel left a comment

Choose a reason for hiding this comment

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

One more comment from me 😎

(I haven't got round to testing the "Don't offer to create skeleton pack again" change yet, though the code looks good 💻 )

Comment thread extensions/ql-vscode/src/helpers.ts Outdated
// For the vscode-codeql-starter repo, the first folder will be a ql pack
// so we need to get the parent folder
if (
firstFolderFsPath.includes("vscode-codeql-starter/codeql-custom-queries")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This might need to use platform-specific separators, e.g. with path.join or path.sep 🪟

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks Shati! You'd think I would've learned my lesson by now!

The separator character is different on Windows.
@elenatanasoiu elenatanasoiu force-pushed the yer-a-workspace-query branch from b9e734a to 70d533f Compare April 14, 2023 12:31
Copy link
Copy Markdown
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

Nice

@elenatanasoiu
Copy link
Copy Markdown
Contributor Author

Thanks @aeisenberg !

@elenatanasoiu elenatanasoiu merged commit 9b647ff into main Apr 14, 2023
@elenatanasoiu elenatanasoiu deleted the yer-a-workspace-query branch April 14, 2023 20:24
elenatanasoiu added a commit that referenced this pull request Apr 17, 2023
Offer non-codespace users the option to configure their storage folder for skeleton packs.

Suggested here:
#2310 (comment)

At the moment we're choosing to create our skeleton packs in the first
folder in the workspace.

This is fine for the codespace template because we can control the
folder structure in that repo.

For users outside of this we'd like to offer them the option to choose
where to save their skeleton packs.
elenatanasoiu added a commit that referenced this pull request Apr 17, 2023
Offer non-codespace users the option to configure their storage folder for skeleton packs.

Suggested here:
#2310 (comment)

At the moment we're choosing to create our skeleton packs in the first
folder in the workspace.

This is fine for the codespace template because we can control the
folder structure in that repo.

For users outside of this we'd like to offer them the option to choose
where to save their skeleton packs.
elenatanasoiu added a commit that referenced this pull request Apr 17, 2023
Offer non-codespace users the option to configure their storage folder for skeleton packs.

Suggested here:
#2310 (comment)

At the moment we're choosing to create our skeleton packs in the first
folder in the workspace.

This is fine for the codespace template because we can control the
folder structure in that repo.

For users outside of this we'd like to offer them the option to choose
where to save their skeleton packs.
elenatanasoiu added a commit that referenced this pull request Apr 17, 2023
Offer non-codespace users the option to configure their storage folder for skeleton packs.

Suggested here:
#2310 (comment)

At the moment we're choosing to create our skeleton packs in the first
folder in the workspace.

This is fine for the codespace template because we can control the
folder structure in that repo.

For users outside of this we'd like to offer them the option to choose
where to save their skeleton packs.
elenatanasoiu added a commit that referenced this pull request Apr 18, 2023
Offer non-codespace users the option to configure their storage folder for skeleton packs.

Suggested here:
#2310 (comment)

At the moment we're choosing to create our skeleton packs in the first
folder in the workspace.

This is fine for the codespace template because we can control the
folder structure in that repo.

For users outside of this we'd like to offer them the option to choose
where to save their skeleton packs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants