From e08c8aa388dfdb10a281c37833cbab55e40840a8 Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Thu, 19 Oct 2023 11:27:11 +0200 Subject: [PATCH 1/2] Add more automplete specs for bundle + stub some gems --- src/_utils/spec.ts | 7 +++++++ src/bundle.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++-- src/gem.ts | 32 ++++++++++++++++---------------- src/rspec.ts | 16 ++++++++++++++++ src/rubocop.ts | 23 +++++++++++++++++++++++ 5 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 src/_utils/spec.ts create mode 100644 src/rspec.ts create mode 100644 src/rubocop.ts diff --git a/src/_utils/spec.ts b/src/_utils/spec.ts new file mode 100644 index 000000000000..dec98fa79bba --- /dev/null +++ b/src/_utils/spec.ts @@ -0,0 +1,7 @@ +// eslint-disable-next-line @withfig/fig-linter/no-missing-default-export +export const specToSuggestions = (spec: Fig.Spec): Fig.Suggestion => { + return { + name: spec.name, + ...("icon" in spec && { icon: spec.icon }), + }; +}; diff --git a/src/bundle.ts b/src/bundle.ts index e97e8fab6c98..d7ad5b98d87f 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -1,3 +1,19 @@ +import rails from "./rails"; +import rubocop from "./rubocop"; +import rspec from "./rspec"; +import rake from "./rake"; +import { gemsGenerator } from "./gem"; +import pry from "./pry"; +import { specToSuggestions } from "./_utils/spec"; + +const EXEC_SUGGESTIONS: Fig.Suggestion[] = [ + specToSuggestions(rails), + specToSuggestions(rubocop), + specToSuggestions(rspec), + specToSuggestions(rake), + specToSuggestions(pry), +]; + const gemfileGemsGenerator: Fig.Generator = { script: "bundle list --name-only", postProcess: (out) => { @@ -175,7 +191,30 @@ const completionSpec: Fig.Spec = { description: "Pass all file descriptors to the new process", }, ], - args: { isCommand: true }, + args: { + isCommand: true, + generators: { + script: "bundle list --name-only", + cache: { + cacheByDirectory: true, + strategy: "stale-while-revalidate", + ttl: 60 * 60, + }, + postProcess: (out) => { + const gems = out.split("\n"); + + return EXEC_SUGGESTIONS.filter((spec) => { + if (spec.name === "rspec") { + return gems.includes("rspec-core"); + } + + return gems.includes( + typeof spec.name === "string" ? spec.name : spec.name[0] + ); + }); + }, + }, + }, }, { name: "config", args: {} }, { name: "help" }, @@ -184,7 +223,10 @@ const completionSpec: Fig.Spec = { { name: "add", description: "Add gem to the Gemfile and run bundle install", - args: {}, + args: { + name: "gem", + generators: gemsGenerator, + }, options: [ { name: ["--version", "-v"], diff --git a/src/gem.ts b/src/gem.ts index e484366bdaef..36565d42e92e 100644 --- a/src/gem.ts +++ b/src/gem.ts @@ -1,4 +1,4 @@ -const gems: Fig.Generator = { +export const gemsGenerator: Fig.Generator = { trigger: () => true, custom: async (tokens, executeShellCommand) => { const searchTerm = tokens[tokens.length - 1]; @@ -172,7 +172,7 @@ const completionSpec: Fig.Spec = { description: "Install a gem into the local repository", args: { name: "GEMNAME", - generators: gems, + generators: gemsGenerator, debounce: true, }, options: [ @@ -282,7 +282,7 @@ const completionSpec: Fig.Spec = { description: "Check a gem repository for added or missing files", args: { name: "GEMNAME", - generators: gems, + generators: gemsGenerator, debounce: true, isOptional: true, }, @@ -345,7 +345,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEMNAME", description: "Name of gem to cleanup", - generators: gems, + generators: gemsGenerator, debounce: true, isOptional: true, }, @@ -384,7 +384,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEMNAME", description: "Name of gem to list contents for", - generators: gems, + generators: gemsGenerator, debounce: true, }, options: [ @@ -533,7 +533,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEMNAME", description: "Name of gem to download", - generators: gems, + generators: gemsGenerator, debounce: true, }, options: [ @@ -634,7 +634,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEMNAME", description: "Name of the gem to print information about", - generators: gems, + generators: gemsGenerator, debounce: true, }, options: [ @@ -678,7 +678,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEMNAME", description: "Name of the gem to print information about", - generators: gems, + generators: gemsGenerator, debounce: true, }, options: [ @@ -708,7 +708,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEMNAME", description: "Name of the gem to print information about", - generators: gems, + generators: gemsGenerator, debounce: true, isOptional: true, }, @@ -723,7 +723,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEMNAME", description: "Name of the gem to print information about", - generators: gems, + generators: gemsGenerator, debounce: true, }, requiresSeparator: true, @@ -828,7 +828,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEMNAME", description: "Gem to generate documentation for (unless –all)", - generators: gems, + generators: gemsGenerator, debounce: true, isOptional: true, }, @@ -991,7 +991,7 @@ const completionSpec: Fig.Spec = { { name: "GEMFILE", description: "Name of gem to show the gemspec for", - generators: gems, + generators: gemsGenerator, debounce: true, }, { @@ -1054,7 +1054,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEMNAME", description: "Name of gem to unpack", - generators: gems, + generators: gemsGenerator, debounce: true, }, options: [ @@ -1088,7 +1088,7 @@ const completionSpec: Fig.Spec = { args: { name: "GEM", description: "Name of gem", - generators: gems, + generators: gemsGenerator, debounce: true, }, options: [ @@ -1116,7 +1116,7 @@ const completionSpec: Fig.Spec = { description: "Uninstall gems from the local repository", args: { name: "GEMNAME", - generators: gems, + generators: gemsGenerator, debounce: true, }, options: [ @@ -1297,7 +1297,7 @@ const completionSpec: Fig.Spec = { description: "Manage gem owners of a gem on the push server", args: { name: "GEMNAME", - generators: gems, + generators: gemsGenerator, debounce: true, }, options: [ diff --git a/src/rspec.ts b/src/rspec.ts new file mode 100644 index 000000000000..b02605b4c2fc --- /dev/null +++ b/src/rspec.ts @@ -0,0 +1,16 @@ +const completionSpec: Fig.Spec = { + name: "rspec", + icon: "https://rspec.info/images/logo.png", + description: + "Behaviour Driven Development for Ruby. Making TDD Productive and Fun", + args: { + name: "file", + description: "The file to run", + default: "./spec", + generators: { + template: ["filepaths", "folders"], + }, + }, +}; + +export default completionSpec; diff --git a/src/rubocop.ts b/src/rubocop.ts new file mode 100644 index 000000000000..542e849a7b99 --- /dev/null +++ b/src/rubocop.ts @@ -0,0 +1,23 @@ +const completionSpec: Fig.Spec = { + name: "rubocop", + description: + "A Ruby static code analyzer and formatter, based on the community Ruby style guide", + icon: "https://github.com/rubocop/rubocop/blob/master/logo/rubo-logo-symbol.png?raw=true", + args: { + name: "file", + template: "filepaths", + isVariadic: true, + }, + options: [ + { + name: ["-a", "--autocorrect"], + description: "Autocorrect offenses (only when it's safe)", + }, + { + name: ["-A", "--autocorrect-all"], + description: "Autocorrect offenses (safe and unsafe)", + }, + ], +}; + +export default completionSpec; From 7a2d1bc36a64bc050b59684339597240b75a9041 Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Sat, 2 Dec 2023 22:52:12 +0100 Subject: [PATCH 2/2] Fix image size --- src/bundle.ts | 2 +- src/rubocop.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bundle.ts b/src/bundle.ts index 519b0bc63812..a4f57d2c4201 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -194,7 +194,7 @@ const completionSpec: Fig.Spec = { args: { isCommand: true, generators: { - script: "bundle list --name-only", + script: ["bundle", "list", "--name-only"], cache: { cacheByDirectory: true, strategy: "stale-while-revalidate", diff --git a/src/rubocop.ts b/src/rubocop.ts index 542e849a7b99..c250b48d8d74 100644 --- a/src/rubocop.ts +++ b/src/rubocop.ts @@ -2,7 +2,7 @@ const completionSpec: Fig.Spec = { name: "rubocop", description: "A Ruby static code analyzer and formatter, based on the community Ruby style guide", - icon: "https://github.com/rubocop/rubocop/blob/master/logo/rubo-logo-symbol.png?raw=true", + icon: "https://github.com/rubocop/rubocop/blob/master/assets/logo.png?raw=true", args: { name: "file", template: "filepaths",