Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Jul 7, 2023
1 parent 7a285d5 commit 4f2c1f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
28 changes: 5 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export async function activate(context: vscode.ExtensionContext) {
if (!selectedText) {
const range = document.getWordRangeAtPosition(position) as any
let word = document.getText(range)
if (!word)
return
const line = range.c.c
const lineNumber = position.line
const lineText = document.lineAt(lineNumber).text
Expand Down Expand Up @@ -381,6 +383,8 @@ export async function activate(context: vscode.ExtensionContext) {
return

const beforeLineText = activeTextEditor.document.lineAt(beforeActivePosition.line).text
if (!beforeLineText)
return
const currentLineText = newText.split('\n')[beforeActivePosition.line]
// 光标在class之后并且当前行与新当前行发生差异时需要偏移
const match = beforeLineText.match(/(class(Name)?=")([^"]*)"/)
Expand Down Expand Up @@ -422,27 +426,7 @@ export async function activate(context: vscode.ExtensionContext) {
updateUnoStatus()
}))
}
const customMap = [
['flex-center', 'justify-center align-center'],
['pointer', 'cursor-pointer'],
['maxw', 'max-w'],
['minw', 'min-w'],
['maxh', 'max-h'],
['minh', 'min-h'],
['position-center', 'left-0 right-0 top-0 bottom-0'],
['col', 'flex-col'],
['pointer-none', 'pointer-events-none'],
['eclipse', 'whitespace-nowrap overflow-hidden text-ellipsis'],
['x-hidden', 'overflow-x-hidden'],
['y-hidden', 'overflow-y-hidden'],
['translatex', 'translate-x'],
['translatey', 'translate-y'],
['dashed', 'border-dashed'],
['dotted', 'border-dotted'],
['double', 'border-double'],
['contain', 'bg-contain'],
['cover', 'bg-cover'],
]

function updateUnoStatus(cwd = currentFolder.uri.fsPath.replace(/\\/g, '/')) {
if (activeTextEditorUri && !prefix.includes(activeTextEditorUri.split('.').slice(-1)[0])) {
hasUnoConfig = undefined
Expand All @@ -458,8 +442,6 @@ export async function activate(context: vscode.ExtensionContext) {

unoCompletionsMap = completions
.map(([content, detail]: any) => createCompletionItem({ content, detail, type: undefined }))
.concat(customMap
.map(([content, detail]) => createCompletionItem({ content, detail, type: undefined })))
})
}
hasUnoConfig = filepath
Expand Down
37 changes: 33 additions & 4 deletions src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ const suppleMore = [
...shadow,
]

const customMap = [
['flex-center', 'justify-center items-center'],
['pointer', 'cursor-pointer'],
['maxw', 'max-w'],
['minw', 'min-w'],
['maxh', 'max-h'],
['minh', 'min-h'],
['position-center', 'left-0 right-0 top-0 bottom-0'],
['col', 'flex-col'],
['pointer-none', 'pointer-events-none'],
['eclipse', 'whitespace-nowrap overflow-hidden text-ellipsis'],
['x-hidden', 'overflow-x-hidden'],
['y-hidden', 'overflow-y-hidden'],
['translatex', 'translate-x'],
['translatey', 'translate-y'],
['dashed', 'border-dashed'],
['dotted', 'border-dotted'],
['double', 'border-double'],
['contain', 'bg-contain'],
['cover', 'bg-cover'],
]

export async function getUnoCompletions(unoUri: string) {
const uno = createGenerator({}, await getConfig(unoUri))
const ac = createAutocomplete(uno)
Expand All @@ -113,10 +135,17 @@ export async function getUnoCompletions(unoUri: string) {
return matched
}
const completions = await enumerateAutocomplete()
return Promise.all([...completions, ...suppleMore].map(async (item) => {
const generate = await uno.generate(new Set([item]), { preflights: false, minify: true })
const css = await formatCSS(generate.css)
return [item, css]
return Promise.all([...completions, ...suppleMore, ...customMap].map(async (item) => {
const isArray = Array.isArray(item)
let css
if (isArray) {
css = (await Promise.all(item[1].split(' ').map(async (item: string) => {
const result = await uno.generate(new Set([item]), { preflights: false, minify: true })
return result.css
}))).join('\n')
}
else { css = (await uno.generate(new Set([isArray ? item[1] : item]), { preflights: false, minify: true })).css }
return [isArray ? item[0] : item, await formatCSS(css)]
}))
}

Expand Down

0 comments on commit 4f2c1f7

Please sign in to comment.