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

Adding ability to parse an abbreviation and then expanding it. #22

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/emmetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


import { TextDocument, Position, Range, CompletionItem, CompletionList, TextEdit, InsertTextFormat, CompletionItemKind } from 'vscode-languageserver-types'
import { expand, createSnippetsRegistry } from './expand/expand-full';
import { expand, createSnippetsRegistry, parse } from './expand/expand-full';
import * as extract from '@emmetio/extract-abbreviation';
import * as path from 'path';
import * as fs from 'fs';
Expand Down Expand Up @@ -626,17 +626,20 @@ function applyVendorPrefixes(expandedProperty: string, vendors: string, preferen
return prefixedProperty + expandedProperty;
}

export function parseAbbreviation(abbreviation: string, options: ExpandOptions): any {
return parse(abbreviation, options);
}

/**
* Expands given abbreviation using given options
* @param abbreviation string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be adjusted, doesn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean formatted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the type isn't string anymore.

Copy link
Contributor Author

@gushuro gushuro Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: I was looking at the wrong place. You're right, we set the parameter to any and line 635 should reflect that.

The parse function in the expand module is expecting an abbreviation of type string.
The idea is that, having an abbreviation that is a string, you can either:

  • Expand it as usual, or
  • Parse it into a tree structure with this method, then read/modify it, and finally expand it

* @param options
*/
export function expandAbbreviation(abbreviation: string, options: ExpandOptions): string {
export function expandAbbreviation(abbreviation: any, options: ExpandOptions): string {
let expandedText;
let preferences = options['preferences'];
delete options['preferences'];
if (isStyleSheet(options['syntax'])) {
if (isStyleSheet(options['syntax']) && typeof abbreviation === 'string') {
let { prefixOptions, abbreviationWithoutPrefix } = splitVendorPrefix(abbreviation);
expandedText = expand(abbreviationWithoutPrefix, options);
expandedText = applyVendorPrefixes(expandedText, prefixOptions, preferences);
Expand Down