Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: proposed API for multi root folder changes #42195

Closed
3 tasks done
bpasero opened this issue Jan 26, 2018 · 7 comments
Closed
3 tasks done

Test: proposed API for multi root folder changes #42195

bpasero opened this issue Jan 26, 2018 · 7 comments

Comments

@bpasero
Copy link
Member

bpasero commented Jan 26, 2018

Refs: #35407

Complexity: 3

There is new proposed API (updateWorkspaceFolders(start: number, deleteCount: number, ...workspaceFoldersToAdd: { uri: Uri, name?: string }[]): boolean) to update the workspace folders of the workspace from an extension. The API provides full control over:

  • removing existing folders
  • adding new folders
  • doing both at the same time (this allows to e.g. move an existing folder to another index)

Verify:

  • the JSDoc of this method allows you to understand what the method is doing
  • you see a little status message when a folder is added or removed with the name of the extension
  • changes are always reflected without a window reload and the extension host continues to work (note that some transitions still require the extension host to restart, e.g. when the first folder changes)
  • test with empty workspace, single folder workspace and multi-root workspace
  • test adding folder(s), removing folder(s), and changing folders (e.g. rename a folder name or swapping folders position)

FYI - to test against the latest API do the following:

  • open your extensions package.json file
  • change the engine.vscode property to *
  • run npm run postinstall (assuming you have the vscode module as dev-dependency)
  • undo the engine-version change from step 2
  • run with --enable-proposed-api
  • copy the updateWorkspaceFolders method from vscode.proposed.d.ts into vscode.d.ts of the vscode node_module
@chrmarti
Copy link
Collaborator

@bpasero You still need to copy the vscode.proposed.d.ts, don't you?

@bpasero
Copy link
Member Author

bpasero commented Jan 30, 2018

@chrmarti yeah thats right!

octref added a commit that referenced this issue Jan 31, 2018
@octref
Copy link
Contributor

octref commented Jan 31, 2018

I was able to use updateWorkspaceFolders to remove one folder, but onDidChangeWorkspaceFolders did not fire. Wondering if I'm doing something wrong...

Code is

import * as vscode from 'vscode';

export const activate = (context: vscode.ExtensionContext) => {
  vscode.workspace.onDidChangeWorkspaceFolders((e) => {
    console.log(e.added.length) // never executed
    console.log(e.removed.length)
  })

  vscode.commands.registerCommand('extension.helloWorld', () => {
    vscode.workspace.updateWorkspaceFolders(0, 1) // this did remove one folder
  })
};

@bpasero Any ideas?

Also instead of --enable-proposed-api , it should be adding "enableProposedApi": true to package.json, right?

@bpasero
Copy link
Member Author

bpasero commented Jan 31, 2018

@octref if do any change that modifies the first folder in the list, the extension host will restart so you will not be able to get any event.

@chrmarti
Copy link
Collaborator

I can't get --enable-proposed-api to work on Linux. I tried adding it when starting the host and in the launch config. I'm now using "enableProposedApi": true in the package.json, that works. Any idea what I did wrong with the command line parameter?

@bpasero
Copy link
Member Author

bpasero commented Jan 31, 2018

@jrieken might know

@jrieken
Copy link
Member

jrieken commented Jan 31, 2018

The flag needs the extension id and I do believe the property in package.json is almost always required

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants