import { Uri , commands , UriHandler } from 'vscode' ; import { SESSION_COMMAND_LOAD } from './SessionSourceControl' ; /** Handles system-wide URI requests. Note that each session can register only one UriHandler! */ export class SessionUriHandler implements UriHandler { handlers : UriMatchHandler [ ] ; constructor ( ) { this . handlers = [ new ReadOnlySessionUriHandler ( ) , new ReadWriteSessionUriHandler ( ) ] ; } handleUri ( uri ) { this . handlers . filter ( h => h . matches ( uri ) ) . forEach ( h => h . handle ( uri ) ) ; } } interface UriMatchHandler { matches ( uri ) : boolean ; handle ( uri ) : void ; } class SingleArgumentUriHandler implements UriMatchHandler { constructor ( private pattern , private command ) { } matches ( uri ) { this . pattern . lastIndex = 0 ; const matchGroups = this . pattern . exec ( uri . path ) ; return matchGroups !== null ; } handle ( uri ) { this . pattern . lastIndex = 0 ; const matchGroups = this . pattern . exec ( uri . path ) ; if ( matchGroups ) { const argumentValue = matchGroups [ 1 ] ; commands . executeCommand ( this . command , argumentValue ) ; } } } class ReadOnlySessionUriHandler extends SingleArgumentUriHandler { constructor ( ) { super ( /\/planning.domains\/session\/(\w+)$/i , SESSION_COMMAND_LOAD ) ; } } class ReadWriteSessionUriHandler extends SingleArgumentUriHandler { constructor ( ) { super ( /\/planning.domains\/session\/edit\/(\w+)$/i , SESSION_COMMAND_LOAD ) ; } }