import * as vscode from 'vscode' ; import parseDepsFromFile from './parseDepsFromFile' ; import { BehaviorSubject } from 'rxjs' ; import { startWith , distinctUntilChanged , map } from 'rxjs/operators' ; import { vscToObservable } from '../util' ; const isEqual = require ( 'lodash/fp/isEqual' ) ; const path = require ( 'path' ) ; export default class Runtime { deps$ : BehaviorSubject < string [ ] > ; _watcher : vscode . FileSystemWatcher ; constructor ( public runtimePath ) { this . _watcher = vscode . workspace . createFileSystemWatcher ( path . join ( runtimePath , 'Cargo.toml' ) , true , false , true ) ; const fileChange$ = vscToObservable ( this . _watcher . onDidChange . bind ( this . _watcher ) ) ; this . deps$ = new BehaviorSubject ( [ ] as string [ ] ) ; fileChange$ . pipe ( startWith ( null ) , map ( ( ) => parseDepsFromFile ( path . join ( runtimePath , 'Cargo.toml' ) ) ) , distinctUntilChanged ( isEqual ) ) . subscribe ( this . deps$ ) ; } dispose ( ) { this . _watcher . dispose ( ) ; } }