Skip to content

Commit 6f5a942

Browse files
author
Brad Cornes
committed
fix completion item order
1 parent 01f37e2 commit 6f5a942

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/tailwindcss-language-server/src/providers/completionProvider.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as emmetHelper from 'emmet-helper'
2020
import { isValidLocationForEmmetAbbreviation } from '../util/isValidLocationForEmmetAbbreviation'
2121
import { getDocumentSettings } from '../util/getDocumentSettings'
2222
import { isJsContext } from '../util/js'
23+
import { naturalExpand } from '../util/naturalExpand'
2324

2425
function completionsFromClassList(
2526
state: State,
@@ -65,15 +66,17 @@ function completionsFromClassList(
6566
return {
6667
isIncomplete: false,
6768
items: Object.keys(isSubset ? subset : state.classNames.classNames).map(
68-
(className) => {
69+
(className, index) => {
6970
let label = className
7071
let kind: CompletionItemKind = CompletionItemKind.Constant
7172
let documentation: string = null
7273
let command: any
74+
let sortText = naturalExpand(index)
7375
if (isContextItem(state, [...subsetKey, className])) {
7476
kind = CompletionItemKind.Module
7577
command = { title: '', command: 'editor.action.triggerSuggest' }
7678
label += sep
79+
sortText = '-' + sortText // move to top
7780
} else {
7881
const color = getColor(state, [className])
7982
if (color) {
@@ -87,6 +90,7 @@ function completionsFromClassList(
8790
kind,
8891
documentation,
8992
command,
93+
sortText,
9094
data: [...subsetKey, className],
9195
textEdit: {
9296
newText: label,
@@ -261,7 +265,7 @@ function provideCssHelperCompletions(
261265

262266
return {
263267
isIncomplete: false,
264-
items: Object.keys(obj).map((item) => {
268+
items: Object.keys(obj).map((item, index) => {
265269
let color = getColorFromString(obj[item])
266270
const replaceDot: boolean =
267271
item.indexOf('.') !== -1 && separator && separator.endsWith('.')
@@ -272,6 +276,7 @@ function provideCssHelperCompletions(
272276
return {
273277
label: item,
274278
filterText: `${replaceDot ? '.' : ''}${item}`,
279+
sortText: naturalExpand(index),
275280
kind: color
276281
? CompletionItemKind.Color
277282
: isObject(obj[item])
@@ -378,10 +383,11 @@ function provideScreenDirectiveCompletions(
378383

379384
return {
380385
isIncomplete: false,
381-
items: Object.keys(screens).map((screen) => ({
386+
items: Object.keys(screens).map((screen, index) => ({
382387
label: screen,
383388
kind: CompletionItemKind.Constant,
384389
data: 'screen',
390+
sortText: naturalExpand(index),
385391
textEdit: {
386392
newText: screen,
387393
range: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function pad(n: string): string {
2+
return ('00000000' + n).substr(-8)
3+
}
4+
5+
export function naturalExpand(value: number | string): string {
6+
let str = typeof value === 'string' ? value : value.toString()
7+
return str.replace(/\d+/g, pad)
8+
}

0 commit comments

Comments
 (0)