'use strict' ; import * as path from 'path' ; import * as vscode from 'vscode' ; import { Uri } from 'vscode' ; import { IConfig } from '../spgo' ; import { TextDocument } from 'vscode' ; import { WorkspaceFolder } from 'vscode' ; export class FileHelper { public static convertToForwardSlash ( sourceDirectory ) { return sourceDirectory . replace ( /\//g , '\\' ) ; } public static convertToBackSlash ( sourceDirectory ) { return sourceDirectory . replace ( /\\/g , '/' ) ; } public static convertToUri ( uriString ) { return Uri . file ( uriString . replace ( /\\/g , '/' ) ) ; } public static ensureCorrectPathSeparator ( sourceDirectory ) { return sourceDirectory . replace ( /\\/g , path . sep ) . replace ( /\//g , path . sep ) ; } static isPathFile ( filePath ) { let finalNode = filePath . fsPath . split ( path . sep ) . pop ( ) ; return finalNode . indexOf ( '.' ) >= 0 && finalNode != '.' && finalNode . indexOf ( '*' ) < 0 ; } static getExtensionRelativeFilePath ( filePath , config ) { return filePath . fsPath . split ( config . sourceRoot + path . sep ) [ 1 ] . toString ( ) ; } static getFileName ( filePath ) { return filePath . fsPath . substring ( filePath . fsPath . lastIndexOf ( path . sep ) + 1 ) ; } static getFolderFromPath ( filePath , config ) { let relativeFilePath = this . getExtensionRelativeFilePath ( filePath , config ) ; return relativeFilePath . substring ( 0 , relativeFilePath . lastIndexOf ( path . sep ) ) ; } static getActiveFile ( workspaces ) { const activeTextEditor = vscode . window . activeTextEditor ; let file ; if ( activeTextEditor ) { let workspace = vscode . workspace . getWorkspaceFolder ( activeTextEditor . document . uri ) ; if ( workspace && workspaces . filter ( w => w . name == workspace . name ) . length ) { file = activeTextEditor . document ; } } return file ; } }