11import * as vscode from "vscode" ;
2- import { Config , Opacity , Rule } from "./models" ;
2+ import * as config from "./config" ;
3+ import * as models from "./models" ;
34
45export class ConfigManager {
5- _configCache : Map < vscode . ConfigurationScope , Config > ;
6+ _configCache : Map < vscode . ConfigurationScope , models . Config > ;
67
78 constructor ( ) {
89 this . _configCache = new Map ( ) ;
@@ -12,20 +13,20 @@ export class ConfigManager {
1213 this . _configCache . clear ( ) ;
1314 }
1415
15- _marshallRules ( jsonRules : any [ ] , defaultOpacity : Opacity , defaultFlags : string ) : Rule [ ] {
16+ _marshallRules ( jsonRules : config . Rule [ ] , defaultOpacity : config . Opacity , defaultFlags : string ) : models . Rule [ ] {
1617 return jsonRules
1718 . filter ( ( rule ) => {
1819 return "pattern" in rule ;
1920 } )
2021 . map ( ( rule ) => {
21- return {
22+ return < models . Rule > {
2223 regex : new RegExp ( rule [ "pattern" ] , rule [ "flags" ] ?? defaultFlags ) ,
2324 opacity : rule [ "opacity" ] ?? defaultOpacity ,
2425 } ;
2526 } ) ;
2627 }
2728
28- _getWorkspaceRulesInJSON ( workspaceConfig : vscode . WorkspaceConfiguration ) : any [ ] {
29+ _getWorkspaceRulesInJSON ( workspaceConfig : vscode . WorkspaceConfiguration ) : config . Rule [ ] {
2930 const jsonRules = workspaceConfig . get ( "rules" ) ?? [ ] ;
3031 if ( ! Array . isArray ( jsonRules ) ) return [ ] ;
3132 return jsonRules ;
@@ -35,7 +36,7 @@ export class ConfigManager {
3536 return "[" + editor . document . uri . path . split ( "." ) . pop ( ) + "]" ;
3637 }
3738
38- _getLanguageSpecificRulesInJSON ( editor : vscode . TextEditor ) : Rule [ ] {
39+ _getLanguageSpecificRulesInJSON ( editor : vscode . TextEditor ) : config . Rule [ ] {
3940 const activeLangSlug = this . _getActiveDocumentLanguageSlug ( editor ) ;
4041
4142 const workspaceConfig = vscode . workspace . getConfiguration ( ) ;
@@ -55,22 +56,22 @@ export class ConfigManager {
5556 return rules ;
5657 }
5758
58- _readRules ( editor : vscode . TextEditor , workspaceConfig : vscode . WorkspaceConfiguration ) : Rule [ ] {
59- const defaultOpacity = ( workspaceConfig . get ( "defaultOpacityTier" ) as Opacity ) ?? Opacity . Mid ;
59+ _readRules ( editor : vscode . TextEditor , workspaceConfig : vscode . WorkspaceConfiguration ) : models . Rule [ ] {
60+ const defaultOpacity = ( workspaceConfig . get ( "defaultOpacityTier" ) as config . Opacity ) ?? config . Opacity . Mid ;
6061 const defaultFlags = ( workspaceConfig . get ( "defaultFlags" ) as string ) ?? "gs" ;
6162 const workspaceRules = this . _getWorkspaceRulesInJSON ( workspaceConfig ) ;
6263 const languageSpecificRules = this . _getLanguageSpecificRulesInJSON ( editor ) ;
6364 const rules = this . _marshallRules ( [ ...workspaceRules , ...languageSpecificRules ] , defaultOpacity , defaultFlags ) ;
6465 return rules ;
6566 }
6667
67- readConfig ( editor : vscode . TextEditor ) : Config {
68+ readConfig ( editor : vscode . TextEditor ) : models . Config {
6869 const cached = this . _configCache . get ( editor . document . uri ) ;
6970 if ( cached ) {
7071 return cached ;
7172 }
7273 const workspaceConfig = vscode . workspace . getConfiguration ( "dim" , editor . document . uri ) ;
73- const config : Config = {
74+ const config : models . Config = {
7475 rules : this . _readRules ( editor , workspaceConfig ) ,
7576 valueForMinTier : workspaceConfig . get ( "valueForMinTier" ) ?? 0.25 ,
7677 valueForMidTier : workspaceConfig . get ( "valueForMidTier" ) ?? 0.5 ,
0 commit comments