This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anantachai Saothong (Manta)
committed
Mar 26, 2017
1 parent
76382c6
commit c81a53d
Showing
9 changed files
with
157 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as vscode from 'vscode' | ||
|
||
export default class TextItem implements vscode.QuickPickItem { | ||
readonly label: string | ||
readonly description: string = '' | ||
|
||
constructor(name: string) { | ||
this.label = name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as vscode from 'vscode' | ||
import * as path from 'path' | ||
import * as _ from 'lodash' | ||
import { match as minimatch } from 'minimatch' | ||
|
||
import * as Shared from './Shared' | ||
import FileInfo from './FileInfo' | ||
|
||
export default class TextPattern { | ||
private config: TextConfiguration | ||
readonly interpolate: (object) => string | ||
|
||
get name() { | ||
return this.config.name | ||
} | ||
|
||
constructor(config: TextConfiguration) { | ||
this.config = config | ||
|
||
// Escape `${0:var}` to `$\{0:${var}\}` | ||
let block = _.isArray(config.code) ? config.code.join(Shared.getEndOfLine()) : config.code | ||
block = block.split(/\$\{/).map((chunk, order, array) => { | ||
if (order === 0 || /^\d+:/.test(chunk) === false) { | ||
return chunk | ||
} | ||
|
||
let index = chunk.length | ||
while (--index && index >= 0) { | ||
if (chunk[index] === '}' && index > 0 && chunk[index - 1] !== '\\') { | ||
break | ||
} | ||
} | ||
|
||
if (index >= 0) { | ||
const colon = chunk.indexOf(':') | ||
return '$\\{' + chunk.substring(0, colon) + ':${' + chunk.substring(colon + 1, index).trim() + '}\\}' + chunk.substring(index + 1) | ||
} else { | ||
return chunk | ||
} | ||
}).join('') | ||
|
||
const interpolate = _.template(block) | ||
this.interpolate = (scope) => { | ||
// Unescape `$\{...\}` | ||
return interpolate(scope).replace(/\$\\\{/g, '${').replace(/\\\}/g, '}') | ||
} | ||
} | ||
|
||
check(document: vscode.TextDocument): boolean { | ||
if (this.config.when) { | ||
try { | ||
return Boolean(_.template('${' + this.config.when + '}')({ | ||
_, // Lodash | ||
minimatch, | ||
path, | ||
activeDocument: document, | ||
activeFileInfo: new FileInfo(document.fileName), | ||
})) | ||
} catch (ex) { | ||
console.error(ex) | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters