Skip to content

Commit

Permalink
Release 3.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Mar 28, 2022
1 parent 3bf463f commit b0ab744
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 29 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/baseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default abstract class BaseProvider {
}

public abstract init(): Promise<void>
public abstract getSnippets(filetype: string): Promise<Snippet[]>
public abstract getSnippets(filetype: string): Snippet[]
public abstract getSnippetFiles(filetype: string): Promise<string[]>
public abstract getTriggerSnippets(document: Document, position: Position, autoTrigger?: boolean): Promise<SnippetEdit[]>
public resolveSnippetBody?(snippet: string): Promise<string>
Expand Down
2 changes: 1 addition & 1 deletion src/list/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 7 additions & 21 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export class ProviderManager implements CompletionItemProvider {
})
}

public async getSnippets(filetype: string): Promise<Snippet[]> {
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) {
Expand Down Expand Up @@ -116,31 +116,17 @@ export class ProviderManager implements CompletionItemProvider {
context: VimCompletionContext): Promise<CompletionItem[]> {
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,
Expand Down
4 changes: 2 additions & 2 deletions src/snipmateProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class SnipmateProvider extends BaseProvider {

public async getTriggerSnippets(document: Document, position: Position, autoTrigger: boolean): Promise<SnippetEdit[]> {
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 []
Expand Down Expand Up @@ -221,7 +221,7 @@ export class SnipmateProvider extends BaseProvider {
return res
}

public async getSnippets(filetype: string): Promise<Snippet[]> {
public getSnippets(filetype: string): Snippet[] {
let filetypes: string[] = this.getFiletypes(filetype)
filetypes.push('_')
let snippetFiles = this.snippetFiles.filter(o => filetypes.includes(o.filetype))
Expand Down
2 changes: 1 addition & 1 deletion src/textmateProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class TextmateProvider extends BaseProvider {
return edits
}

public async getSnippets(filetype: string): Promise<Snippet[]> {
public getSnippets(filetype: string): Snippet[] {
let res: Snippet[] = []
let filetypes: string[] = this.getFiletypes(filetype)
filetypes.push('all')
Expand Down
4 changes: 2 additions & 2 deletions src/ultisnipsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class UltiSnippetsProvider extends BaseProvider {
}

public async getTriggerSnippets(document: Document, position: Position, autoTrigger?: boolean): Promise<SnippetEdit[]> {
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 []
Expand Down Expand Up @@ -252,7 +252,7 @@ export class UltiSnippetsProvider extends BaseProvider {
return res
}

public async getSnippets(filetype: string): Promise<Snippet[]> {
public getSnippets(filetype: string): Snippet[] {
let filetypes = this.getFiletypes(filetype)
filetypes.push('all')
let snippetFiles = this.snippetFiles.filter(o => filetypes.indexOf(o.filetype) !== -1)
Expand Down

0 comments on commit b0ab744

Please sign in to comment.