✨ Add completion for default icons (#7)
This commit is contained in:
parent
80a536d848
commit
720f4e6c2f
2 changed files with 54 additions and 0 deletions
|
@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
|
||||||
This allows the completions to show _all_ filters, not just the ones in `filters.json` and `questions.json`.
|
This allows the completions to show _all_ filters, not just the ones in `filters.json` and `questions.json`.
|
||||||
It's also possible to look up uses of a filter or a tagRendering.
|
It's also possible to look up uses of a filter or a tagRendering.
|
||||||
The caching will take about 30 seconds to complete, but it will only run once per session, and will update individual files as they are saved or removed.
|
The caching will take about 30 seconds to complete, but it will only run once per session, and will update individual files as they are saved or removed.
|
||||||
|
- Autocompletion for `icon` fields, giving the built-in icons as suggestions.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,59 @@ import {
|
||||||
vsCodeToHex,
|
vsCodeToHex,
|
||||||
} from "./utils/color";
|
} from "./utils/color";
|
||||||
|
|
||||||
|
export const iconCompletionProvider =
|
||||||
|
vscode.languages.registerCompletionItemProvider(
|
||||||
|
{
|
||||||
|
language: "json",
|
||||||
|
scheme: "file",
|
||||||
|
pattern: "**/assets/*/*/*.json",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
async provideCompletionItems(
|
||||||
|
document: vscode.TextDocument,
|
||||||
|
position: vscode.Position
|
||||||
|
) {
|
||||||
|
console.log("iconCompletionProvider");
|
||||||
|
const text = document.getText();
|
||||||
|
const jsonPath = getCursorPath(text, position);
|
||||||
|
|
||||||
|
const regexes = [/icon$/, /icon.render/, /icon.mappings.\d+.then$/];
|
||||||
|
|
||||||
|
if (regexes.some((regex) => regex.exec(jsonPath))) {
|
||||||
|
// We need to look at all the files in the assets/svg folder
|
||||||
|
const svgFolder = path.join(
|
||||||
|
(vscode.workspace.workspaceFolders
|
||||||
|
? vscode.workspace.workspaceFolders[0].uri.fsPath
|
||||||
|
: "") || "",
|
||||||
|
"assets",
|
||||||
|
"svg"
|
||||||
|
);
|
||||||
|
|
||||||
|
const files = await vscode.workspace.fs.readDirectory(
|
||||||
|
vscode.Uri.file(svgFolder)
|
||||||
|
);
|
||||||
|
|
||||||
|
const icons: vscode.CompletionItem[] = [];
|
||||||
|
|
||||||
|
files.forEach((file) => {
|
||||||
|
if (file[1] === 1) {
|
||||||
|
if (file[0].endsWith(".svg")) {
|
||||||
|
const name = file[0].split(".")[0];
|
||||||
|
icons.push({
|
||||||
|
label: name,
|
||||||
|
kind: vscode.CompletionItemKind.File,
|
||||||
|
insertText: name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return icons;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Icon definition provider
|
* Icon definition provider
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue