@@ -4,33 +4,11 @@ import * as vscode from 'vscode'
44import * as git from '../services/git'
55import node from '../services/node'
66
7- // interface ErrorMessageFilter {
8- // [lang: string]: {
9- // [key: string]: string
10- // }
11- // }
12-
13- // TODO: should be loaded on startup based on language
14- // const commandErrorMessageFilter: ErrorMessageFilter = {
15- // #"diff-47d0c00fa3c186f7fc510aad6c9706e5d40404c1952033d7c544d0317de2b80b-16-6-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">16
- // 'node-gyp': 'Error running npm setup command'
17- // }
18- // }
19-
20- // TODO: pass command and command name down for filtering. Eg. JAVASCRIPT, 'npm install'
217const runCommands = async ( commands :string [ ] ) => {
228for ( const command of commands ) {
239const { stdout, stderr} = await node . exec ( command )
2410if ( stderr ) {
2511console . error ( stderr )
26- // language specific error messages from running commands
27- // const filteredMessages = Object.keys(commandErrorMessageFilter[language])
28- // for (const message of filteredMessages) {
29- // if (stderr.match(message)) {
30- // // ignored error
31- // throw new Error('Error running setup command')
32- // }
33- // }
3412}
3513console . log ( `run command:${ command } ` , stdout )
3614}
@@ -44,64 +22,52 @@ const disposeWatcher = (listener: string) => {
4422delete watchers [ listener ]
4523}
4624
47- const setupActions = async ( workspaceRoot :vscode . WorkspaceFolder , actions :G . StepActions ) :Promise < void > => {
48- const { commands, commits, files, listeners} = actions
49- // run commits
50- if ( commits ) {
51- for ( const commit of commits ) {
52- await git . loadCommit ( commit )
53- }
54- }
55-
56- // run file watchers (listeners)
57- if ( listeners ) {
58- console . log ( 'listeners' )
59- for ( const listener of listeners ) {
60- if ( ! watchers [ listener ] ) {
61- const rootUri = vscode . workspace . getWorkspaceFolder ( workspaceRoot . uri )
62- const pattern = new vscode . RelativePattern ( rootUri ! , listener ) // eslint-disable-line
63- console . log ( pattern )
64- const listen = vscode . workspace . createFileSystemWatcher ( pattern )
65- watchers [ listener ] = listen
66- watchers [ listener ] . onDidChange ( ( ) => {
67- console . log ( 'onDidChange' )
68- // trigger save
69- vscode . commands . executeCommand ( 'coderoad.run_test' , null , ( ) => {
70- // cleanup watcher on success
71- disposeWatcher ( listener )
72- } )
25+ const loadListeners = ( listeners :string [ ] , workspaceUri :vscode . Uri ) => {
26+ for ( const listener of listeners ) {
27+ if ( ! watchers [ listener ] ) {
28+ const rootUri = vscode . workspace . getWorkspaceFolder ( workspaceUri )
29+ const pattern = new vscode . RelativePattern ( rootUri ! , listener ) // eslint-disable-line
30+ console . log ( pattern )
31+ const listen = vscode . workspace . createFileSystemWatcher ( pattern )
32+ watchers [ listener ] = listen
33+ watchers [ listener ] . onDidChange ( ( ) => {
34+ console . log ( 'onDidChange' )
35+ // trigger save
36+ vscode . commands . executeCommand ( 'coderoad.run_test' , null , ( ) => {
37+ // cleanup watcher on success
38+ disposeWatcher ( listener )
7339} )
74- watchers [ listener ] . onDidCreate ( ( ) => {
75- console . log ( ' onDidCreate' )
76- // trigger save
77- vscode . commands . executeCommand ( 'coderoad.run_test' , null , ( ) => {
78- // cleanup watcher on success
79- disposeWatcher ( listener )
80- } )
40+ } )
41+ watchers [ listener ] . onDidCreate ( ( ) => {
42+ console . log ( 'onDidCreate' )
43+ // trigger save
44+ vscode . commands . executeCommand ( 'coderoad.run_test' , null , ( ) => {
45+ // cleanup watcher on success
46+ disposeWatcher ( listener )
8147} )
82- watchers [ listener ] . onDidDelete ( ( ) => {
83- console . log ( ' onDidDelete' )
84- // trigger save
85- vscode . commands . executeCommand ( 'coderoad.run_test' , null , ( ) => {
86- // cleanup watcher on success
87- disposeWatcher ( listener )
88- } )
48+ } )
49+ watchers [ listener ] . onDidDelete ( ( ) => {
50+ console . log ( 'onDidDelete' )
51+ // trigger save
52+ vscode . commands . executeCommand ( 'coderoad.run_test' , null , ( ) => {
53+ // cleanup watcher on success
54+ disposeWatcher ( listener )
8955} )
90- }
91- }
92- } else {
93- // remove all watchers
94- for ( const listener of Object . keys ( watchers ) ) {
95- disposeWatcher ( listener )
56+ } )
9657}
9758}
59+ }
9860
99- // run command
100- if ( commands ) {
101- await runCommands ( commands )
61+ const setupActions = async ( workspaceRoot :vscode . WorkspaceFolder , actions :G . StepActions ) :Promise < void > => {
62+ const { commands, commits, files, listeners} = actions
63+ // 1. run commits
64+ if ( commits ) {
65+ for ( const commit of commits ) {
66+ await git . loadCommit ( commit )
67+ }
10268}
10369
104- // open files
70+ //2. open files
10571if ( files ) {
10672for ( const filePath of files ) {
10773try {
@@ -131,6 +97,21 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, actions: G.St
13197}
13298}
13399}
100+
101+ // 3. start file watchers (listeners)
102+ if ( listeners ) {
103+ loadListeners ( listeners , workspaceRoot . uri )
104+ } else {
105+ // remove all watchers
106+ for ( const listener of Object . keys ( watchers ) ) {
107+ disposeWatcher ( listener )
108+ }
109+ }
110+
111+ // 4. run command
112+ if ( commands ) {
113+ await runCommands ( commands )
114+ }
134115}
135116
136117export default setupActions