Skip to content

Commit 9beea75

Browse files
committed
fix: fix typing item sort
1 parent 7ce5813 commit 9beea75

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

assets/sort.png

106 KB
Loading

src/extension.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
// The module 'vscode' contains the VS Code extensibility API
2-
// Import the module and reference it with the alias vscode in your code below
32
import * as vscode from "vscode";
43
import getDesignToken from "antd-token-previewer/es/utils/getDesignToken";
5-
import rgbHex from "rgb-hex";
64
import { genMarkdownString } from "./utils";
75

86
// this method is called when your extension is activated
97
// your extension is activated the very first time the command is executed
108
export function activate(context: vscode.ExtensionContext) {
11-
// Use the console to output diagnostic information (console.log) and errors (console.error)
129
// This line of code will only be executed once when your extension is activated
1310
const fullToken = getDesignToken();
1411

12+
// HOVER
1513
vscode.languages.registerHoverProvider(
1614
[
1715
"javascript",
@@ -43,6 +41,7 @@ export function activate(context: vscode.ExtensionContext) {
4341
}
4442
);
4543

44+
// TYPING
4645
// Add antd token value tips on typing
4746
// Note: 11 is a `value` kind of completion items.
4847
// Based on the kind an icon is chosen by the editor.
@@ -51,8 +50,10 @@ export function activate(context: vscode.ExtensionContext) {
5150
for (let key in fullToken) {
5251
const value = String(fullToken[key as keyof typeof fullToken]);
5352
const item = new vscode.CompletionItem(`antd-${key}: ${value}`, 11);
54-
item.insertText = key;
55-
item.sortText = `a${key}`;
53+
item.insertText = key.includes("-") ? `['${key}']` : key;
54+
55+
const sortValue = value.padStart(3, "0");
56+
item.sortText = `a-${sortValue}-${key}`;
5657

5758
const colorSpan = genMarkdownString(value);
5859
let documentContent: vscode.MarkdownString | string = "";
@@ -83,22 +84,6 @@ export function activate(context: vscode.ExtensionContext) {
8384
},
8485
}
8586
);
86-
87-
// The command has been defined in the package.json file
88-
// Now provide the implementation of the command with registerCommand
89-
// The commandId parameter must match the command field in package.json
90-
let disposable = vscode.commands.registerCommand(
91-
"antd-design-token.helloWorld",
92-
() => {
93-
// The code you place here will be executed every time your command is executed
94-
// Display a message box to the user
95-
vscode.window.showInformationMessage(
96-
"Hello World from antd design token!"
97-
);
98-
}
99-
);
100-
101-
context.subscriptions.push(disposable);
10287
}
10388

10489
// this method is called when your extension is deactivated

0 commit comments

Comments
 (0)