(
[targets]: [TypedSelection[]],
snippetLocation: string
)
| 54 | } |
| 55 | |
| 56 | async run( |
| 57 | [targets]: [TypedSelection[]], |
| 58 | snippetLocation: string |
| 59 | ): Promise<ActionReturnValue> { |
| 60 | const [snippetName, placeholderName] = |
| 61 | parseSnippetLocation(snippetLocation); |
| 62 | |
| 63 | const snippet = this.graph.snippets.getSnippet(snippetName)!; |
| 64 | |
| 65 | const editor = ensureSingleEditor(targets); |
| 66 | |
| 67 | // Find snippet definition matching context. |
| 68 | // NB: We only look at the first target to create our context. This means |
| 69 | // that if there are two snippets that match two different contexts, and |
| 70 | // the two targets match those two different contexts, we will just use the |
| 71 | // snippet that matches the first context for both targets |
| 72 | const definition = findMatchingSnippetDefinition( |
| 73 | targets[0], |
| 74 | snippet.definitions |
| 75 | ); |
| 76 | |
| 77 | if (definition == null) { |
| 78 | throw new Error("Couldn't find matching snippet definition"); |
| 79 | } |
| 80 | |
| 81 | const parsedSnippet = this.snippetParser.parse(definition.body.join("\n")); |
| 82 | |
| 83 | transformSnippetVariables(parsedSnippet, placeholderName); |
| 84 | |
| 85 | const snippetString = parsedSnippet.toTextmateString(); |
| 86 | |
| 87 | await displayPendingEditDecorations( |
| 88 | targets, |
| 89 | this.graph.editStyles.pendingModification0 |
| 90 | ); |
| 91 | |
| 92 | const targetSelections = targets.map( |
| 93 | (target) => target.selection.selection |
| 94 | ); |
| 95 | |
| 96 | await this.graph.actions.setSelection.run([targets]); |
| 97 | |
| 98 | // NB: We used the command "editor.action.insertSnippet" instead of calling editor.insertSnippet |
| 99 | // because the latter doesn't support special variables like CLIPBOARD |
| 100 | const [updatedTargetSelections] = await callFunctionAndUpdateSelections( |
| 101 | this.graph.rangeUpdater, |
| 102 | () => |
| 103 | commands.executeCommand("editor.action.insertSnippet", { |
| 104 | snippet: snippetString, |
| 105 | }), |
| 106 | editor.document, |
| 107 | [targetSelections] |
| 108 | ); |
| 109 | |
| 110 | return { |
| 111 | thatMark: updatedTargetSelections.map((selection) => ({ |
| 112 | editor, |
| 113 | selection, |
nothing calls this directly
no test coverage detected