Skip to content

Commit 3026cc3

Browse files
committed
feat: add option showColorTokens, allows filtering color tokens from autocomplete results
1 parent da977ad commit 3026cc3

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/getCompletions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const getCompletions = (
4343

4444
logger(`token type <${type}>`);
4545

46+
const entries: ts.CompletionEntry[] = [];
4647
for (const entry of original.entries) {
4748
if (type === 'color') {
4849
const themeValue =
@@ -57,13 +58,18 @@ export const getCompletions = (
5758
detail: ' ' + defaultValue,
5859
description: 'ThemeToken',
5960
};
61+
entries.push(entry);
6062
continue;
6163
}
6264
}
6365

6466
const [scale, value] = getMaybeSpecificToken(entry.name, type, config);
6567
if (scale && value) {
6668
const isColor = scale === 'color';
69+
if (isColor && !options.completionFilters.showColorTokens) {
70+
// filter out color tokens if the option is disabled
71+
continue;
72+
}
6773
if (isColor) {
6874
entry.kindModifiers = 'color';
6975
}
@@ -73,7 +79,11 @@ export const getCompletions = (
7379
description: `${toPascal(scale)}Token`,
7480
};
7581
}
82+
83+
entries.push(entry);
7684
}
7785

86+
original.entries = entries;
87+
7888
return original;
7989
};

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const init = (modules: { typescript: tss }) => {
4242
};
4343

4444
const options = readOptions(ctx);
45+
46+
logger(`Options parsed`);
47+
logger(options);
48+
4549
const { defaultTheme, tamaguiConfigFilePath } = options;
4650

4751
logger(`Using tamagui config path: ${tamaguiConfigFilePath}`);

src/readOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ export const readOptions = ({ info, modules }: TSContext) => {
1010
pathToApp = 'apps/next',
1111
defaultTheme = 'light',
1212
colorTileSize = 18,
13+
completionFilters: { showColorTokens = true } = {},
1314
} = info.config as {
1415
pathToApp?: string;
1516
defaultTheme?: string;
1617
colorTileSize?: number;
18+
completionFilters?: {
19+
showColorTokens?: boolean;
20+
};
1721
};
1822

1923
const rootDir = path.join(
@@ -30,6 +34,9 @@ export const readOptions = ({ info, modules }: TSContext) => {
3034
tamaguiConfigFilePath,
3135
defaultTheme,
3236
colorTileSize,
37+
completionFilters: {
38+
showColorTokens,
39+
},
3340
} as const;
3441
};
3542

0 commit comments

Comments
 (0)