Skip to content

Commit

Permalink
Add command to create new .yarnproject files
Browse files Browse the repository at this point in the history
  • Loading branch information
desplesda committed May 24, 2024
1 parent ca2efcc commit 81998a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Updated VS Code engine from 1.63 to 1.74.
- Commands that depend on the language server being online will now only appear in the command palette if the language server has started.
- The extension will now activate when the workspace contains a .yarn or .yarnproject file, rather than waiting for a .yarn file to be opened.
- Added a command to create a new `.yarnproject` file in the workspace.

### Removed

Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@
"command": "yarnspinner.exportDebugOutput",
"category": "Yarn Spinner",
"title": "Export Debug Output",
"enablement": "config.yarnspinner.enableExperimentalFeatures"
"enablement": "config.yarnspinner.enableExperimentalFeatures && yarnspinner.languageServerLaunched"
},
{
"command": "yarnspinner.createProject",
"category": "Yarn Spinner",
"title": "Create New Yarn Project...",
"enablement": "yarnspinner.languageServerLaunched"
}
],
"configurationDefaults": {
Expand Down
30 changes: 30 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,36 @@ async function launchLanguageServer(context: vscode.ExtensionContext, configs: v
});
}));

context.subscriptions.push(vscode.commands.registerCommand("yarnspinner.createProject", async () => {
// Create a new Yarn Project.

const workspaceURI = getActiveWorkspaceUri();

let defaultDestinationURI: vscode.Uri | undefined;
if (workspaceURI) {
defaultDestinationURI = vscode.Uri.joinPath(workspaceURI, `Project.yarnproject`);
}

const destinationUri = await vscode.window.showSaveDialog({
defaultUri: defaultDestinationURI
});

if (!destinationUri) {
return;
}

const params: languageClient.ExecuteCommandParams = {
command: "yarnspinner.getEmptyYarnProjectJSON",
arguments: [ ]
};


let json = await client.sendRequest(languageClient.ExecuteCommandRequest.type, params);
fs.writeFileSync(destinationUri.fsPath, json);

vscode.commands.executeCommand('revealInExplorer', destinationUri);
}))

// Enable commands that depend upon the language server being online and the above commands being registered
vscode.commands.executeCommand('setContext', 'yarnspinner.languageServerLaunched', true);

Expand Down

0 comments on commit 81998a8

Please sign in to comment.