forked from withfig/autocomplete
-
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.
Merge remote-tracking branch 'origin/master' into feat/use_esbuild
- Loading branch information
Showing
9 changed files
with
2,412 additions
and
104 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,68 @@ | ||
const bazelBuildFiles: Fig.Generator = { | ||
script: `FILES=( $(find ./ -name BUILD) ); for f in $FILES; do echo "----$f"; cat "$f"; done`, | ||
// returns filepaths and contents in the form below, note the "----" to indicate the filepath | ||
// ----.//lib/BUILD | ||
// load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
||
// cc_library( | ||
// name = "hello-time", | ||
// srcs = ["hello-time.cc"], | ||
// hdrs = ["hello-time.h"], | ||
// visibility = ["//main:__pkg__"], | ||
// ) | ||
|
||
postProcess: function (out) { | ||
const lines = out.split("\n"); | ||
// return lines | ||
const targets = []; | ||
let currPath = ""; | ||
for (let i = 0; i < lines.length; i++) { | ||
const isFilepath = lines[i].match("----.(.*)/BUILD"); | ||
const isBazelTarget = lines[i].match('name = "(.*)"'); | ||
if (isFilepath) { | ||
currPath = isFilepath[1] + ":"; | ||
} else if (isBazelTarget) { | ||
targets.push({ | ||
name: currPath + isBazelTarget[1], | ||
description: "bazel target", | ||
icon: "🎯", | ||
priority: 80, | ||
}); | ||
} | ||
} | ||
return targets; | ||
}, | ||
}; | ||
|
||
const completionSpec: Fig.Spec = { | ||
name: "bazel", | ||
description: "Bazel the build system!", | ||
subcommands: [ | ||
{ | ||
name: "run", | ||
description: "Runs the specified target.", | ||
args: { | ||
name: "BUILD file", | ||
generators: bazelBuildFiles, | ||
}, | ||
}, | ||
{ | ||
name: "test", | ||
description: "Builds and runs the specified test targets.", | ||
args: { | ||
name: "BUILD file", | ||
generators: bazelBuildFiles, | ||
}, | ||
}, | ||
{ | ||
name: "build", | ||
description: "Builds the specified targets..", | ||
args: { | ||
name: "BUILD file", | ||
generators: bazelBuildFiles, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export default completionSpec; |
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,98 @@ | ||
interface ComposerArgument { | ||
name: string; | ||
is_required: boolean; | ||
is_array: boolean; | ||
description: string; | ||
default: null | string | Array<string>; | ||
} | ||
|
||
interface ComposerOption { | ||
name: string; | ||
shortcut: string; | ||
accept_value: boolean; | ||
is_value_required: boolean; | ||
is_multiple: boolean; // not supported by fig | ||
description: string; | ||
default: null | boolean; // not supported by fig | ||
} | ||
|
||
interface ComposerCommandDefinition { | ||
arguments: Record<string, ComposerArgument>; | ||
options: Record<string, ComposerOption>; | ||
} | ||
|
||
interface ComposerCommand { | ||
name: string; | ||
usage: string[]; // this is actually generated by fig | ||
description: string; | ||
help: string; // | ||
definition: ComposerCommandDefinition; | ||
} | ||
|
||
interface ComposerListOutput { | ||
commands: ComposerCommand[]; | ||
} | ||
|
||
const completionSpec: Fig.Spec = { | ||
name: "composer", | ||
description: "Composer Command", | ||
|
||
generateSpec: async (context, executeShellCommand) => { | ||
const jsonList = await executeShellCommand("composer list --format=json"); | ||
const subcommands: Fig.Subcommand[] = []; | ||
|
||
try { | ||
const data: ComposerListOutput = JSON.parse(jsonList); | ||
for (const command of data.commands) { | ||
subcommands.push({ | ||
name: command.name, | ||
description: command.description, | ||
icon: "https://getcomposer.org/img/logo-composer-transparent5.png", | ||
|
||
args: Object.keys(command.definition.arguments).map((argKey) => { | ||
const arg = command.definition.arguments[argKey]; | ||
const argDefault = arg.default | ||
? Array.isArray(arg.default) | ||
? arg.default[0] | ||
: arg.default | ||
: undefined; | ||
|
||
return { | ||
name: arg.name, | ||
description: arg.description, | ||
isOptional: !arg.is_required, | ||
default: argDefault, | ||
variadic: arg.is_array, | ||
}; | ||
}), | ||
|
||
options: Object.keys(command.definition.options).map((optionKey) => { | ||
const option = command.definition.options[optionKey]; | ||
const names = [option.name]; | ||
|
||
const shortCut = option.shortcut; | ||
if (shortCut.trim().length > 0) { | ||
names.push(shortCut); | ||
} | ||
|
||
return { | ||
name: names, | ||
description: option.description, | ||
required: option.is_value_required, | ||
args: option.accept_value ? {} : undefined, | ||
}; | ||
}), | ||
}); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
|
||
return { | ||
name: "composer", | ||
subcommands, | ||
}; | ||
}, | ||
}; | ||
|
||
export default completionSpec; |
Oops, something went wrong.