import { CancellationToken , ConfigurationChangeEvent , Event , FileSystemWatcher , GlobPattern , Uri , workspace , WorkspaceConfiguration , WorkspaceFolder , WorkspaceFoldersChangeEvent } from 'vscode' ; import { Resource } from '../types' ; import { IWorkspaceService } from './types' ; export class WorkspaceService implements IWorkspaceService { public get onDidChangeConfiguration ( ) : Event < ConfigurationChangeEvent > { return workspace . onDidChangeConfiguration ; } public get rootPath ( ) : string | undefined { return Array . isArray ( workspace . workspaceFolders ) ? workspace . workspaceFolders [ 0 ] . uri . fsPath : undefined ; } public get workspaceFolders ( ) : WorkspaceFolder [ ] | undefined { return workspace . workspaceFolders ; } public get onDidChangeWorkspaceFolders ( ) : Event < WorkspaceFoldersChangeEvent > { return workspace . onDidChangeWorkspaceFolders ; } public get hasWorkspaceFolders ( ) { return Array . isArray ( workspace . workspaceFolders ) && workspace . workspaceFolders . length > 0 ; } public getConfiguration ( section ? , resource ? ) { return workspace . getConfiguration ( section , resource || null ) ; } public getWorkspaceFolder ( uri ) { return uri ? workspace . getWorkspaceFolder ( uri ) : undefined ; } public asRelativePath ( pathOrUri , includeWorkspaceFolder ? ) { return workspace . asRelativePath ( pathOrUri , includeWorkspaceFolder ) ; } public createFileSystemWatcher ( globPattern , _ignoreCreateEvents ? , ignoreChangeEvents ? , ignoreDeleteEvents ? ) { return workspace . createFileSystemWatcher ( globPattern , ignoreChangeEvents , ignoreChangeEvents , ignoreDeleteEvents ) ; } public findFiles ( include , exclude ? , maxResults ? , token ? ) { return workspace . findFiles ( include , exclude , maxResults , token ) ; } public getWorkspaceFolderIdentifier ( resource , defaultValue = '' ) { const workspaceFolder = resource ? workspace . getWorkspaceFolder ( resource ) : undefined ; return workspaceFolder ? workspaceFolder . uri . fsPath : defaultValue ; } }