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

Support tilde character (~) in Razor links #305

Closed
rhires opened this issue Nov 20, 2015 · 4 comments
Closed

Support tilde character (~) in Razor links #305

rhires opened this issue Nov 20, 2015 · 4 comments
Assignees
Labels
feature-request Request for new features or functionality
Milestone

Comments

@rhires
Copy link

rhires commented Nov 20, 2015

Code does translate correctly the tilde ~ as a proper path reference when the code runs (but that may be mono or core-clr doing that magic, or roslyn), but when I cmd-click the link, Code offers to create a new folder in the path that literally includes the tilde as the folder name in that path, when it should convert it to the proper path of wwwroot...this is in the _Layout.cshtml file. I'm unsure where to look in the code so I can see what it's doing to offer a fix.

@egamma egamma added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Nov 23, 2015
@alexdima alexdima added the info-needed Issue requires more information from poster label Nov 30, 2015
@alexdima alexdima self-assigned this Nov 30, 2015
@alexdima
Copy link
Member

@rhires Are you Ctrl+Clicking on a "detected link" inside an HTML block?

Something like:

<a href="~/some/path/to/something.txt">

@rhires
Copy link
Author

rhires commented Nov 30, 2015

Yes, for example this item in _Layout.cshtml: <link rel="stylesheet" href="~/css/bootstrap.css" /> - even though it's properly found when I run the app (dnx web from the command line in Mac OS X) when I cmd-click, I get an offer to create the file with the tilde in it: File not found ([$PATH-to-project-root/Views/Shared/~/css/bootstrap.css) If I create the file, then I have a new folder called ~ with the rest of the path in it below.

@alexdima
Copy link
Member

Ok, I think I understand. In your _Layout.cshtml you use:

<link rel="stylesheet" href="~/css/bootstrap.css" />

~ is something Razor understands and resolves it at runtime to an actual path (possibly something that is configurable). Probably in this case at runtime it will be:

<link rel="stylesheet" href="/css/bootstrap.css" />

When you Ctrl+click on the detected link, VSCode wants to open the file but VSCode fails to understand the special meaning of ~.

@alexdima alexdima added feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Nov 30, 2015
@alexdima alexdima changed the title Tilde character + cmd click doesn't convert to wwwroot in pathname on OS X Support tilde character (~) in Razor links Nov 30, 2015
@alexdima alexdima removed their assignment Dec 8, 2015
@egamma egamma modified the milestone: Backlog Dec 10, 2015
@aeschli aeschli closed this as completed Nov 22, 2017
@aeschli aeschli reopened this Nov 22, 2017
@aeschli
Copy link
Contributor

aeschli commented Nov 22, 2017

I added code to detect the '~' and remove it. So the URL will resolve to the current workspace folder. That's IMO the best we can do as we don't know the Razor application root.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants