Inserting snippet into user's snippets fails (multi-repository workspaces)
Summary
When a user tries to add a snippet to their user snippets (rather than project snippets) the command fails.
Steps to reproduce
User tries to add a snippet to their user snippets (rather than project snippets):
- Open folder containing multiple repositories
- Open file from one of the repositories
- Trigger the
GitLab: Create snippet
command - Select
User's Snippets
in the project selection - See the command fail
Possible fixes
I added all caps comments to the following snippet from create_snippet.js
async function createSnippet() {
const editor = vscode.window.activeTextEditor;
let repositoryRoot = null;
let project = null;
if (editor) {
const repository = gitExtensionWrapper.getActiveRepository();
repositoryRoot = repository && repository.rootFsPath;
try {
project = repository && (await repository.getProject());
} catch (e) {
logError(e);
}
// FIXME: the empty `uri` representing user's snippets is not correctly handled
if (!project) {
repositoryRoot = await gitlabProjectInput.show(
[
{
label: "User's Snippets",
uri: '', // HERE WE RETURN EMPTY STRING
},
],
"Select a Gitlab Project or use the User's Snippets",
);
try {
const selectedRepository = gitExtensionWrapper.getRepository(repositoryRoot); // HERE WE EXPECT SOME VALID URL
project = selectedRepository && (await selectedRepository.getProject());
} catch (e) {
logError(e);
}
}
const visibility = await vscode.window.showQuickPick(visibilityOptions);
if (visibility) {
const context = await vscode.window.showQuickPick(contextOptions);
if (context) {
uploadSnippet(project, editor, visibility.type, context.type, repositoryRoot); // THIS FUNCTION NEEDS VALID repositoryRoot
}
}
} else {
vscode.window.showInformationMessage('GitLab Workflow: No open file.');
}
}