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

Invalid emmet abbr returns weird expanded value in css files #27628

Closed
Tyriar opened this issue May 30, 2017 · 22 comments
Closed

Invalid emmet abbr returns weird expanded value in css files #27628

Tyriar opened this issue May 30, 2017 · 22 comments
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s) emmet Emmet related issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented May 30, 2017

  • VSCode Version: Code - Insiders 1.13.0-insider (c2a17a7, 2017-05-30T05:12:15.312Z)
  • OS Version: Linux x64 4.10.0-21-generic
  • Extensions:
Extension Author Version
EditorConfig EditorConfig 0.9.3
lorem-ipsum Tyriar 1.0.0
sort-lines Tyriar 1.3.0
theme-sapphire Tyriar 0.2.1
vscode-svgviewer cssho 1.4.1
tslint eg2 0.15.0
git-project-manager felipecaputo 1.3.2
md-navigate jrieken 0.0.1
vscode-scss mrmlnc 0.6.2
seti-icons qinjia 0.1.3

#27316

image

image

@Tyriar Tyriar added the emmet Emmet related issues label May 30, 2017
@ramya-rao-a
Copy link
Contributor

haha .foo is not a valid abbreviation to expand, and the extension should handle it better.

@ramya-rao-a ramya-rao-a changed the title Using emmet expand abbreviation in a sass file gives weird output Invalid emmet abbr returns weird expanded value in css files May 30, 2017
@ramya-rao-a ramya-rao-a added the bug Issue identified by VS Code Team member as probable bug label May 30, 2017
@ramya-rao-a ramya-rao-a modified the milestones: May 2017, June 2017 May 30, 2017
@ramya-rao-a
Copy link
Contributor

@sergeche Would you expect the plugin to parse the css file and call expand-abbreviation only if the cursor is in the "rule" part of the css file? Or is there any validation from the emmet modules that we can make use of?

@jens1o
Copy link
Contributor

jens1o commented Jun 5, 2017

Sorry to interrupt but this is valid? .class => <div class="class">|</div>

image

(such as #header => <div id="header"></div>)

https://docs.emmet.io/cheat-sheet/

@ramya-rao-a
Copy link
Contributor

@jens1o It is valid html, so yes it is valid

@jens1o
Copy link
Contributor

jens1o commented Jun 5, 2017

Then I'm sorry, but I do not understand what you're trying to say.

haha .foo is not a valid abbreviation to expand, and the extension should handle it better.

@ramya-rao-a
Copy link
Contributor

Oh I mean when taken in the context of css .foo is not a valid abbreviation
In the context of html it certainly is.

In this issue we are talking about css abbreviation

@jens1o
Copy link
Contributor

jens1o commented Jun 5, 2017

Ah, sorry, then I didn't get the subject.

@ramya-rao-a
Copy link
Contributor

Since auto-complete will get triggered for every new letter typed, either the emmet plugin should be smart enough not to try to expand .foo in the context of css or the css parser being used should not treat it as an abbreviation

@jens1o
Copy link
Contributor

jens1o commented Jun 5, 2017

But is it the css parser who should say this is a valid expression or an invalid? (like d:b; => display: block;)

I think that would overwhelm the css parser, and block other extensions. I think it should be handled by the emmet extension.

@ramya-rao-a
Copy link
Contributor

There's work to be done on both sides.

div for eg expands to display:inline-block by the css-abbreviation module because that's the nearest match it can find

But .foo clearly is an invalid CSS abbreviation and can be easily be invalidated by the css-abbreviation module.

Additionally, the extension shouldn't ask for expansion if it can beforehand figure out that the cursor is not in a "property" line

@jens1o
Copy link
Contributor

jens1o commented Jun 5, 2017

nice idea. I think I still tune to the Insiders to give you feedback.

@sergeche
Copy link

sergeche commented Jun 5, 2017

The plugin itself should implement logic whether a string can be expanded as abbreviation or not. It’s one of the reasons I’ve moved from monolithic codebase to a small, re-usable modules: to allow authors to use editor API for a better Emmet integration with editor features.

You use Atom plugin as a reference, here’s an example where I decide where abbreviation can be expanded: https://github.com/emmetio/atom-plugin/blob/master/lib/detect-syntax.js#L17-L20

@ramya-rao-a
Copy link
Contributor

@sergeche Ah the catch there is that scope info is not available to VS Code extensions :( See #580

And so I will either end up parsing the whole file to see if cursor is in a selector/rule or try to do some regex magic.

@sergeche
Copy link

sergeche commented Jun 7, 2017

@ramya-rao-a you can re-use @emmetio/html-matcher and @emmetio/css-parser to quickly parse a document. These parsers are pretty fast: on my MacBook Pro they are able to parse a 500 KB document in about 10 ms. But it’s a good idea to implement a VSCode-specific StreamReader as in Atom plugin. The goal of this reader is to use text coordinates native to editor and use editor’s content representation model. For example, Atom stores text content as lines of text so instead of spending resources on allocating memory for a whole text content and then translate text coordinates into editor ones, I simply read directly from editor in it’s coordiantes

@Fred-Vatin
Copy link

In the new emmet, would this issue solve the current one when something like c:r is expanded as color: r; instead of color: rgb(0, 0, 0); ?

@sergeche
Copy link

Can be solved by providing more value samples for c snippet: https://github.com/emmetio/snippets/blob/master/css.json#L76

@ramya-rao-a
Copy link
Contributor

@sergeche I implemented a stream reader for VS Code's TextDocument, and am currently parsing the document to avoid suggesting emmet expansions in invalid locations like inside the open tag in html or a selector in css.

But take the case of scss where you can have nested selectors. In this case, when we start typing a nested selector, the parser is not aware of whether the user is typing another property or a new selector. In this case, we end up with the below both in Atom and VS Code

screen shot 2017-06-18 at 11 29 35 pm

So even though editors try and figure out the right scope for emmet abbreviations, I believe the extract-abbreviation module can use some validation of its own based on simple regex.

@sergeche
Copy link

Yes, stubled with this issue too, will fix CSS abbreviation parser

@ramya-rao-a
Copy link
Contributor

@sergeche Can we do the same for html as well? That would solve #27975

@sergeche
Copy link

Yes. Please create a separate issue at https://github.com/emmetio/atom-plugin/issues so I can better track bugs

@ramya-rao-a
Copy link
Contributor

Thanks @sergeche !

Logged emmetio/atom-plugin#22

@ramya-rao-a ramya-rao-a added the upstream Issue identified as 'upstream' component related (exists outside of VS Code) label Jun 19, 2017
@ramya-rao-a
Copy link
Contributor

Closing this in favor of #27975

@bpasero bpasero added *duplicate Issue identified as a duplicate of another issue(s) and removed bug Issue identified by VS Code Team member as probable bug labels Jun 29, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s) emmet Emmet related issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

6 participants