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

Zen Coding not working with cshtml and razor files #14

Closed
MarkLFT opened this issue Sep 19, 2020 · 14 comments
Closed

Zen Coding not working with cshtml and razor files #14

MarkLFT opened this issue Sep 19, 2020 · 14 comments

Comments

@MarkLFT
Copy link

MarkLFT commented Sep 19, 2020

Installed product versions

  • VS2019 Professional
  • This extension: 1.2.12

Description

When using a cshtml or razor file TAB Expansion does not work.

Steps to recreate

Create either a cshtml or razor file.
Create some standard HTML markup
Enter any standard appreviation i.e div.row then press tab.

Current behavior

The cursor just tabs across the page

Expected behavior

Expand text as in a regular html page.

@TheBinaryGuy
Copy link

I'm having the same issue as well. Any luck yet?

@Hrolgar
Copy link

Hrolgar commented Dec 14, 2020

Is there any fix for this yet? I've had to go from VSCode to VS19 for work purposes. Hard to live without emmet. This extension seems like it would do the trick for me.

@TheBinaryGuy
Copy link

@Hrolgar Yes actually. In my case it was the experimental Razor editor that was causing the problem, so if you have that on, try turning it off, restart VS and see if that fixes it.

image

@Hrolgar
Copy link

Hrolgar commented Dec 14, 2020

@TheBinaryGuy that did the trick!
I can't tell you how happy I am now! Cheers man!

@TheBinaryGuy
Copy link

TheBinaryGuy commented Dec 14, 2020

@Hrolgar No worries, glad it helped. 👍

@dealdiane
Copy link

Works for me as well. What features are we missing by turning that experimental editor off?

@TheBinaryGuy
Copy link

@dealdiane I haven't looked into the new editor as much, I only occasionally use Razor nowadays. But here's a blog post from Microsoft if you want to read more about it: https://devblogs.microsoft.com/aspnet/improvements-to-the-new-razor-editor-in-visual-studio/

@aryehsilver
Copy link

aryehsilver commented Oct 12, 2021

I have it turned off already but it still doesn't work.

Edit:
I realised it was due to being inside a razor code block as in this issue #7 outside a block works as expected.

@johandanforth
Copy link

Also not working in VS2022 (Preview 7.0), even if the language server option is enabled. Seems to work for pure html files sometimes, but also krasches VS totally sometimes.

@madskristensen
Copy link
Owner

@johandanforth what file extension do you expect it to work on that it doesn't?

@johandanforth
Copy link

johandanforth commented Nov 5, 2021

Hej @madskristensen . I tried it on a .cshtml file in the ~/Views/Home/ directory of a vanilla .net 6 MVC project. Nothing happens. Also tried "tabbing" inside and outside div elements. Nothing.

Then I created a new .html file, and there it worked. I tried to enable the experimental setting for html/css language service, but there was no change. But after enabling that option, VS2022 froze and crashed when I tried a simple "div-tab" in the html-file. Actually something is not fully alright with the extension, Vs freeze/die/restart a couple of times now that I try it some more. I've just forked the code and trying to figure out what's happening with the razor pages not working.

Skärmbild 2021-11-05 225409

@johandanforth
Copy link

johandanforth commented Nov 5, 2021

@madskristensen I got a little longer. I went into tools->options->text editor->Html->Advanced and selected to "Use legacy Razor editor for ASP.NET Core" and restarted. Now ZenCoding kicks in, expands a simple "div" or whatever, but then it crashes, every time (se uploaded images). When using the "new" razor editor (whatever that is), it seems it is of another ContentType than "HTMLX", right? I don't know anything about these things really, but to create a IVsTextViewCreationListener you have to specify the ContenType for the specific kind of "page editor" with something like:

    [Export(typeof(IVsTextViewCreationListener))]
    [ContentType("HTML")]
    [ContentType("HTMLX")]
    [TextViewRole(PredefinedTextViewRoles.Document)]
    public class CommandRegistration : IVsTextViewCreationListener 
    { 
        //... and so on
    }

but the ExpandCommand in ZenCodingVS is never executing for razor pages in ASP.NET Core in VS2022.

zencoding3 - options
.
zencoding1
zencoding2

@johandanforth
Copy link

Adding the "RAZOR" content type to the CommandRegistration class got ZenCoding working, but it crashes and restarts eventually for no reason. Guess one have to look at activity logs or such, which I'm not familiar with.

namespace ZenCodingVS
{
    [Export(typeof(IVsTextViewCreationListener))]
    [ContentType("HTML")]
    [ContentType("HTMLX")]
    [ContentType("RAZOR")]
    [TextViewRole(PredefinedTextViewRoles.Document)]
    public class CommandRegistration : IVsTextViewCreationListener
    {
        [Import]
        public IVsEditorAdaptersFactoryService EditorAdaptersFactoryService { get; set; }

@johandanforth
Copy link

I ran devenv.exe with logging, and got an activity log for you @madskristensen if it may help you.
activitylog.zip

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

No branches or pull requests

7 participants