MCPcopy Create free account
hub / github.com/cursorless-dev/cursorless / mergeSnippets

Method mergeSnippets

src/core/Snippets.ts:147–176  ·  view source on GitHub ↗

* Merge core, third-party, and user snippets, with precedence user > third * party > core.

()

Source from the content-addressed store, hash-verified

145 * party > core.
146 */
147 private mergeSnippets() {
148 this.mergedSnippets = {};
149
150 // We make a list of all entries from all sources, in order of increasing
151 // precedence: user > third party > core.
152 const entries = [
153 ...Object.entries(cloneDeep(this.coreSnippets)),
154 ...Object.values(this.thirdPartySnippets).flatMap((snippets) =>
155 Object.entries(cloneDeep(snippets))
156 ),
157 ...Object.entries(cloneDeep(this.userSnippets)),
158 ];
159
160 entries.forEach(([key, value]) => {
161 if (this.mergedSnippets.hasOwnProperty(key)) {
162 const { definitions, ...rest } = value;
163 const mergedSnippet = this.mergedSnippets[key];
164
165 // NB: We make sure that the new definitions appear before the previous
166 // ones so that they take precedence
167 mergedSnippet.definitions = definitions.concat(
168 ...mergedSnippet.definitions
169 );
170
171 merge(mergedSnippet, rest);
172 } else {
173 this.mergedSnippets[key] = value;
174 }
175 });
176 }
177
178 /**
179 * Looks in merged collection of snippets for a snippet with key

Callers 2

updateUserSnippetsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected