-
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
Add back support for unencoded folder/workspace query params #15
Conversation
a253181
to
ef8f1c6
Compare
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.
LGTM! Left a couple comments but all none-blocking
@@ -319,13 +329,21 @@ class WorkspaceProvider implements IWorkspaceProvider { | |||
} | |||
|
|||
// Folder | |||
// NOTE@coder: Modified to print as a human-readable string for file paths. |
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.
Nice comment 👏
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.
// NOTE@coder: Modified to print as a human-readable string for file paths. | |
/** @coder Modified to print as a human-readable string for file paths. */ |
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.
I can standardize on that if we want. I lean toward TODO, NOTE, etc because my editor highlights it so it stands out.
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.
Maybe I need to add highlighting for jsdoc tags.
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.
nvm I do have highlighting but my editor is not recognizing @coder
as a valid tag name.
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.
Maybe I can do multi-line and use @author coder
.
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.
I'm down for @author
and also standardizing!
// convert it to use the vscode-remote scheme. | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
nit: modernize 😛
return "vscode-remote://" + value; | |
return `vscode-remote://${value}; |
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.
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 comment
The 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 Schemas.vscodeRemote
. I completely forgot to replace the hard-coded string with that.
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 URI.parse
so we should still get all the same validation that way.
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}`; |
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.
🤔 Just thinking out loud to make sure I understand this change. In these two if
blocks, we're modifying the targetHref
based on the workspace.folderUri.scheme
. If the scheme matches the vscodeRemote
(which I'm guessing would be localhost
with code-server?), then we use our encodePath
helper function which maintains the /
in the URI/URL so that it's easier for users to edit these by hand.
Is that right?
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.
vscodeRemote
is vscode-remote
. It is the scheme portion (file
, http
, https
, etc).
In VS Code the vscode-remote
scheme means the same thing as file
, meaning it is on disk, but on the remote side.
Yup, you got it right!
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.
Ahh just means it's on the remote side, got it. Thank you!
@@ -319,13 +329,21 @@ class WorkspaceProvider implements IWorkspaceProvider { | |||
} | |||
|
|||
// Folder | |||
// NOTE@coder: Modified to print as a human-readable string for file paths. |
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.
// NOTE@coder: Modified to print as a human-readable string for file paths. | |
/** @coder Modified to print as a human-readable string for file paths. */ |
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 comment
The 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 comment
The 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.
export const encodePath = (path: string): string => { | ||
return path.split('/').map((p) => encodeURIComponent(p)).join('/'); | ||
}; |
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
export const encodePath = (path: string): string => { | |
return path.split('/').map((p) => encodeURIComponent(p)).join('/'); | |
}; | |
export const encodeURIComponentHumanReadable = (path: string): string => { | |
// Encode everything... | |
return encodeURIComponent(path) | |
// Decode forward slashes to retain a human-readable result | |
.replaceAll(encodeURIComponent('/'), '/') |
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?
Fixes coder/code-server#4484.