-
Notifications
You must be signed in to change notification settings - Fork 392
clang: new completion #154
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
Open
yamaguchi1024
wants to merge
6
commits into
scop:main
Choose a base branch
from
yamaguchi1024:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed5e509
clang: new completion
yamaguchi1024 5a7d378
clang: new completion
yamaguchi1024 c7f12e5
Merge branch 'master' of github.com:yamaguchi1024/bash-completion
yamaguchi1024 a417718
Merge branch 'master' of github.com:yamaguchi1024/bash-completion
yamaguchi1024 4ba53fa
Add unittest for clang autocompletion.
yamaguchi1024 50ead93
Add clang to ubuntu Dockerfile
yamaguchi1024 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -53,6 +53,7 @@ bashcomp_DATA = 2to3 \ | |
chrpath \ | ||
_chsh \ | ||
cksfv \ | ||
clang \ | ||
cleanarch \ | ||
clisp \ | ||
clone_member \ | ||
|
This file contains hidden or 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,67 @@ | ||
# clang(1) completion -*- shell-script -*- | ||
_clang() | ||
{ | ||
local cur prev words cword arg flags prev2 | ||
_init_completion || return | ||
|
||
if [[ $cword > 1 ]]; then | ||
prev2="${COMP_WORDS[$cword - 2]}" | ||
fi | ||
|
||
# Clang want to know if -cc1 or -Xclang option is specified or not, because we don't want to show | ||
# cc1 options otherwise. | ||
if [[ "${COMP_WORDS[1]}" == "-cc1" || "$prev" == "-Xclang" ]]; then | ||
arg="#" | ||
fi | ||
|
||
# bash always separates '=' as a token even if there's no space before/after '='. | ||
# On the other hand, '=' is just a regular character for clang options that | ||
# contain '='. For example, "-stdlib=" is defined as is, instead of "-stdlib" and "=". | ||
# So, we need to partially undo bash tokenization here for integrity. | ||
if [[ "$cur" == -* ]]; then | ||
# -foo<tab> | ||
arg="$arg$cur" | ||
elif [[ "$prev" == -* && "$cur" == '=' ]]; then | ||
# -foo=<tab> | ||
arg="$arg$prev=," | ||
elif [[ "$cur" == -*= ]]; then | ||
# -foo=<tab> | ||
arg="$arg$cur," | ||
elif [[ "$prev" == -* ]]; then | ||
# -foo <tab> or -foo bar<tab> | ||
arg="$arg$prev,$cur" | ||
elif [[ "$prev2" == -* && "$prev" == '=' ]]; then | ||
# -foo=bar<tab> | ||
arg="$arg$prev2=,$cur" | ||
elif [[ ${cur: -1} != '=' && ${cur/=} != $cur ]]; then | ||
# -foo=bar<tab> | ||
arg="$arg${cur%=*}=,${cur#*=}" | ||
fi | ||
|
||
# expand ~ to $HOME | ||
eval local path=${COMP_WORDS[0]} | ||
flags=$( "$path" --autocomplete="$arg" 2>/dev/null | sed -e 's/\t.*//' ) | ||
# If clang is old that it does not support --autocomplete, | ||
# fall back to the filename completion. | ||
if [[ $? -ne 0 ]]; then | ||
_filedir | ||
return | ||
fi | ||
|
||
# When clang does not emit any possible autocompletion, or user pushed tab after " ", | ||
# just autocomplete files. | ||
if [[ "$flags" == $'\n' || "$arg" == "" ]]; then | ||
# If -foo=<tab> and there was no possible values, autocomplete files. | ||
[[ "$cur" == '=' || "$cur" == -*= ]] && cur="" | ||
_filedir | ||
elif [[ "$cur" == '=' ]]; then | ||
COMPREPLY=( $( compgen -W "$flags" -- "") ) | ||
else | ||
# Bash automatically appends a space after '=' by default. | ||
# Disable it so that it works nicely for options in the form of -foo=bar. | ||
[[ "${flags: -1}" == '=' ]] && compopt -o nospace 2> /dev/null | ||
COMPREPLY=( $( compgen -W "$flags" -- "$cur" ) ) | ||
fi | ||
} && | ||
complete -F _clang clang | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# ex: filetype=sh |
This file contains hidden or 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 @@ | ||
assert_source_completions clang |
This file contains hidden or 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
This file contains hidden or 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,18 @@ | ||
proc setup {} { | ||
save_env | ||
} | ||
|
||
|
||
proc teardown {} { | ||
assert_env_unmodified | ||
} | ||
|
||
|
||
setup | ||
|
||
|
||
assert_complete_any "clang " | ||
sync_after_int | ||
|
||
|
||
teardown |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unnnecessary. Why not just invoke
$words[0]
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we replace it with $words[0], it wouldn't work with something like ~/bin/clang where ~ needs to be expanded.