diff --git a/CHANGELOG.md b/CHANGELOG.md index 65364f9..0df5653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,34 @@ +# 3.0.6 + +- Avoid check and show context snippets in pum. + +# 3.0.5 + +- Fix `snippets.editSnippets` not contains global snippet files. +- Fix snipmate viml interpolation not work. + +# 3.0.4 + +- Register snippets.editSnippets when ultisnips enabled. +- Fix same directory check on case insensive system. + +# 3.0.3 + +- Fix trigger kind for regex snippet. + +# 3.0.2 + +- Add command `snippets.openOutput`. + +# 3.0.1 + +- Fix languageIds of textmate snippets. +- Fix bad params for resolveSnippet. + +# 3.0.0 + +- Not parse ultisnip snippets. + # 2.5.2 - Fix escape for `$` in ultisnip body. diff --git a/package.json b/package.json index de4265a..e419f43 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-snippets", - "version": "3.0.5", + "version": "3.0.6", "description": "Snippets extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm", diff --git a/src/baseProvider.ts b/src/baseProvider.ts index 5cac9db..ebe8d08 100644 --- a/src/baseProvider.ts +++ b/src/baseProvider.ts @@ -8,7 +8,7 @@ export default abstract class BaseProvider { } public abstract init(): Promise - public abstract getSnippets(filetype: string): Promise + public abstract getSnippets(filetype: string): Snippet[] public abstract getSnippetFiles(filetype: string): Promise public abstract getTriggerSnippets(document: Document, position: Position, autoTrigger?: boolean): Promise public resolveSnippetBody?(snippet: string): Promise diff --git a/src/list/snippet.ts b/src/list/snippet.ts index 0a518f3..ca4be71 100644 --- a/src/list/snippet.ts +++ b/src/list/snippet.ts @@ -21,7 +21,7 @@ export default class SnippetsList extends BasicList { let buf = await window.buffer let doc = workspace.getDocument(buf.id) if (!doc) return [] - let snippets = await this.manager.getSnippets(doc.filetype) + let snippets = this.manager.getSnippets(doc.filetype) let res: ListItem[] = [] for (let snip of snippets) { let pos: Position = Position.create(snip.lnum, 0) diff --git a/src/provider.ts b/src/provider.ts index 58f60d4..029e107 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -36,13 +36,13 @@ export class ProviderManager implements CompletionItemProvider { }) } - public async getSnippets(filetype: string): Promise { + public getSnippets(filetype: string): Snippet[] { let names = Array.from(this.providers.keys()) let list: Snippet[] = [] for (let name of names) { let provider = this.providers.get(name) try { - let snippets = await provider.getSnippets(filetype) + let snippets = provider.getSnippets(filetype) snippets.map(s => s.provider = name) list.push(...snippets) } catch (e) { @@ -116,31 +116,17 @@ export class ProviderManager implements CompletionItemProvider { context: VimCompletionContext): Promise { let doc = workspace.getDocument(document.uri) if (!doc) return [] - let snippets = await this.getSnippets(doc.filetype) + let snippets = this.getSnippets(doc.filetype) let currline = doc.getline(position.line, true) - let { input, col } = context.option - let character = characterIndex(currline, col) + let { input, col, line } = context.option + let character = characterIndex(line, col) let before_content = currline.slice(0, character) let res: CompletionItem[] = [] - let contextPrefixes: string[] = [] for (let snip of snippets) { + if (snip.context || snip.prefix === '') continue + if (input.length == 0 && !before_content.endsWith(snip.prefix)) continue let contentBehind = before_content - if (contextPrefixes.indexOf(snip.prefix) !== -1) continue - if (snip.regex != null && snip.prefix == '') continue - if (snip.context) { - let provider = this.providers.get(snip.provider) - let valid: boolean - try { - valid = await provider.checkContext(snip.context) - } catch (e) { - this.appendError(`checkContext of ${snip.provider}`, e) - valid = false - } - if (!valid) continue - contextPrefixes.push(snip.prefix) - } let head = this.getPrefixHead(doc, snip.prefix) - if (input.length == 0 && !before_content.endsWith(snip.prefix)) continue let ultisnip = snip.provider == 'ultisnips' || snip.provider == 'snipmate' let item: CompletionItem = { label: snip.prefix, diff --git a/src/snipmateProvider.ts b/src/snipmateProvider.ts index bf2944f..1c3ec75 100644 --- a/src/snipmateProvider.ts +++ b/src/snipmateProvider.ts @@ -183,7 +183,7 @@ export class SnipmateProvider extends BaseProvider { public async getTriggerSnippets(document: Document, position: Position, autoTrigger: boolean): Promise { if (autoTrigger) return [] - let snippets = await this.getSnippets(document.filetype) + let snippets = this.getSnippets(document.filetype) let line = document.getline(position.line) line = line.slice(0, position.character) if (!line || line[line.length - 1] == ' ') return [] @@ -221,7 +221,7 @@ export class SnipmateProvider extends BaseProvider { return res } - public async getSnippets(filetype: string): Promise { + public getSnippets(filetype: string): Snippet[] { let filetypes: string[] = this.getFiletypes(filetype) filetypes.push('_') let snippetFiles = this.snippetFiles.filter(o => filetypes.includes(o.filetype)) diff --git a/src/textmateProvider.ts b/src/textmateProvider.ts index 284eef8..8ed7c30 100644 --- a/src/textmateProvider.ts +++ b/src/textmateProvider.ts @@ -171,7 +171,7 @@ export class TextmateProvider extends BaseProvider { return edits } - public async getSnippets(filetype: string): Promise { + public getSnippets(filetype: string): Snippet[] { let res: Snippet[] = [] let filetypes: string[] = this.getFiletypes(filetype) filetypes.push('all') diff --git a/src/ultisnipsProvider.ts b/src/ultisnipsProvider.ts index 94f060a..62802cb 100644 --- a/src/ultisnipsProvider.ts +++ b/src/ultisnipsProvider.ts @@ -182,7 +182,7 @@ export class UltiSnippetsProvider extends BaseProvider { } public async getTriggerSnippets(document: Document, position: Position, autoTrigger?: boolean): Promise { - let snippets = await this.getSnippets(document.filetype) + let snippets = this.getSnippets(document.filetype) let line = document.getline(position.line) line = line.slice(0, position.character) if (!line || line[line.length - 1] == ' ') return [] @@ -252,7 +252,7 @@ export class UltiSnippetsProvider extends BaseProvider { return res } - public async getSnippets(filetype: string): Promise { + public getSnippets(filetype: string): Snippet[] { let filetypes = this.getFiletypes(filetype) filetypes.push('all') let snippetFiles = this.snippetFiles.filter(o => filetypes.indexOf(o.filetype) !== -1)