|
| 1 | +import { compact } from '@zardoy/utils' |
1 | 2 | import * as vscode from 'vscode' |
2 | 3 | import { getExtensionSetting, registerExtensionCommand } from 'vscode-framework' |
3 | 4 | import { EmmetResult } from '../typescript/src/ipcTypes' |
@@ -61,14 +62,16 @@ export const registerEmmet = async () => { |
61 | 62 | }) |
62 | 63 | return { |
63 | 64 | items: |
64 | | - improveEmmetCompletions<any>(normalizedCompletions)?.map(({ label, insertText, rangeLength, documentation, sortText }) => ({ |
65 | | - label: { label, description: 'EMMET' }, |
66 | | - // sortText is overrided if its a number |
67 | | - sortText: Number.isNaN(+sortText) ? '075' : sortText, |
68 | | - insertText: new vscode.SnippetString(insertText), |
69 | | - range: new vscode.Range(position.translate(0, -rangeLength), position), |
70 | | - documentation: documentation as string, |
71 | | - })) ?? [], |
| 65 | + improveEmmetCompletions<any>(normalizedCompletions, sendToEmmet)?.map( |
| 66 | + ({ label, insertText, rangeLength, documentation, sortText }) => ({ |
| 67 | + label: { label, description: 'EMMET' }, |
| 68 | + // sortText is overrided if its a number |
| 69 | + sortText: Number.isNaN(+sortText) ? '075' : sortText, |
| 70 | + insertText: new vscode.SnippetString(insertText), |
| 71 | + range: new vscode.Range(position.translate(0, -rangeLength), position), |
| 72 | + documentation: documentation as string, |
| 73 | + }), |
| 74 | + ) ?? [], |
72 | 75 | isIncomplete: true, |
73 | 76 | } |
74 | 77 | }, |
@@ -124,27 +127,33 @@ function getEmmetConfiguration() { |
124 | 127 | } |
125 | 128 | } |
126 | 129 |
|
127 | | -const improveEmmetCompletions = <T extends Record<'label' | 'insertText' | 'sortText', string>>(items: T[] | undefined) => { |
| 130 | +const improveEmmetCompletions = <T extends Record<'label' | 'insertText' | 'sortText', string>>(items: T[] | undefined, sendedText: string) => { |
128 | 131 | if (!items) return |
129 | 132 | // TODO-low make to tw= by default when twin.macro is installed? |
130 | 133 | const dotSnippetOverride = getExtensionSetting('jsxEmmet.dotOverride') |
131 | 134 | const modernEmmet = getExtensionSetting('jsxEmmet.modernize') |
132 | 135 |
|
133 | | - return items.map(item => { |
134 | | - const { label } = item |
135 | | - if (label === '.' && typeof dotSnippetOverride === 'string') item.insertText = dotSnippetOverride |
136 | | - // change sorting to most used |
137 | | - if (['div', 'b'].includes(label)) item.sortText = '070' |
138 | | - if (label.startsWith('btn')) item.sortText = '073' |
139 | | - if (modernEmmet) { |
140 | | - // remove id from input suggestions |
141 | | - if (label === 'inp' || label.startsWith('input:password')) { |
142 | | - item.insertText = item.insertText.replace(/ id="\${\d}"/, '') |
143 | | - } |
| 136 | + return compact( |
| 137 | + items.map(item => { |
| 138 | + const { label } = item |
| 139 | + if (label === '.' && typeof dotSnippetOverride === 'string') item.insertText = dotSnippetOverride |
| 140 | + // change sorting to most used |
| 141 | + if (['div', 'b'].includes(label)) item.sortText = '070' |
| 142 | + if (label.startsWith('btn')) item.sortText = '073' |
| 143 | + if (modernEmmet) { |
| 144 | + // note that it still allows to use Item* pattern |
| 145 | + if (sendedText[0] && sendedText[0] !== sendedText[0].toLowerCase() && item.insertText === `<${sendedText}>\${0}</${sendedText}>`) { |
| 146 | + return undefined |
| 147 | + } |
| 148 | + // remove id from input suggestions |
| 149 | + if (label === 'inp' || label.startsWith('input:password')) { |
| 150 | + item.insertText = item.insertText.replace(/ id="\${\d}"/, '') |
| 151 | + } |
144 | 152 |
|
145 | | - if (label === 'textarea') item.insertText = `<textarea>$1</textarea>` |
146 | | - } |
| 153 | + if (label === 'textarea') item.insertText = `<textarea>$1</textarea>` |
| 154 | + } |
147 | 155 |
|
148 | | - return item |
149 | | - }) |
| 156 | + return item |
| 157 | + }), |
| 158 | + ) |
150 | 159 | } |
0 commit comments