dawsbot / RelativePath

VSCode Relative path plugin
https://marketplace.visualstudio.com/items?itemName=jakob101.RelativePath
MIT License
69 stars 22 forks source link

Support Multi-root Workspaces #21

Closed talbenmoshe closed 6 years ago

talbenmoshe commented 6 years ago

This extension is awesome! But i'm unable to use it since I switched to the new multi-root feature in vscode.

When I'm in a certain project, I get file suggestions only from a different project in the workspace.

jakob101 commented 6 years ago

Oh! I will take a look. Thanks!


From: Tal Ben Moshe notifications@github.com Sent: Friday, November 24, 2017 8:43:56 AM To: jakob101/RelativePath Cc: Subscribed Subject: [jakob101/RelativePath] Support Multi-root Workspaces (#21)

This extension is awesome! But i'm unable to use it since I switched to the new multi-root feature in vscode.

When I'm in a certain project, I get file suggestions only from a different project in the workspace.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jakob101/RelativePath/issues/21, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AA-v2mumH8WcqBQWvTEc5FBBhiBhgEQ_ks5s5nO8gaJpZM4QpeGq.

rrag commented 6 years ago

I have used this extension and love it. the solution is described here

Looks like instead of setting this._workspacePath to rootPath in ctor

workspace.getWorkspaceFolder(window.activeTextEditor.document.uri)

should be used as the _workspacePath at https://github.com/jakob101/RelativePath/blob/master/src/extension.ts#L180

Am I in the right track? I have never worked on a vscode extension, and will be happy to PR if you can direct me to the right path

jakob101 commented 6 years ago

That’s correct! You’d make me very happy if you could propose a pr :)

Creating an extension is pretty easy - open vscode with the cloned repo and press F5. It will open a new VSCode window where you run the extension. The old one has the debugger.

Let me know if you need more pointers :)

And thanks !!! 👋🙏


From: Ragu Ramaswamy notifications@github.com Sent: Thursday, December 14, 2017 3:35:47 AM To: jakob101/RelativePath Cc: Jakob Werner; Comment Subject: Re: [jakob101/RelativePath] Support Multi-root Workspaces (#21)

I have used this extension and love it. the solution is described herehttps://github.com/Microsoft/vscode/wiki/Extension-Authoring:-Adopting-Multi-Root-Workspace-APIs#eliminating-rootpath

Looks like instead of setting this._workspacePath to rootPath in ctorhttps://github.com/jakob101/RelativePath/blob/master/src/extension.ts#L41

workspace.getWorkspaceFolder(window.activeTextEditor.document.uri)

should be used as the _workspacePath at https://github.com/jakob101/RelativePath/blob/master/src/extension.ts#L180

Am I in the right track? I have never worked on a vscode extension, and will be happy to PR if you can direct me to the right path

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jakob101/RelativePath/issues/21#issuecomment-351590718, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AA-v2hNLf_-SeSvHX9ZYQZTr5u8d-lj9ks5tAImDgaJpZM4QpeGq.

rrag commented 6 years ago

great, I got this

rrag commented 6 years ago

There is caching of all the files in the worspace. Since this cache is done on initialization in the constructor of the extension there are a few problems

  1. the same list of files are displayed everytime, the list depends on the project the command extension.relativePath is executed the first time
  2. if I open the command extension.relativePath the first time from the welcome tab and not a real file in a workspace, I would get an error

deepinscreenshot_select-area_20171217094851

        const editor = window.activeTextEditor;
        const resource = editor.document.uri;
        const folder = workspace.getWorkspaceFolder(resource)

since window.activeTextEditor will be undefined in the welcome page

I think I can solve the first problem by adding a window.onDidChangeActiveTextEditor

and comparing the prior workspace folder and the current workspace folder

if they are different do a this.updateFiles(false) else do nothing.

        window.onDidChangeActiveTextEditor((e: TextEditor) => {
            console.log("onDidChangeActiveTextEditor", e)
            const currentWorkspacePath = this.getWorkspaceFolder();
            if (this._workspacePath !== currentWorkspacePath) {
                this._workspacePath = currentWorkspacePath;
                this.updateFiles(false);
            }
        })

But for the second problem I am not sure what I can do. may be a helpful message to say that window.activeTextEditor is not there so execute the same command from a valid file,

If we go with the above info message display approach, then we can also use the same when you open up the command from a folder which is not a workspace folder also

I would like to hear your thoughts on this.

Also unrelated, I had to upgrade to latest dependencies and typescript config like

https://github.com/Microsoft/vscode-extension-samples/blob/master/basic-multi-root-sample/package.json https://github.com/Microsoft/vscode-extension-samples/blob/master/basic-multi-root-sample/tsconfig.json

as described in https://code.visualstudio.com/updates/v1_6#_extension-authoring

rrag commented 6 years ago

https://github.com/jakob101/RelativePath/pull/22

jakob101 commented 6 years ago

Sorry man, had some hectic days. Thanks for the PR, it looks good to me! You found great solutions to some issues.

rrag commented 6 years ago

Sorry for the delay, been busy with vacation time :) I will get to this this week