fix completion item order

master
Brad Cornes 2020-04-27 23:18:28 +01:00
parent 01f37e2c30
commit 6f5a942632
2 changed files with 17 additions and 3 deletions

View File

@ -20,6 +20,7 @@ import * as emmetHelper from 'emmet-helper'
import { isValidLocationForEmmetAbbreviation } from '../util/isValidLocationForEmmetAbbreviation' import { isValidLocationForEmmetAbbreviation } from '../util/isValidLocationForEmmetAbbreviation'
import { getDocumentSettings } from '../util/getDocumentSettings' import { getDocumentSettings } from '../util/getDocumentSettings'
import { isJsContext } from '../util/js' import { isJsContext } from '../util/js'
import { naturalExpand } from '../util/naturalExpand'
function completionsFromClassList( function completionsFromClassList(
state: State, state: State,
@ -65,15 +66,17 @@ function completionsFromClassList(
return { return {
isIncomplete: false, isIncomplete: false,
items: Object.keys(isSubset ? subset : state.classNames.classNames).map( items: Object.keys(isSubset ? subset : state.classNames.classNames).map(
(className) => { (className, index) => {
let label = className let label = className
let kind: CompletionItemKind = CompletionItemKind.Constant let kind: CompletionItemKind = CompletionItemKind.Constant
let documentation: string = null let documentation: string = null
let command: any let command: any
let sortText = naturalExpand(index)
if (isContextItem(state, [...subsetKey, className])) { if (isContextItem(state, [...subsetKey, className])) {
kind = CompletionItemKind.Module kind = CompletionItemKind.Module
command = { title: '', command: 'editor.action.triggerSuggest' } command = { title: '', command: 'editor.action.triggerSuggest' }
label += sep label += sep
sortText = '-' + sortText // move to top
} else { } else {
const color = getColor(state, [className]) const color = getColor(state, [className])
if (color) { if (color) {
@ -87,6 +90,7 @@ function completionsFromClassList(
kind, kind,
documentation, documentation,
command, command,
sortText,
data: [...subsetKey, className], data: [...subsetKey, className],
textEdit: { textEdit: {
newText: label, newText: label,
@ -261,7 +265,7 @@ function provideCssHelperCompletions(
return { return {
isIncomplete: false, isIncomplete: false,
items: Object.keys(obj).map((item) => { items: Object.keys(obj).map((item, index) => {
let color = getColorFromString(obj[item]) let color = getColorFromString(obj[item])
const replaceDot: boolean = const replaceDot: boolean =
item.indexOf('.') !== -1 && separator && separator.endsWith('.') item.indexOf('.') !== -1 && separator && separator.endsWith('.')
@ -272,6 +276,7 @@ function provideCssHelperCompletions(
return { return {
label: item, label: item,
filterText: `${replaceDot ? '.' : ''}${item}`, filterText: `${replaceDot ? '.' : ''}${item}`,
sortText: naturalExpand(index),
kind: color kind: color
? CompletionItemKind.Color ? CompletionItemKind.Color
: isObject(obj[item]) : isObject(obj[item])
@ -378,10 +383,11 @@ function provideScreenDirectiveCompletions(
return { return {
isIncomplete: false, isIncomplete: false,
items: Object.keys(screens).map((screen) => ({ items: Object.keys(screens).map((screen, index) => ({
label: screen, label: screen,
kind: CompletionItemKind.Constant, kind: CompletionItemKind.Constant,
data: 'screen', data: 'screen',
sortText: naturalExpand(index),
textEdit: { textEdit: {
newText: screen, newText: screen,
range: { range: {

View File

@ -0,0 +1,8 @@
function pad(n: string): string {
return ('00000000' + n).substr(-8)
}
export function naturalExpand(value: number | string): string {
let str = typeof value === 'string' ? value : value.toString()
return str.replace(/\d+/g, pad)
}