Skip to content

Commit

Permalink
fix: completion bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YOYZHANG committed May 29, 2022
1 parent 5ef45ba commit 67bf7d3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/completion.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import type { CompletionItemProvider, ExtensionContext, TextDocument } from 'vscode'
import { CompletionItem, CompletionItemKind, Position, Range, languages } from 'vscode'
import { collections } from './collection'
import { Log } from './utils/Log'

// const REGEX_COLLECTION = /(?:\s|^)(:$)|(:[\w\d_+-]+?)$|(:[\w\d_+-]+:)$/
const REGEX_COLLECTION = /\:\:/
const REGEX_COLLECTION = /(\:[\w\d+_-])/
export function RegisterCompletion(ctx: ExtensionContext) {
const emojiProvider: CompletionItemProvider = {
provideCompletionItems(document: TextDocument, position: Position) {
if (position.character === 0)
return []

const line = document.getText(new Range(new Position(position.line, 0), new Position(position.line, position.character)))

const match = line.match(REGEX_COLLECTION)
Expand All @@ -18,16 +21,10 @@ export function RegisterCompletion(ctx: ExtensionContext) {
const item = new CompletionItem(`${x.emoji} :${x.name}:`, CompletionItemKind.Color)
item.filterText = `:${x.name}:`
item.insertText = `${x.emoji}`
item.range = new Range(position.translate(0, -1), position)
item.range = new Range(position.translate(0, -2), position)
return item
})
},
// async resolveCompletionItem(item: CompletionItem) {
// return {
// ...item,
// documentation: await getMarkdown(ctx, item.label as string),
// }
// },
}
ctx.subscriptions.push(
languages.registerCompletionItemProvider(
Expand All @@ -40,5 +37,10 @@ export function RegisterCompletion(ctx: ExtensionContext) {
emojiProvider,
':',
),
languages.registerCompletionItemProvider(
'git-commit',
emojiProvider,
':',
),
)
}

0 comments on commit 67bf7d3

Please sign in to comment.