Skip to content

Commit 6ea779d

Browse files
committed
🐛 Fix not resolving variables SnippetSession.createEditsAndSnippetsFromEdits method
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent d2232af commit 6ea779d

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/vs/editor/contrib/snippet/browser/snippetSession.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,17 @@ export class SnippetSession {
535535
const parser = new SnippetParser();
536536
const snippet = new TextmateSnippet();
537537

538+
// snippet variables resolver
539+
const resolver = new CompositeSnippetVariableResolver([
540+
editor.invokeWithinContext(accessor => new ModelBasedVariableResolver(accessor.get(ILabelService), model)),
541+
new ClipboardBasedVariableResolver(() => clipboardText, 0, editor.getSelections().length, editor.getOption(EditorOption.multiCursorPaste) === 'spread'),
542+
new SelectionBasedVariableResolver(model, editor.getSelection(), 0, overtypingCapturer),
543+
new CommentBasedVariableResolver(model, editor.getSelection(), languageConfigurationService),
544+
new TimeBasedVariableResolver,
545+
new WorkspaceBasedVariableResolver(editor.invokeWithinContext(accessor => accessor.get(IWorkspaceContextService))),
546+
new RandomBasedVariableResolver,
547+
]);
548+
538549
//
539550
snippetEdits = snippetEdits.sort((a, b) => Range.compareRangesUsingStarts(a.range, b.range));
540551
let offset = 0;
@@ -553,6 +564,7 @@ export class SnippetSession {
553564
}
554565

555566
parser.parseFragment(template, snippet);
567+
snippet.resolveVariables(resolver);
556568

557569
const snippetText = snippet.toString();
558570
const snippetFragmentText = snippetText.slice(offset);
@@ -568,19 +580,6 @@ export class SnippetSession {
568580
//
569581
parser.ensureFinalTabstop(snippet, enforceFinalTabstop, true);
570582

571-
// snippet variables resolver
572-
const resolver = new CompositeSnippetVariableResolver([
573-
editor.invokeWithinContext(accessor => new ModelBasedVariableResolver(accessor.get(ILabelService), model)),
574-
new ClipboardBasedVariableResolver(() => clipboardText, 0, editor.getSelections().length, editor.getOption(EditorOption.multiCursorPaste) === 'spread'),
575-
new SelectionBasedVariableResolver(model, editor.getSelection(), 0, overtypingCapturer),
576-
new CommentBasedVariableResolver(model, editor.getSelection(), languageConfigurationService),
577-
new TimeBasedVariableResolver,
578-
new WorkspaceBasedVariableResolver(editor.invokeWithinContext(accessor => accessor.get(IWorkspaceContextService))),
579-
new RandomBasedVariableResolver,
580-
]);
581-
snippet.resolveVariables(resolver);
582-
583-
584583
return {
585584
edits,
586585
snippets: [new OneSnippet(editor, snippet, '')]

0 commit comments

Comments
 (0)