1- import globToRegExp from "glob-to-regexp" ;
21import * as vscode from "vscode" ;
32
3+ import globToRegExp from "glob-to-regexp" ;
4+
45import { Settings } from "./settings/settings" ;
56import { Configuration } from "./tsco-cli/configuration/configuration" ;
67import { fileExists , getDirectoryPath , getFullPath , getRelativePath , joinPath , readFile , writeFile } from "./tsco-cli/helpers/file-system-helper" ;
8+ import { log , setLogger } from "./tsco-cli/source-code/source-code-logger" ;
79import { SourceCodeOrganizer } from "./tsco-cli/source-code/source-code-organizer" ;
810
911// #region Functions (10)
@@ -14,21 +16,17 @@ async function getConfiguration(configurationFilePath: string | null)
1416 {
1517 if ( await fileExists ( configurationFilePath ) )
1618 {
17- output . appendLine ( `tsco using configuration file ${ configurationFilePath } ` ) ;
18-
1919 // absolute configuration file path from settings
2020 return await Configuration . getConfiguration ( configurationFilePath ) ;
2121 }
2222 else if ( await fileExists ( joinPath ( getWorkspaceRootDirectoryPath ( ) , configurationFilePath ) ) )
2323 {
24- output . appendLine ( `tsco using configuration file ${ joinPath ( getWorkspaceRootDirectoryPath ( ) , configurationFilePath ) } ` ) ;
25-
2624 // relative configuration file path from settings
2725 return await Configuration . getConfiguration ( joinPath ( getWorkspaceRootDirectoryPath ( ) , configurationFilePath ) ) ;
2826 }
2927 else
3028 {
31- output . appendLine ( `tsco configuration file ${ getFullPath ( configurationFilePath ) } not found` ) ;
29+ log ( `tsco configuration file ${ getFullPath ( configurationFilePath ) } not found` ) ;
3230 }
3331 }
3432
@@ -38,8 +36,6 @@ async function getConfiguration(configurationFilePath: string | null)
3836
3937 if ( await fileExists ( configurationFilePath ) )
4038 {
41- output . appendLine ( `tsco using configuration file ${ configurationFilePath } ` ) ;
42-
4339 // look in workspace root
4440 return await Configuration . getConfiguration ( configurationFilePath ) ;
4541 }
@@ -52,13 +48,11 @@ async function getConfiguration(configurationFilePath: string | null)
5248
5349 if ( await fileExists ( configurationFilePath ) )
5450 {
55- output . appendLine ( `tsco using configuration file ${ configurationFilePath } ` ) ;
56-
5751 return await Configuration . getConfiguration ( configurationFilePath ) ;
5852 }
5953 }
6054
61- output . appendLine ( "tsco using default configuration" ) ;
55+ log ( "tsco using default configuration" ) ;
6256
6357 // default configuration
6458 return Configuration . getDefaultConfiguration ( ) ;
@@ -196,12 +190,12 @@ async function organize(sourceCodeFilePath: string, configuration: Configuration
196190
197191 if ( configuration . files . include . length > 0 )
198192 {
199- include = configuration . files . include . some ( inc => matches ( inc , sourceCodeFilePathRelative ) || matches ( inc , "./" + sourceCodeFilePathRelative ) ) ;
193+ include = configuration . files . include . some ( inc => matches ( inc , sourceCodeFilePathRelative ) || matches ( inc , sourceCodeFilePathRelative . replace ( "../" , "" ) . replace ( "./" , "" ) ) ) ;
200194 }
201195
202196 if ( configuration . files . exclude . length > 0 )
203197 {
204- exclude = configuration . files . exclude . some ( exc => matches ( exc , sourceCodeFilePathRelative ) || matches ( exc , "./" + sourceCodeFilePathRelative ) ) ;
198+ exclude = configuration . files . exclude . some ( exc => matches ( exc , sourceCodeFilePathRelative ) || matches ( exc , sourceCodeFilePathRelative . replace ( "../" , "" ) . replace ( "./" , "" ) ) ) ;
205199 }
206200
207201 if ( include && ! exclude )
@@ -223,22 +217,22 @@ async function organize(sourceCodeFilePath: string, configuration: Configuration
223217
224218 await vscode . workspace . applyEdit ( edit ) ;
225219
226- output . appendLine ( `tsco organized ${ sourceCodeFilePath } ` ) ;
220+ log ( `tsco organized ${ sourceCodeFilePath } ` ) ;
227221
228222 return true ;
229223 }
230224 else
231225 {
232- output . appendLine ( `tsco skipping organizing ${ sourceCodeFilePath } , because it is already organized` ) ;
226+ log ( `tsco skipping organizing ${ sourceCodeFilePath } , because it is already organized` ) ;
233227 }
234228 }
235229 else if ( ! include )
236230 {
237- output . appendLine ( `tsco skipping organizing ${ sourceCodeFilePath } , because it does not match file include patterns` ) ;
231+ log ( `tsco skipping organizing ${ sourceCodeFilePath } , because it does not match file include patterns` ) ;
238232 }
239233 else if ( exclude )
240234 {
241- output . appendLine ( `tsco skipping organizing ${ sourceCodeFilePath } , because it matches file exclude patterns` ) ;
235+ log ( `tsco skipping organizing ${ sourceCodeFilePath } , because it matches file exclude patterns` ) ;
242236 }
243237
244238 return false ;
@@ -256,6 +250,11 @@ export function activate(context: vscode.ExtensionContext)
256250
257251 vscode . workspace . onDidChangeConfiguration ( ( ) => settings = Settings . getSettings ( ) ) ;
258252 savingHandler = vscode . workspace . onWillSaveTextDocument ( async ( e ) => await onSave ( e . document . uri . fsPath ) ) ;
253+
254+ setLogger ( {
255+ log : ( message : string ) => output . appendLine ( message ) ,
256+ logError : ( error : string | Error | unknown ) => output . appendLine ( `ERROR: ${ error instanceof Error ? error . message : error ?. toString ( ) ?? "" } ` )
257+ } ) ;
259258}
260259
261260// #endregion Exported Functions
0 commit comments