pranaygp / vscode-css-peek

A vscode extension for peeking at CSS definitions from a class or id tag in HTML
MIT License
146 stars 32 forks source link

Support for Pug files #22

Open nickngqs opened 6 years ago

nickngqs commented 6 years ago

Will there be support for pug files?

For example .classname #id in pug files

pranaygp commented 6 years ago

There's no planned support for pug files. Currently, this supports HTML and HTML-like languages (ejs, erb, php, etc.) out of the box without the codebase having to specifically worry about parsing different languages

However, if you're interested in contributing support for PUG, I'm happy to accept a PR :) You'll want to look at this file : https://github.com/pranaygp/vscode-css-peek/blob/43edfb62dbaa4d4a95ed2b3027ba2ad520662117/server/src/core/findSelector.ts#L17-L67 which should be the only file you'll have to change. Instead of findSelector being hardwired to parse HTML, you can do something like:


import findHTMLSelector from '...'
import findPUGSelector from '...'
...
export default function findSelector(document: TextDocument, position: Position): Selector {
  switch (document.languageId) {
    case 'pug':
      return findPUGSelector(document, position)
    ...
    default: // So that we can support html, ejs, erb, php, etc. etc. Anything that we don't explicitly support but *might* work   
      return findHTMLSelector(document, position)
  }
}
cyberbiont commented 4 years ago

I vote up for this. Don't have time to make it myself right now though