Skip to content

Commit

Permalink
add typos.arguments configuration
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
chemzqm committed Sep 13, 2022
1 parent e06bacf commit 428a431
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
10 changes: 9 additions & 1 deletion package.json
Expand Up @@ -50,6 +50,14 @@
"default": "typos",
"description": "Command used to invoke typos."
},
"typos.arguments": {
"type": "array",
"default": [],
"description": "Additional arguments used to invoke typos",
"items": {
"type": "string"
}
},
"typos.disabledFiletypes": {
"type": "array",
"default": [],
Expand All @@ -66,7 +74,7 @@
"typos.listTyposArguments": {
"type": "array",
"default": [],
"description": "Additional arguments of typos command used on list.",
"description": "Additional arguments of typos command used on list, should not contains --color and --format.",
"items": {
"type": "string"
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -30,6 +30,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
let config = workspace.getConfiguration('typos', doc.uri)
return new TyposBuffer(doc, {
command: config.get('command', 'typos'),
arguments: config.get('arguments', []),
disabledFiletypes: config.get<string[]>('disabledFiletypes', []),
highlightGroup: config.get('highlightGroup', 'SpellBad'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/item.ts
Expand Up @@ -7,6 +7,7 @@ export const NAMESPACE = 'typos'
export interface TyposConfig {
command: string
disabledFiletypes: string[]
arguments: string[]
highlightGroup: string
}

Expand Down Expand Up @@ -84,7 +85,7 @@ export default class TyposBuffer implements BufferSyncItem {
let cmd = this.config.command
let tokenSource = this.tokenSource = new CancellationTokenSource()
let token = tokenSource.token
getTyposBuffer(this.config.command, doc.textDocument.lines, token).then(typos => {
getTyposBuffer(this.config.command, this.config.arguments, doc.textDocument.lines, token).then(typos => {
if (token.isCancellationRequested) return
this.typos = typos
this.info(`${typos.length} typos found for ${doc.uri}.`)
Expand Down
4 changes: 2 additions & 2 deletions src/util.ts
Expand Up @@ -64,10 +64,10 @@ export function parseLine(line: string): TyposItem | undefined {
}
}

export function getTyposBuffer(cmd: string, lines: ReadonlyArray<string>, token: CancellationToken): Promise<ReadonlyArray<TyposItem>> {
export function getTyposBuffer(cmd: string, args: string[], lines: ReadonlyArray<string>, token: CancellationToken): Promise<ReadonlyArray<TyposItem>> {
let res: TyposItem[] = []
return new Promise((resolve, reject) => {
spawnCommand(cmd, ['--format=json', '-'], lines, token, line => {
spawnCommand(cmd, [...args, '--format=json', '-'], lines, token, line => {
let item = parseLine(line)
if (item) res.push(item)
}).then(() => {
Expand Down

0 comments on commit 428a431

Please sign in to comment.