Skip to content

Commit

Permalink
add skip snippets languages setting and filtering on snippets load (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomFractals committed Mar 28, 2021
1 parent 86ca66f commit 3752a9d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@
"type": "boolean",
"default": true,
"description": "Shows built-in extension snippets."
},
"snippets.viewer.skipLanguageSnippets": {
"type": "string",
"default": "",
"description": "Comma delimited list of langueges to skip snippets display in Snippets tree view."
}
}
}
Expand Down
30 changes: 21 additions & 9 deletions src/snippets/snippetLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ export class SnippetLoader {
// get snippet languages from extension snippet files
const snippetLanguages: SnippetLanguage[] = [];
const snippetLanguageMap: Map<string, SnippetLanguage> = new Map<string, SnippetLanguage>();
let skipLanguages: string[] = [];
const showBuiltInExtensionSnippets: boolean =
<boolean>workspace.getConfiguration('snippets.viewer').get('showBuiltInExtensionSnippets');
let skipLanguageSnippets: string =
<string>workspace.getConfiguration('snippets.viewer').get('skipLanguageSnippets');
if (skipLanguageSnippets.length > 0) {
skipLanguageSnippets = skipLanguageSnippets.trim().replace(/\s/g, '');
skipLanguages = skipLanguageSnippets.split(',');
}
extensions.all.forEach(extension => {
if ((showBuiltInExtensionSnippets || !extension.packageJSON.isBuiltin) &&
extension.packageJSON?.contributes?.snippets) {
Expand All @@ -44,16 +51,21 @@ export class SnippetLoader {
if (extensionLocation && Array.isArray(snippetsConfig)) {
snippetsConfig.forEach(snippetConfig => {
const language: string = snippetConfig.language;
const snippetFile: SnippetFile = new SnippetFile(extensionName,
path.join(extensionLocation.fsPath, snippetConfig.path),
language
);
if (!snippetLanguageMap.has(language)) {
const snippetLanguage: SnippetLanguage = new SnippetLanguage(language);
snippetLanguages.push(snippetLanguage);
snippetLanguageMap.set(language, snippetLanguage);
if (skipLanguages.indexOf(language) < 0) {
// create snippets file
const snippetFile: SnippetFile = new SnippetFile(extensionName,
path.join(extensionLocation.fsPath, snippetConfig.path),
language
);
if (!snippetLanguageMap.has(language)) {
// create snippets language
const snippetLanguage: SnippetLanguage = new SnippetLanguage(language);
snippetLanguages.push(snippetLanguage);
snippetLanguageMap.set(language, snippetLanguage);
}
// add snippet file to language snippets
snippetLanguageMap.get(language)?.snippetFiles.push(snippetFile);
}
snippetLanguageMap.get(language)?.snippetFiles.push(snippetFile);
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"snippets.viewer.skipLanguageSnippets": "bat, coffeescript, javascriptreact, typescriptreact, swift, vb"
}

0 comments on commit 3752a9d

Please sign in to comment.