Remove try/catch in excmd completion

This commit removes the try/catch in the excmd completion source and
instead makes the ExcmdCompletionOption constructor default to a string
for missing values.

This is useful for three reasons:
- The try/catch discarded excmds that didn't have a type/documentation,
  but being able to autocomplete the name of these functions could still
  be useful
- Try/catch are usually expensive
- TypeScript wrongly complained about a missing parenthesis when the
  try/catch was there
This commit is contained in:
glacambre 2018-08-16 17:09:13 +02:00
parent e1bb76600e
commit 5eae45d0a0
No known key found for this signature in database
GPG key ID: B9625DB1767553AC

View file

@ -7,8 +7,8 @@ class ExcmdCompletionOption extends Completions.CompletionOptionHTML
public fuseKeys = [] public fuseKeys = []
constructor( constructor(
public value: string, public value: string,
public ttype: string, public ttype: string = "",
public documentation: string, public documentation: string = "",
) { ) {
super() super()
this.fuseKeys.push(this.value) this.fuseKeys.push(this.value)
@ -49,13 +49,7 @@ export class ExcmdCompletionSource extends Completions.CompletionSourceFuse {
let fns = Metadata.everything["src/excmds.ts"] let fns = Metadata.everything["src/excmds.ts"]
this.options = (await this.scoreOptions( this.options = (await this.scoreOptions(
Object.keys(fns).filter(f => f.startsWith(exstr)), Object.keys(fns).filter(f => f.startsWith(exstr)),
)).map(f => { )).map(f => new ExcmdCompletionOption(f, fns[f].type, fns[f].doc))
try {
return new ExcmdCompletionOption(f, fns[f].type, fns[f].doc)
} catch {
return new ExcmdCompletionOption("", "", "")
}
})
this.options.forEach(o => (o.state = "normal")) this.options.forEach(o => (o.state = "normal"))
this.updateChain() this.updateChain()
} }