Skip to content

Feature/file watcher #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
support file system watchers (listeners)
  • Loading branch information
ShMcK committed Nov 5, 2019
commit f983329503f7e946e8730edfe3a9bc91f4b029fe
20 changes: 19 additions & 1 deletion src/actions/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,33 @@ const runCommands = async (commands: string[], language: string = 'JAVASCRIPT')
}
}

// collect active file watchers (listeners)
const watchers: {[key: string]: vscode.FileSystemWatcher} = {}

const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, commits, files}: G.StepActions): Promise<void> => {
const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, commits, files, listeners}: G.StepActions): Promise<void> => {
// run commits
if (commits) {
for (const commit of commits) {
await git.loadCommit(commit)
}
}

// run file watchers (listeners)
if (listeners) {
for (const listener of listeners) {
if (!watchers[listener]) {
watchers[listener] = vscode.workspace.createFileSystemWatcher(listener)
watchers[listener].onDidChange(() => {
// trigger save
vscode.commands.executeCommand('coderoad.run_test')
// cleanup watcher
watchers[listener].dispose()
delete watchers[listener]
})
}
}
}

// run command
if (commands) {
await runCommands(commands)
Expand Down
8 changes: 2 additions & 6 deletions typings/graphql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export type StepActions = {
commits: Array<Scalars['Sha1']>
files?: Maybe<Array<Scalars['String']>>
commands?: Maybe<Array<Scalars['String']>>
listeners?: Maybe<Array<Scalars['String']>>
}

export type TestRunner = 'JEST'
Expand Down Expand Up @@ -494,6 +495,7 @@ export type StepActionsResolvers<
commits?: Resolver<Array<ResolversTypes['Sha1']>, ParentType, ContextType>
files?: Resolver<Maybe<Array<ResolversTypes['String']>>, ParentType, ContextType>
commands?: Resolver<Maybe<Array<ResolversTypes['String']>>, ParentType, ContextType>
listeners?: Resolver<Maybe<Array<ResolversTypes['String']>>, ParentType, ContextType>
}

export type TutorialResolvers<
Expand Down Expand Up @@ -632,9 +634,3 @@ export interface IntrospectionResultData {
}[]
}
}
const result: IntrospectionResultData = {
__schema: {
types: [],
},
}
export default result