Skip to content

Commit

Permalink
Avoiding using chokidar
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Jan 8, 2019
1 parent c82173a commit 8357ab7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@
"@types/lodash": "^4.14.118",
"@types/node": "^10.12.8",
"absolute": "0.0.1",
"chokidar": "^2.0.3",
"json5": "^0.5.1",
"lodash": "^4.17.4",
"mkdirp": "^0.5.1",
Expand Down
15 changes: 8 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* IMPORT */

import * as _ from 'lodash';
import * as chokidar from 'chokidar';
import * as JSON5 from 'json5';
import * as os from 'os';
import * as path from 'path';
Expand Down Expand Up @@ -164,27 +163,29 @@ const Config = {
async onChangeListener () {

let config = await Config.get (),
watcher;
watcher: vscode.FileSystemWatcher;

async function handleChange () {

const newConfig = await Config.get ();

if ( _.isEqual ( config, newConfig ) ) return;

if ( config.configPath !== newConfig.configPath ) watchChokidar ();
if ( config.configPath !== newConfig.configPath ) watchConfig ();

config = newConfig;

Config.onChangeCallbacks.forEach ( callback => callback ( config ) );

}

function watchChokidar () {
function watchConfig () {

if ( watcher ) watcher.close ();
if ( watcher ) watcher.dispose ();

watcher = chokidar.watch ( config.configPath ).on ( 'all', handleChange );
watcher = vscode.workspace.createFileSystemWatcher ( config.configPath );

watcher.onDidChange ( handleChange );

}

Expand All @@ -194,7 +195,7 @@ const Config = {

}

watchChokidar ();
watchConfig ();
watchWorkspaceConfiguration ();

},
Expand Down

0 comments on commit 8357ab7

Please sign in to comment.