Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cargo and rustc completion. #2409

Merged
merged 1 commit into from Oct 27, 2015
Merged

Conversation

@bheesham
Copy link
Contributor

@bheesham bheesham commented Sep 19, 2015

I've added completion for Rust and Cargo.

@bheesham bheesham force-pushed the bheesham:rustc-cargo-completion branch 2 times, most recently from e3fa126 to abe927e Sep 19, 2015
@faho
Copy link
Member

@faho faho commented Sep 19, 2015

For the rustc completion: You can add descriptions to any completion option by separating the option and it's description with a tab character and the next option with a newline.

I.e. something like this should give properly described options:

printf "%s\t%s\n" box-pointers "some text that describes box-pointers" fat-ptr-transmutes "some description for fat-ptr-transmutes"

(Note that I'm not a rust user, but to me some of these seem rather esoteric, so descriptions seem useful)

@bheesham bheesham force-pushed the bheesham:rustc-cargo-completion branch from abe927e to b30cd30 Sep 22, 2015
@bheesham
Copy link
Contributor Author

@bheesham bheesham commented Sep 22, 2015

Descriptions for flags have now been added. I ended up writing a Python script to help me out since I'm not entirely sure how to play with strings using Fish.

@faho
Copy link
Member

@faho faho commented Sep 22, 2015

Did you mean to commit and push that?

I ended up writing a Python script

Can't say I'm a massive fan. Push it and I'll take a look.

@bheesham
Copy link
Contributor Author

@bheesham bheesham commented Sep 22, 2015

No I didn't since this was only for completions. The script is over here: https://github.com/bheesham/rust.fish/blob/master/gen.py

@faho
Copy link
Member

@faho faho commented Sep 22, 2015

No I didn't since this was only for completions.

Ah okay, it's for generating completion scripts. I thought you had written a helper that is called at runtime. This is kinda neat, but I'd still like it more if we could generate the completions on the user's machine since they then perfectly match the rust version (since that's apparently possible).

What you basically do here is call rust -C help and rust -W help and bang the output into the shape we want with some regex-magic, right? If so, we usually use sed for that (and I don't like the idea of asking for other utilities unrelated to the command to be installed, even something as ubiquitous as python), but we now also have, hot off the presses, our new cool string tool, with its subcommand string match (basically grep) and string replace (basically sed's "s/PATTERN/REPLACEMENT/").

I could also take a look, but I'll have to download rust first and my current internet connection won't allow for that, so I'll try to get to it over the weekend.

@bheesham
Copy link
Contributor Author

@bheesham bheesham commented Sep 23, 2015

Yep, that's exactly what the script does.

Ah yeah. I saw the pull request for string. I'll refactor some of the code to start using it when I get a chance to.

@faho faho self-assigned this Sep 26, 2015
@faho
Copy link
Member

@faho faho commented Oct 5, 2015

@bheesham: Any progress?

@bheesham
Copy link
Contributor Author

@bheesham bheesham commented Oct 12, 2015

Ah crap, nope. This completely escaped my mind for a bit.

I'll pick this issue back up around Thursday.

@bheesham bheesham force-pushed the bheesham:rustc-cargo-completion branch 2 times, most recently from 573d972 to 0884930 Oct 16, 2015
@bheesham
Copy link
Contributor Author

@bheesham bheesham commented Oct 17, 2015

@faho , I'm now using the string commands. All I'm using the Python script for now is to not have to write complete -c rustc and complete -c cargo.

I've been able to bring the filesize of rustc.fish down from 28.3kb to 2.66kb!

@bheesham bheesham force-pushed the bheesham:rustc-cargo-completion branch from 0884930 to cd0feeb Oct 19, 2015
@faho
Copy link
Member

@faho faho commented Oct 20, 2015

How well does this perform? It does quite a lot of math calls.

@bheesham bheesham force-pushed the bheesham:rustc-cargo-completion branch from cd0feeb to 6696faa Oct 20, 2015
@bheesham
Copy link
Contributor Author

@bheesham bheesham commented Oct 21, 2015

Not too well I think.

The current version (run the rustc -{Z,W,C} help command, parse output, iterate) sources in around 390ms on my laptop. The previous version which used Python to generate the completions sources in about 9ms.

I guess my next challenge is to find a way to generate completions without heavily relying on math.

@bheesham bheesham force-pushed the bheesham:rustc-cargo-completion branch from 6696faa to acab102 Oct 24, 2015
@bheesham
Copy link
Contributor Author

@bheesham bheesham commented Oct 24, 2015

Cool. The time it takes to source is now significantly less than what it was before.

It's around 88ms for me. Still not as fast as file Python generates, but hey, it's a major improvement.

@bheesham
Copy link
Contributor Author

@bheesham bheesham commented Oct 24, 2015

I did run into a strange problem though.

rustc -W help | string replace -r -i '(\s+)(.+)(\s+)(allow|warn|deny|forbid)(\s+){2}([^\n]+)' '$2 $6' outputs the wrong thing. It keeps in the header and footer of the help message, which is weird.

Output:


Available lint options:
    -W <foo>           Warn about <foo>
    -A <foo>           Allow <foo>
    -D <foo>           Deny <foo>
    -F <foo>           Forbid <foo> (deny, and deny all overrides)


Lint checks provided by rustc:

                             name  default  meaning
                             ----  -------  -------
box-pointers  use of owned (Box type) heap memory
fat-ptr-transmutes  detects transmutes of fat pointers
missing-copy-implementations  detects potentially-forgotten implementations of `Copy`
missing-debug-implementations  detects missing implementations of fmt::Debug
missing-docs  detects missing documentation for public members
trivial-casts  detects trivial casts which could be removed
trivial-numeric-casts  detects trivial casts of numeric types which could be removed
unsafe-code  usage of `unsafe` code
unstable-features  enabling unstable features (deprecated. do not use)
unused-extern-crates  extern crates that are never used
unused-import-braces  unnecessary braces around an imported item
unused-qualifications  detects unnecessarily qualified names
unused-results  unused result of an expression in a statement
variant-size-differences  detects enums with widely varying variant sizes
dead-code  detect unused, unexported items
deprecated  detects use of #[deprecated] items
drop-with-repr-extern  use of #[repr(C)] on a type that implements Drop
improper-ctypes  proper use of libc types in foreign modules
non-camel-case-types  types, variants, traits and type parameters should have camel case names
non-shorthand-field-patterns  using `Struct { x: x }` instead of `Struct { x }`
non-snake-case  methods, functions, lifetime parameters and modules should have snake case names
non-upper-case-globals  static constants should have uppercase identifiers
overflowing-literals  literal out of range for its type
path-statements  path statements with no effect
plugin-as-library  compiler plugin used as ordinary library in non-plugin crate
private-no-mangle-fns  functions marked #[no_mangle] should be exported
private-no-mangle-statics  statics marked #[no_mangle] should be exported
raw-pointer-derive  uses of #[derive] with raw pointers are rarely correct
stable-features  stable features found in #[feature] directive
unconditional-recursion  functions that cannot return without calling themselves
unknown-lints  unrecognized lint attribute
unreachable-code  detects unreachable code paths
unused-allocation  detects unnecessary allocations that can be eliminated
unused-assignments  detect assignments that will never be read
unused-attributes  detects attributes that were not used by the compiler
unused-comparisons  comparisons made useless by limits of the types involved
unused-features  unused or unknown features found in crate-level #[feature] directives
unused-imports  imports that are never used
unused-must-use  unused result of a type flagged as #[must_use]
unused-mut  detect mut variables which don't need to be mutable
unused-parens  `if`, `match`, `while` and `return` do not need parentheses
unused-unsafe  unnecessary use of an `unsafe` block
unused-variables  detect variables which are not used in any way
warnings  mass-change the level for lints which produce warnings
while-true  suggest using `loop { }` instead of `while true { }`
exceeding-bitshifts  shift exceeds the type's number of bits
mutable-transmutes  mutating transmuted &mut T from &T may cause undefined behavior
no-mangle-const-items  const items will not have their symbols exported
unknown-crate-types  unknown crate type found in #[crate_type] directive


Lint groups provided by rustc:

         name  sub-lints
         ----  ---------
    bad-style  non-camel-case-types, non-snake-case, non-upper-case-globals
       unused  unused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unused-must-use, unused-unsafe, path-statements


Compiler plugins can provide additional lints and lint groups. To see a listing of these, re-run `rustc -W help` with a crate filename.

Any ideas? I'm using fish, version 2.2.0-378-g573d972.

@faho
Copy link
Member

@faho faho commented Oct 24, 2015

outputs the wrong thing. It keeps in the header and footer of the help message, which is weird.

Well, it looks like it just doesn't match on them, so it replaces nothing - the lines appear unchanged.

@faho
Copy link
Member

@faho faho commented Oct 24, 2015

It's around 88ms for me. Still not as fast as file Python generates, but hey, it's a major improvement.

That probably warrants the technical term "good enough" - unless you're running a monster rig.

@faho
Copy link
Member

@faho faho commented Oct 24, 2015

Okay, I tested it a bit and played a bit around, and while there's still plenty of micro-optimizations possible (e.g. the recurring | egrep -v '^$' | egrep -v ':$' can be replaced by | string match -r '^.*[^:]$' - which saves a total of 6 grep calls when setting up the completion), but for me it's basically instantaneous anyway.

The semantics of egrep and string (i.e. pcre2) seem to be different enough that the egrep | string replace in the rust -W help part can't be replaced with string match -r directly, which is unfortunate, but in the end it doesn't really matter (we've tried so hard, and got so far).

So unless you think there's anything missing, this seems about ready to merge. Okay?

@bheesham bheesham force-pushed the bheesham:rustc-cargo-completion branch from acab102 to 4986fbe Oct 27, 2015
rustc.fish makes heavy use of the `string` commands.
@bheesham bheesham force-pushed the bheesham:rustc-cargo-completion branch from 4986fbe to 46fbfaa Oct 27, 2015
@bheesham
Copy link
Contributor Author

@bheesham bheesham commented Oct 27, 2015

Sounds like a plan. :-)

Thanks for all the pointers!

@faho faho merged commit 46fbfaa into fish-shell:master Oct 27, 2015
1 check failed
1 check failed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
@faho
Copy link
Member

@faho faho commented Oct 27, 2015

Merged, thanks!

@zanchey zanchey added this to the next-2.x milestone Oct 30, 2015
@zanchey zanchey added the completions label Oct 30, 2015
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.