1
1
// The module 'vscode' contains the VS Code extensibility API
2
- // Import the module and reference it with the alias vscode in your code below
3
2
import * as vscode from "vscode" ;
4
3
import getDesignToken from "antd-token-previewer/es/utils/getDesignToken" ;
5
- import rgbHex from "rgb-hex" ;
6
4
import { genMarkdownString } from "./utils" ;
7
5
8
6
// this method is called when your extension is activated
9
7
// your extension is activated the very first time the command is executed
10
8
export function activate ( context : vscode . ExtensionContext ) {
11
- // Use the console to output diagnostic information (console.log) and errors (console.error)
12
9
// This line of code will only be executed once when your extension is activated
13
10
const fullToken = getDesignToken ( ) ;
14
11
12
+ // HOVER
15
13
vscode . languages . registerHoverProvider (
16
14
[
17
15
"javascript" ,
@@ -43,6 +41,7 @@ export function activate(context: vscode.ExtensionContext) {
43
41
}
44
42
) ;
45
43
44
+ // TYPING
46
45
// Add antd token value tips on typing
47
46
// Note: 11 is a `value` kind of completion items.
48
47
// Based on the kind an icon is chosen by the editor.
@@ -51,8 +50,10 @@ export function activate(context: vscode.ExtensionContext) {
51
50
for ( let key in fullToken ) {
52
51
const value = String ( fullToken [ key as keyof typeof fullToken ] ) ;
53
52
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 } ` ;
56
57
57
58
const colorSpan = genMarkdownString ( value ) ;
58
59
let documentContent : vscode . MarkdownString | string = "" ;
@@ -83,22 +84,6 @@ export function activate(context: vscode.ExtensionContext) {
83
84
} ,
84
85
}
85
86
) ;
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 ) ;
102
87
}
103
88
104
89
// this method is called when your extension is deactivated
0 commit comments