-
Notifications
You must be signed in to change notification settings - Fork 12
Add back support for unencoded folder/workspace query params #15
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,6 +37,16 @@ function doCreateUri(path: string, queryValues: Map<string, string>): URI { | |||||
return URI.parse(window.location.href).with({ path, query }); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Encode a path for opening via the folder or workspace query parameter. This | ||||||
* preserves slashes so it can be edited by hand more easily. | ||||||
* | ||||||
* @author coder | ||||||
*/ | ||||||
export const encodePath = (path: string): string => { | ||||||
return path.split('/').map((p) => encodeURIComponent(p)).join('/'); | ||||||
}; | ||||||
|
||||||
interface ICredential { | ||||||
service: string; | ||||||
account: string; | ||||||
|
@@ -319,13 +329,27 @@ class WorkspaceProvider implements IWorkspaceProvider { | |||||
} | ||||||
|
||||||
// Folder | ||||||
/** | ||||||
* Modified to print as a human-readable string for file paths. | ||||||
* @author coder | ||||||
*/ | ||||||
else if (isFolderToOpen(workspace)) { | ||||||
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_FOLDER}=${encodeURIComponent(workspace.folderUri.toString())}`; | ||||||
const target = workspace.folderUri.scheme === Schemas.vscodeRemote | ||||||
? encodePath(workspace.folderUri.path) | ||||||
: encodeURIComponent(workspace.folderUri.toString()); | ||||||
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_FOLDER}=${target}`; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this interpolation be replaced with a URL constructor? Something like: const url = new URL(window.location.pathname, window.location.origin);
url.searchParams.set(
WorkspaceProvider.QUERY_PARAM_FOLDER,
workspace.folderUri.scheme === Schemas.vscodeRemote
? encodePath(workspace.folderUri.path)
: encodeURIComponent(workspace.folderUri.toString())); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it would work but I wanted to avoid modifying the original logic as much as possible. |
||||||
} | ||||||
|
||||||
// Workspace | ||||||
/** | ||||||
* Modified to print as a human-readable string for file paths. | ||||||
* @author coder | ||||||
*/ | ||||||
else if (isWorkspaceToOpen(workspace)) { | ||||||
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_WORKSPACE}=${encodeURIComponent(workspace.workspaceUri.toString())}`; | ||||||
const target = workspace.workspaceUri.scheme === Schemas.vscodeRemote | ||||||
? encodePath(workspace.workspaceUri.path) | ||||||
: encodeURIComponent(workspace.workspaceUri.toString()); | ||||||
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_WORKSPACE}=${target}`; | ||||||
Comment on lines
+349
to
+352
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Just thinking out loud to make sure I understand this change. In these two Is that right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In VS Code the Yup, you got it right! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh just means it's on the remote side, got it. Thank you! |
||||||
} | ||||||
|
||||||
// Append payload if any | ||||||
|
@@ -423,18 +447,42 @@ class WindowIndicator implements IWindowIndicator { | |||||
let payload = Object.create(null); | ||||||
let logLevel: string | undefined = undefined; | ||||||
|
||||||
/** | ||||||
* If the value begins with a slash assume it is a file path and convert it to | ||||||
* use the vscode-remote scheme. | ||||||
* | ||||||
* @author coder | ||||||
*/ | ||||||
const toRemote = (value: string): string => { | ||||||
if (value.startsWith("/")) { | ||||||
return "vscode-remote://" + value; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: modernize 😛
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like? import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
return URI.from({
scheme: Schemas.vscodeRemote,
authority: '/foo/bar/baz’
}).toString(true /* skip encoding */)
// => vscode-remote:///foo/bar/baz There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh template strings, I like to avoid them if there is just one variable at the start or end hahaha, I guess my old-school brain finds it more readable. Good call on The change feels semantically odd, right? Since what we have is a path and not an authority. I messed around with adding it to the path but it seems to lose the double slash. It does get passed into |
||||||
} | ||||||
return value | ||||||
} | ||||||
|
||||||
const query = new URL(document.location.href).searchParams; | ||||||
query.forEach((value, key) => { | ||||||
switch (key) { | ||||||
|
||||||
// Folder | ||||||
case WorkspaceProvider.QUERY_PARAM_FOLDER: | ||||||
/** | ||||||
* Handle URIs that we previously left unencoded and de-schemed. | ||||||
* | ||||||
* @author coder | ||||||
*/ | ||||||
value = toRemote(value); | ||||||
workspace = { folderUri: URI.parse(value) }; | ||||||
foundWorkspace = true; | ||||||
break; | ||||||
|
||||||
// Workspace | ||||||
case WorkspaceProvider.QUERY_PARAM_WORKSPACE: | ||||||
/** | ||||||
* Handle URIs that we previously left unencoded and de-schemed. | ||||||
* | ||||||
* @author coder | ||||||
*/ | ||||||
value = toRemote(value); | ||||||
workspace = { workspaceUri: URI.parse(value) }; | ||||||
foundWorkspace = true; | ||||||
break; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the advantage to doing it this way?