diff --git a/CHANGELOG.md b/CHANGELOG.md index cdb3832..7feee0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Added + +* Added standard template definitions for autocompletion. ### Added diff --git a/src/editor-service.ts b/src/editor-service.ts index 0e3b054..840f25a 100644 --- a/src/editor-service.ts +++ b/src/editor-service.ts @@ -18,10 +18,14 @@ export type TypeaheadCompletion = ElementCompletion | AttributesCompletion | AttributeValuesCompletion; export interface ElementCompletion { kind: 'element-tags'; - elements: { - tagname: string, - description: string, expandTo?: string, expandToSnippet?: string - }[]; + elements: ElementSnippet[]; +} +export interface ElementSnippet { + tagname: string; + description: string; + expandTo?: string; + expandToSnippet?: string; + prefix?: string; } export interface AttributesCompletion { kind: 'attributes'; diff --git a/src/local-editor-service.ts b/src/local-editor-service.ts index d154b7c..f7d582c 100644 --- a/src/local-editor-service.ts +++ b/src/local-editor-service.ts @@ -21,6 +21,8 @@ import {Warning, WarningCarryingException} from 'polymer-analyzer/lib/warning/wa import {getLocationInfoForPosition, isPositionInsideRange} from './ast-from-source-position'; import {AttributeCompletion, EditorService, SourcePosition, TypeaheadCompletion} from './editor-service'; +import {snippets} from './snippets'; + export class LocalEditorService extends EditorService { private _analyzer: Analyzer; constructor(options: AnalyzerOptions) { @@ -85,7 +87,7 @@ export class LocalEditorService extends EditorService { Array.from(document.getByKind('element')).filter(e => e.tagName); return { kind: 'element-tags', - elements: elements.map(e => { + elements: snippets.concat(elements.map(e => { const attributesSpace = e.attributes.length > 0 ? ' ' : ''; return { tagname: e.tagName!, @@ -97,7 +99,7 @@ export class LocalEditorService extends EditorService { this._generateAutoCompletionForElement(e) : undefined }; - }) + })) }; } diff --git a/src/snippets.ts b/src/snippets.ts new file mode 100644 index 0000000..473d9e6 --- /dev/null +++ b/src/snippets.ts @@ -0,0 +1,48 @@ +import {ElementSnippet} from './editor-service'; + +const snippets: ElementSnippet[] = [ + { + 'tagname': 'html-import', + 'description': 'Template definition of an HTML import.', + 'prefix': 'hi', + 'expandTo': '', + 'expandToSnippet': '' + }, + { + 'tagname': 'tdd-test', + 'description': 'Template definition for a TDD test suite', + 'prefix': 'tdd-test', + 'expandTo': '', + 'expandToSnippet': ` + +
+ +