mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
add a command to setup a workspace
This commit is contained in:
@ -9,16 +9,9 @@ This extension implements an in-memory file system to show-case the [filesytem p
|
||||
To *get started* you need this:
|
||||
|
||||
* install this extension
|
||||
* have a workspace-file as shown below and open it via 'File > Open Workspace'
|
||||
* when *not* having a workspace opened, select 'F1 > [MemFS] Setup Workspace' (optionally save the workspace now)
|
||||
* select 'F1 > [MemFs] Create Files' and notice how the explorer is now populated
|
||||
* ... try things out, e.g. IntelliSense in memfs-files, create new files, save them, etc
|
||||
* select 'F1 > [MemFs] Delete Files' or reload to restart
|
||||
|
||||
A sample workspace file, saved as `Test.code-workspace`, is this:
|
||||
|
||||
```json
|
||||
{
|
||||
"uri": "memfs:/",
|
||||
"name": "MemFS"
|
||||
}
|
||||
```
|
||||

|
||||
|
||||
@ -15,11 +15,19 @@
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onFileSystem:memfs"
|
||||
"onFileSystem:memfs",
|
||||
"onCommand:memfs.workspaceInit",
|
||||
"onCommand:memfs.init",
|
||||
"onCommand:memfs.reset"
|
||||
],
|
||||
"main": "./out/src/extension",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "memfs.workspaceInit",
|
||||
"title": "Setup Workspace",
|
||||
"category": "MemFS"
|
||||
},
|
||||
{
|
||||
"command": "memfs.init",
|
||||
"title": "Create Files",
|
||||
@ -30,7 +38,23 @@
|
||||
"title": "Delete Files",
|
||||
"category": "MemFS"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menus": {
|
||||
"commandPalette": [
|
||||
{
|
||||
"command": "memfs.init",
|
||||
"when": "workbenchState == workspace"
|
||||
},
|
||||
{
|
||||
"command": "memfs.reset",
|
||||
"when": "workbenchState == workspace"
|
||||
},
|
||||
{
|
||||
"command": "memfs.workspaceInit",
|
||||
"when": "workbenchState != workspace"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
|
||||
BIN
fsprovider-sample/sample.png
Normal file
BIN
fsprovider-sample/sample.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 109 KiB |
@ -6,6 +6,8 @@ import { MemFS } from './fileSystemProvider';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
console.log('MemFS says "Hello"')
|
||||
|
||||
const memFs = new MemFS();
|
||||
context.subscriptions.push(vscode.workspace.registerFileSystemProvider('memfs', memFs, { isCaseSensitive: true }));
|
||||
let initialized = false;
|
||||
@ -52,6 +54,10 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
memFs.writeFile(vscode.Uri.parse(`memfs:/xyz/def/foo.md`), Buffer.from('*MemFS*'), { create: true, overwrite: true });
|
||||
memFs.writeFile(vscode.Uri.parse(`memfs:/xyz/def/foo.bin`), Buffer.from([0, 0, 0, 1, 7, 0, 0, 1, 1]), { create: true, overwrite: true });
|
||||
}));
|
||||
|
||||
context.subscriptions.push(vscode.commands.registerCommand('memfs.workspaceInit', _ => {
|
||||
vscode.workspace.updateWorkspaceFolders(0, 0, { uri: vscode.Uri.parse('memfs:/'), name: "MemFS - Sample" });
|
||||
}));
|
||||
}
|
||||
|
||||
function randomData(lineCnt: number, lineLen = 155): Buffer {
|
||||
|
||||
Reference in New Issue
Block a user