11import * as vscode from "vscode" ;
22import { findParens } from "./parse" ;
33import { debounce , repeat } from "./utils" ;
4- import { DEBOUNCE_TIME , PARSER_CONFIG } from "./constants" ;
4+ import { DEBOUNCE_CONFIG , PARSER_CONFIG } from "./constants" ;
55import { ParserPlugin } from "@babel/parser" ;
66
77export function activateParens ( ) {
@@ -21,19 +21,24 @@ export function activateParens() {
2121
2222 subscriptions . push ( decorationType ) ;
2323
24- updateDecorations ( decorationType ) ;
24+ for ( const editor of vscode . window . visibleTextEditors ) {
25+ updateDecorations ( editor , decorationType ) ;
26+ }
2527
2628 const triggerUpdateDecorations = debounce (
27- ( ) => updateDecorations ( decorationType ) ,
28- DEBOUNCE_TIME
29+ ( editor : vscode . TextEditor ) => updateDecorations ( editor , decorationType ) ,
30+ vscode . workspace . getConfiguration ( ) . get ( DEBOUNCE_CONFIG )
2931 ) ;
3032 subscriptions . push (
3133 new vscode . Disposable ( ( ) => triggerUpdateDecorations . cancel ( ) )
3234 ) ;
3335
3436 vscode . window . onDidChangeActiveTextEditor (
3537 ( ) => {
36- triggerUpdateDecorations ( ) ;
38+ const activeEditor = vscode . window . activeTextEditor ;
39+ if ( activeEditor !== undefined ) {
40+ triggerUpdateDecorations ( activeEditor ) ;
41+ }
3742 } ,
3843 null ,
3944 subscriptions
@@ -46,7 +51,7 @@ export function activateParens() {
4651 activeEditor !== undefined &&
4752 event . document === activeEditor . document
4853 ) {
49- triggerUpdateDecorations ( ) ;
54+ triggerUpdateDecorations ( activeEditor ) ;
5055 }
5156 } ,
5257 null ,
@@ -70,13 +75,11 @@ function getPlugins(): ParserPlugin[] {
7075 }
7176}
7277
73- function updateDecorations ( decorationType : vscode . TextEditorDecorationType ) {
74- const activeEditor = vscode . window . activeTextEditor ;
75- if ( ! activeEditor ) {
76- return ;
77- }
78-
79- const parens = findParens ( activeEditor . document . getText ( ) , getPlugins ( ) ) ;
78+ function updateDecorations (
79+ editor : vscode . TextEditor ,
80+ decorationType : vscode . TextEditorDecorationType
81+ ) {
82+ const parens = findParens ( editor . document . getText ( ) , getPlugins ( ) ) ;
8083 if ( parens === null ) {
8184 return ;
8285 }
@@ -98,13 +101,13 @@ function updateDecorations(decorationType: vscode.TextEditorDecorationType) {
98101
99102 const paren = { before : "(" , after : ")" } ;
100103
101- activeEditor . setDecorations (
104+ editor . setDecorations (
102105 decorationType ,
103106 decorations . map ( ( { count, pos, beforeAfter } ) => {
104107 return {
105108 range : new vscode . Range (
106- activeEditor . document . positionAt ( pos ) ,
107- activeEditor . document . positionAt ( pos )
109+ editor . document . positionAt ( pos ) ,
110+ editor . document . positionAt ( pos )
108111 ) ,
109112 renderOptions : {
110113 [ beforeAfter ] : { contentText : repeat ( paren [ beforeAfter ] , count ) } ,
0 commit comments