Skip to content

Commit 50ff939

Browse files
committed
feat: add option showTrueTokens, allows filtering true and -true space/size tokens from autocomplete
1 parent 3026cc3 commit 50ff939

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/getCompletions.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,19 @@ export const getCompletions = (
6363
}
6464
}
6565

66-
const [scale, value] = getMaybeSpecificToken(entry.name, type, config);
66+
const [scale, value, token] = getMaybeSpecificToken(
67+
entry.name,
68+
type,
69+
config
70+
);
6771
if (scale && value) {
72+
const isTrueToken =
73+
(scale === 'space' || scale === 'size') &&
74+
(token === '$true' || token === '$-true');
75+
if (isTrueToken && !options.completionFilters.showTrueTokens) {
76+
// filter out true and -true tokens
77+
continue;
78+
}
6879
const isColor = scale === 'color';
6980
if (isColor && !options.completionFilters.showColorTokens) {
7081
// filter out color tokens if the option is disabled

src/readOptions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ export const readOptions = ({ info, modules }: TSContext) => {
1010
pathToApp = 'apps/next',
1111
defaultTheme = 'light',
1212
colorTileSize = 18,
13-
completionFilters: { showColorTokens = true } = {},
13+
completionFilters: { showColorTokens = true, showTrueTokens = true } = {},
1414
} = info.config as {
1515
pathToApp?: string;
1616
defaultTheme?: string;
1717
colorTileSize?: number;
1818
completionFilters?: {
1919
showColorTokens?: boolean;
20+
showTrueTokens?: boolean;
2021
};
2122
};
2223

@@ -36,6 +37,7 @@ export const readOptions = ({ info, modules }: TSContext) => {
3637
colorTileSize,
3738
completionFilters: {
3839
showColorTokens,
40+
showTrueTokens,
3941
},
4042
} as const;
4143
};

src/utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ export const getMaybeSpecificToken = (
4444
| ParsedConfig[keyof ParsedConfig]
4545
| undefined;
4646

47-
const val = scaleObj?.[
48-
(token.startsWith('$') ? token : `$${token}`) as keyof typeof scaleObj
49-
] as string | undefined;
47+
const tokenKey = (
48+
token.startsWith('$') ? token : `$${token}`
49+
) as keyof typeof scaleObj;
50+
const val = scaleObj?.[tokenKey] as string | undefined;
5051

5152
if (!val) return [undefined, undefined] as const;
5253

53-
return [scale, val] as const;
54+
return [scale, val, tokenKey] as const;
5455
};
5556

5657
/**

0 commit comments

Comments
 (0)